Java Code Examples for org.springframework.context.ApplicationEventPublisher#publishEvent()

The following examples show how to use org.springframework.context.ApplicationEventPublisher#publishEvent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkspaceWatcher.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public WorkspaceWatcher(WorkspaceManager wsMgr, Workspace ws, WatchedPathStore watchedPathStore, final ApplicationEventPublisher publisher) {
    this.ws = ws;
    this.wsMgr = wsMgr;
    this.workingDir = ws.getWorkingDir().toPath();
    this.watchedPathStore = watchedPathStore;

    this.debouncer = new Debouncer<>(event -> {
        log.info("publish file change event: {}", event);
        publisher.publishEvent(event);
    }, 50);

    for (String dir : ignoreDirs) {
        try {
            ignorePaths.add(ws.getPath(dir));
            watchedPathStore.add(ws.getSpaceKey(), ws.getPath(dir).toString());
        } catch (AccessDeniedException e) {
            e.printStackTrace();
        }
    }

    watchedPathStore.add(ws.getSpaceKey(), "/");
    watchedPathStore.add(ws.getSpaceKey(), "/.git/"); // for .git/HEAD
}
 
Example 2
Source File: PublishDelegateParseListener.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
public PublishDelegateParseListener(final ApplicationEventPublisher publisher, final EventingProperty property) {

    if (property.isTask()) {
      this.taskListener = delegateTask -> {
        publisher.publishEvent(delegateTask);
        publisher.publishEvent(new TaskEvent(delegateTask));
      };
    } else {
      this.taskListener = null;
    }

    if (property.isExecution()) {
      this.executionListener = delegateExecution -> {
        publisher.publishEvent(delegateExecution);
        publisher.publishEvent(new ExecutionEvent(delegateExecution));
      };
    } else {
      this.executionListener = null;
    }
  }
 
Example 3
Source File: PublishDelegateParseListener.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public PublishDelegateParseListener(final ApplicationEventPublisher publisher, final EventingProperty property) {

    if (property.isTask()) {
      this.taskListener = delegateTask -> {
        publisher.publishEvent(delegateTask);
        publisher.publishEvent(new TaskEvent(delegateTask));
      };
    } else {
      this.taskListener = null;
    }

    if (property.isExecution()) {
      this.executionListener = delegateExecution -> {
        publisher.publishEvent(delegateExecution);
        publisher.publishEvent(new ExecutionEvent(delegateExecution));
      };
    } else {
      this.executionListener = null;
    }
  }
 
Example 4
Source File: StompSubProtocolHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void publishEvent(ApplicationEventPublisher publisher, ApplicationEvent event) {
	try {
		publisher.publishEvent(event);
	}
	catch (Throwable ex) {
		if (logger.isErrorEnabled()) {
			logger.error("Error publishing " + event, ex);
		}
	}
}
 
Example 5
Source File: StompSubProtocolHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void publishEvent(ApplicationEventPublisher publisher, ApplicationEvent event) {
	try {
		publisher.publishEvent(event);
	}
	catch (Throwable ex) {
		if (logger.isErrorEnabled()) {
			logger.error("Error publishing " + event, ex);
		}
	}
}
 
Example 6
Source File: BatchProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new batch processor.
 * 
 * @param processName
 *            the process name
 * @param retryingTransactionHelper
 *            the retrying transaction helper
 * @param workProvider
 *            the object providing the work packets
 * @param workerThreads
 *            the number of worker threads
 * @param batchSize
 *            the number of entries we process at a time in a transaction
 * @param applicationEventPublisher
 *            the application event publisher (may be <tt>null</tt>)
 * @param logger
 *            the logger to use (may be <tt>null</tt>)
 * @param loggingInterval
 *            the number of entries to process before reporting progress
 *            
 * @since 3.4 
 */
public BatchProcessor(
        String processName,
        RetryingTransactionHelper retryingTransactionHelper,
        BatchProcessWorkProvider<T> workProvider,
        int workerThreads, int batchSize,
        ApplicationEventPublisher applicationEventPublisher,
        Log logger,
        int loggingInterval)
{
    this.threadFactory = new TraceableThreadFactory();
    this.threadFactory.setNamePrefix(processName);
    this.threadFactory.setThreadDaemon(true);
    
    this.processName = processName;
    this.retryingTransactionHelper = retryingTransactionHelper;
    this.workProvider = workProvider;
    this.workerThreads = workerThreads;
    this.batchSize = batchSize;
    if (logger == null)
    {
        this.logger = LogFactory.getLog(this.getClass());
    }
    else
    {
        this.logger = logger;
    }
    this.loggingInterval = loggingInterval;
    
    // Let the (enterprise) monitoring side know of our presence
    if (applicationEventPublisher != null)
    {
        applicationEventPublisher.publishEvent(new BatchMonitorEvent(this));
    }
}
 
Example 7
Source File: AbstractHibernateQuery.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
public List listForCriteria() {
    Datastore datastore = session.getDatastore();
    ApplicationEventPublisher publisher = datastore.getApplicationEventPublisher();
    if(publisher != null) {
        publisher.publishEvent(new PreQueryEvent(datastore, this));
    }

    List results = criteria.list();
    if(publisher != null) {
        publisher.publishEvent(new PostQueryEvent(datastore, this, results));
    }
    return results;
}
 
