Java Code Examples for org.springframework.context.event.SmartApplicationListener

The following examples show how to use org.springframework.context.event.SmartApplicationListener. These examples are extracted from open source projects. 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 Project: haven-platform   Source File: BalancerConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Listens ContextClosedEvent and Closes all async http connections
 */
@Bean
ApplicationListener<?> applicationListener() {
    return new SmartApplicationListener() {
        @Override
        public int getOrder() { return 0; }

        @Override
        public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
            return ContextClosedEvent.class.isAssignableFrom(eventType);
        }

        @Override
        public boolean supportsSourceType(Class<?> sourceType) { return true; }

        @Override
        public void onApplicationEvent(ApplicationEvent event) { Closeables.close(proxyInstance); }
    };
}
 
Example 2
/**
    * {@inheritDoc}
    *
    * <p>
    * The {@link org.kuali.rice.coreservice.api.parameter.Parameter} properties need to come from the
    * {@link ConfigContext} instead of the {@link org.kuali.common.util.spring.env.EnvironmentService} for the scenario
    * where nobody has wired in a bootstrap PSC in order to help manage the resetting of the database via RunOnce.
    * </p>
    */
@Override
@Bean
public SmartApplicationListener applicationEventListener() {
	Properties properties = ConfigContext.getCurrentContextConfig().getProperties();
	String applicationId = properties.getProperty(CoreConstants.Config.APPLICATION_ID);
	String namespace = properties.getProperty(NAMESPACE_KEY, NAMESPACE);
	String component = properties.getProperty(COMPONENT_KEY, COMPONENT);
	String name = properties.getProperty(NAME_KEY, NAME);
	String description = properties.getProperty(DESCRIPTION_KEY, DESCRIPTION);
	boolean runOnMissingParameter = Boolean.parseBoolean(properties.getProperty(RUN_ON_MISSING_PARAMETER_KEY, RUN_ON_MISSING_PARAMETER.toString()));
       int order = Integer.parseInt(properties.getProperty(ORDER_KEY, String.valueOf(Ordered.LOWEST_PRECEDENCE)));

	RunOnce runOnce = ParameterServiceRunOnce.builder(applicationId, namespace, component, name)
               .description(description).runOnMissingParameter(runOnMissingParameter).build();
	Executable springExecutable = SpringExecUtils.getSpringExecutable(service, propertySource, IngestXmlExecConfig.class,
               Lists.newArrayList("master"));
       Executable executable = RunOnceExecutable.builder(springExecutable, runOnce).build();

	return ExecutableApplicationEventListener.builder(executable, ContextRefreshedEvent.class).order(order).build();
}
 
Example 3
Source Project: spring-analysis-note   Source File: MultiServerUserRegistry.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance wrapping the local user registry.
 */
public MultiServerUserRegistry(SimpUserRegistry localRegistry) {
	Assert.notNull(localRegistry, "'localRegistry' is required");
	this.id = generateId();
	this.localRegistry = localRegistry;
	this.delegateApplicationEvents = this.localRegistry instanceof SmartApplicationListener;
}
 
Example 4
Source Project: java-technology-stack   Source File: MultiServerUserRegistry.java    License: MIT License 5 votes vote down vote up
/**
 * Create an instance wrapping the local user registry.
 */
public MultiServerUserRegistry(SimpUserRegistry localRegistry) {
	Assert.notNull(localRegistry, "'localRegistry' is required.");
	this.id = generateId();
	this.localRegistry = localRegistry;
	this.delegateApplicationEvents = this.localRegistry instanceof SmartApplicationListener;
}
 
Example 5
/**
 * Create an instance wrapping the local user registry.
 */
public MultiServerUserRegistry(SimpUserRegistry localRegistry) {
	Assert.notNull(localRegistry, "'localRegistry' is required.");
	this.localRegistry = localRegistry;
	this.listener = (this.localRegistry instanceof SmartApplicationListener ?
			(SmartApplicationListener) this.localRegistry : new NoOpSmartApplicationListener());
	this.id = generateId();
}
 
Example 6
Source Project: rice   Source File: IngestXmlConfig.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
    * {@inheritDoc}
    */
@Override
@Bean
public SmartApplicationListener applicationEventListener() {
	Executable executable = config.ingestXmlExecutable();
       Integer order = env.getInteger(ORDER_KEY, Integer.valueOf(Ordered.LOWEST_PRECEDENCE));

	return ExecutableApplicationEventListener.builder(executable, ContextRefreshedEvent.class).order(order.intValue()).build();
}
 
Example 7
Source Project: spring-analysis-note   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public int getOrder() {
	return (this.delegateApplicationEvents ?
			((SmartApplicationListener) this.localRegistry).getOrder() : Ordered.LOWEST_PRECEDENCE);
}
 
Example 8
Source Project: spring-analysis-note   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return (this.delegateApplicationEvents &&
			((SmartApplicationListener) this.localRegistry).supportsEventType(eventType));
}
 
Example 9
Source Project: spring-analysis-note   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public boolean supportsSourceType(@Nullable Class<?> sourceType) {
	return (this.delegateApplicationEvents &&
			((SmartApplicationListener) this.localRegistry).supportsSourceType(sourceType));
}
 
Example 10
Source Project: spring-analysis-note   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (this.delegateApplicationEvents) {
		((SmartApplicationListener) this.localRegistry).onApplicationEvent(event);
	}
}
 
Example 11
Source Project: java-technology-stack   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public int getOrder() {
	return (this.delegateApplicationEvents ?
			((SmartApplicationListener) this.localRegistry).getOrder() : Ordered.LOWEST_PRECEDENCE);
}
 
Example 12
Source Project: java-technology-stack   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return (this.delegateApplicationEvents &&
			((SmartApplicationListener) this.localRegistry).supportsEventType(eventType));
}
 
Example 13
Source Project: java-technology-stack   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public boolean supportsSourceType(@Nullable Class<?> sourceType) {
	return (this.delegateApplicationEvents &&
			((SmartApplicationListener) this.localRegistry).supportsSourceType(sourceType));
}
 
Example 14
Source Project: java-technology-stack   Source File: MultiServerUserRegistry.java    License: MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (this.delegateApplicationEvents) {
		((SmartApplicationListener) this.localRegistry).onApplicationEvent(event);
	}
}
 
Example 15
@Bean
public SmartApplicationListener heartbeatListener(ConfigClientProperties properties,
		ConfigServerInstanceProvider provider) {
	return new HeartbeatListener(properties, provider);
}
 
Example 16
/**
 * Determine whether the given listener supports the given event.
 * <p>
 * The default implementation detects the {@link SmartApplicationListener}
 * interface. In case of a standard {@link ApplicationListener}, a
 * {@link GenericApplicationListenerAdapter} will be used to introspect the
 * generically declared type of the target listener.
 * 
 * @param listener
 *            the target listener to check
 * @param eventType
 *            the event type to check against
 * @param sourceType
 *            the source type to check against
 * @return whether the given listener should be included in the candidates
 *         for the given event type
 */
protected boolean supportsEvent(ApplicationListener listener, Class<? extends ApplicationEvent> eventType,
        Class sourceType)
{

    SmartApplicationListener smartListener = (listener instanceof SmartApplicationListener ? (SmartApplicationListener) listener
            : new GenericApplicationListenerAdapter(listener));
    return (smartListener.supportsEventType(eventType) && smartListener.supportsSourceType(sourceType));
}