Example 8
Source File: AbstractHibernateQuery.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
@Override
public Object singleResult() {
    if(criteria == null) throw new IllegalStateException("Cannot execute query using a detached criteria instance");

    if (hibernateProjectionList != null) {
        criteria.setProjection(hibernateProjectionList.getHibernateProjectionList());
    }
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    applyDefaultSortOrderAndCaching();
    applyFetchStrategies();

    Datastore datastore = session.getDatastore();
    ApplicationEventPublisher publisher = datastore.getApplicationEventPublisher();
    if(publisher != null) {
        publisher.publishEvent(new PreQueryEvent(datastore, this));
    }

    Object result;
    if(hasJoins) {
        try {
            result = proxyHandler.unwrap(criteria.uniqueResult());;
        } catch (NonUniqueResultException e) {
            result = singleResultViaListCall();
        }
    }
    else {
        result = singleResultViaListCall();
    }
    if(publisher != null) {
        publisher.publishEvent(new PostQueryEvent(datastore, this, Collections.singletonList(result)));
    }
    return result;
}
 
Example 9
Source File: InjectingApplicationEventPublisherDemo.java    From geekbang-lessons with Apache License 2.0 4 votes vote down vote up
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { // #1
    applicationEventPublisher.publishEvent(new MySpringEvent("The event from ApplicationEventPublisherAware"));
}
 
Example 10
Source File: Car.java    From project-manager with Apache License 2.0 4 votes vote down vote up
public void sell(ApplicationEventPublisher publisher) {
    sold = true;
    CarSold event = new CarSold(vin);
    publisher.publishEvent(event);
}
 
Example 11
Source File: ServerStatistics.java    From iaf with Apache License 2.0 4 votes vote down vote up
@PUT
@RolesAllowed({"IbisAdmin", "IbisTester"})
@Path("/server/log")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateLogConfiguration(LinkedHashMap<String, Object> json) throws ApiException {

	Level loglevel = null;
	Boolean logIntermediaryResults = true;
	int maxMessageLength = -1;
	Boolean enableDebugger = null;
	StringBuilder msg = new StringBuilder();

	Logger rootLogger = LogUtil.getRootLogger();

	for (Entry<String, Object> entry : json.entrySet()) {
		String key = entry.getKey();
		Object value = entry.getValue();
		if(key.equalsIgnoreCase("loglevel")) {
			loglevel = Level.toLevel(""+value);
		}
		else if(key.equalsIgnoreCase("logIntermediaryResults")) {
			logIntermediaryResults = Boolean.parseBoolean(""+value);
		}
		else if(key.equalsIgnoreCase("maxMessageLength")) {
			maxMessageLength = Integer.parseInt(""+value);
		}
		else if(key.equalsIgnoreCase("enableDebugger")) {
			enableDebugger = Boolean.parseBoolean(""+value);
		}
	}

	if(loglevel != null && rootLogger.getLevel() != loglevel) {
		Configurator.setLevel(rootLogger.getName(), loglevel);
		msg.append("LogLevel changed from [" + rootLogger.getLevel() + "] to [" + loglevel +"]");
	}

	boolean logIntermediary = AppConstants.getInstance().getBoolean("log.logIntermediaryResults", true);
	if(logIntermediary != logIntermediaryResults) {
		AppConstants.getInstance().put("log.logIntermediaryResults", "" + logIntermediaryResults);

		if(msg.length() > 0)
			msg.append(", logIntermediaryResults from [" + logIntermediary+ "] to [" + logIntermediaryResults + "]");
		else
			msg.append("logIntermediaryResults changed from [" + logIntermediary+ "] to [" + logIntermediaryResults + "]");
	}

	if (maxMessageLength != IbisMaskingLayout.getMaxLength()) {
		if(msg.length() > 0)
			msg.append(", logMaxMessageLength from [" + IbisMaskingLayout.getMaxLength() + "] to [" + maxMessageLength + "]");
		else
			msg.append("logMaxMessageLength changed from [" + IbisMaskingLayout.getMaxLength() + "] to [" + maxMessageLength + "]");
		IbisMaskingLayout.setMaxLength(maxMessageLength);
	}

	if (enableDebugger!=null) {
		boolean testtoolEnabled=AppConstants.getInstance().getBoolean("testtool.enabled", true);
		if (testtoolEnabled!=enableDebugger) {
			AppConstants.getInstance().put("testtool.enabled", "" + enableDebugger);
			DebuggerStatusChangedEvent event = new DebuggerStatusChangedEvent(this, enableDebugger);
			ApplicationEventPublisher applicationEventPublisher = getIbisManager().getApplicationEventPublisher();
			if (applicationEventPublisher!=null) {
				log.info("setting debugger enabled ["+enableDebugger+"]");
				applicationEventPublisher.publishEvent(event);
			} else {
				log.warn("no applicationEventPublisher, cannot set debugger enabled ["+enableDebugger+"]");
			}
		}
		}
	
	
	if(msg.length() > 0) {
		log.warn(msg.toString());
		LogUtil.getLogger("SEC").info(msg.toString());
	}

	return Response.status(Response.Status.NO_CONTENT).build();
}
 
Example 12
Source File: EventVerifier.java    From hawkbit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Publishes a reset counter marker event on the context to reset the
 * current counted events. This allows test to prepare a setup such in
 * {@code @Before} annotations which are actually counted to the executed
 * test-method and maybe fire events which are not covered / recognized by
 * the test-method itself and reset the counter again.
 * 
 * Note that this approach is only working when using a single-thread
 * executor in the ApplicationEventMultiCaster, so the order of the events
 * keep the same.
 * 
 * @param publisher
 *            the {@link ApplicationEventPublisher} to publish the marker
 *            event to
 */
public static void publishResetMarkerEvent(final ApplicationEventPublisher publisher) {
    publisher.publishEvent(new ResetCounterMarkerEvent());
}