Class ContinuousQueryListenerContainer
java.lang.Object
org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer
- All Implemented Interfaces:
Aware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,Lifecycle,Phased,SmartLifecycle
public class ContinuousQueryListenerContainer
extends Object
implements BeanFactoryAware, BeanNameAware, InitializingBean, DisposableBean, SmartLifecycle
Container providing asynchronous processing/handling for Apache Geode Continuous Queries (CQ).
- Since:
- 1.1.0
- Author:
- Costin Leau, John Blum
- See Also:
-
ExecutorRegionServicePoolPoolManagerCqAttributesCqEventCqListenerCqQueryQueryServiceBeanFactoryBeanFactoryAwareBeanNameAwareDisposableBeanInitializingBeanSmartLifecycleSimpleAsyncTaskExecutorTaskExecutorPoolResolverDefaultableDelegatingPoolAdapterDelegatingPoolAdapterErrorHandler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final PoolResolverstatic final Stringprotected final org.slf4j.LoggerFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidaddListener(ContinuousQueryDefinition definition) Adds aContinuous Query (CQ) definitionto the (potentially running) container.voidprotected voidapplyContinuousQueryListenerContainerConfigurers(Iterable<ContinuousQueryListenerContainerConfigurer> configurers) Applies anIterableofContinuousQueryListenerContainerConfigurerobjects to customize the configuration of thisContinuousQueryListenerContainer.protected voidapplyContinuousQueryListenerContainerConfigurers(ContinuousQueryListenerContainerConfigurer... configurers) Applies an array ofContinuousQueryListenerContainerConfigurerobjects to customize the configuration of thisContinuousQueryListenerContainer.protected ExecutorCreates a defaultTaskExecutor.voiddestroy()protected voiddispatchEvent(ContinuousQueryListener listener, CqEvent event) Asynchronously dispatches theCQ eventto the targetedContinuousQueryListener.protected BeanFactoryReturns a reference to the configuredBeanFactory.protected StringReturns the configuredbean nameof this container.Returns a Composite object containing the collection ofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.Returns a reference to all the configured/registeredContinuous Queries.protected Set<ContinuousQueryDefinition>Returns a reference to all the configuredContinuousQueryDefinitions.Returns anOptionalreference to the configuredErrorHandlerinvoked when any unhandledExceptionsare thrown when invoking CQ listeners processing CQ events.intgetPhase()Gets the phase in which this CQ listener container will start in the Spring container.Returns the configuredpool name.Returns a reference to the configuredQueryService.Returns a reference to the configuredTaskExecutor.booleanisActive()Determines whether this container is currently active, i.e., whether it has been setup and initialized but not shutdown yet.booleanDetermines whether this CQ listener container will automatically start on startup.booleanDetermines whether the container has be started and is currently running.protected CqListenernewCqListener(ContinuousQueryListener listener) voidsetAutoStartup(boolean autoStartup) Sets whether the CQ listener container should automatically start on startup.voidsetBeanFactory(BeanFactory beanFactory) Sets theBeanFactorycontaining this bean.voidsetBeanName(String name) Set the name of the bean in the bean factory that created this bean.voidsetCache(RegionService cache) Set the underlying RegionService (GemFire Cache) used for registering Queries.voidsetContinuousQueryListenerContainerConfigurers(List<ContinuousQueryListenerContainerConfigurer> configurers) Null-safe operation setting anIterableofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.voidsetContinuousQueryListenerContainerConfigurers(ContinuousQueryListenerContainerConfigurer... configurers) Null-safe operation setting an array ofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.voidsetErrorHandler(ErrorHandler errorHandler) Set anErrorHandlerto be invoked in case of any uncaughtExceptionsthrown while processing a CQ event.voidsetPhase(int phase) Sets the phase in which this CQ listener container will start in the Spring container.voidsetPoolName(String poolName) Set the name of thePoolused for performing the queries by this container.voidsetPoolResolver(PoolResolver poolResolver) voidsetQueryListeners(Set<ContinuousQueryDefinition> queries) Attaches the given query definitions.voidsetQueryService(QueryService queryService) Set the GemFire QueryService used by this container to create ContinuousQueries (CQ).voidsetTaskExecutor(Executor taskExecutor) Sets the Task Executor used for running the event listeners when messages are received.voidstart()voidstop()void
-
Field Details
-
DEFAULT_THREAD_NAME_PREFIX
-
DEFAULT_POOL_RESOLVER
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Details
-
ContinuousQueryListenerContainer
public ContinuousQueryListenerContainer()
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
applyContinuousQueryListenerContainerConfigurers
protected void applyContinuousQueryListenerContainerConfigurers(ContinuousQueryListenerContainerConfigurer... configurers) Applies an array ofContinuousQueryListenerContainerConfigurerobjects to customize the configuration of thisContinuousQueryListenerContainer.- Parameters:
configurers- array ofContinuousQueryListenerContainerConfigurerused to customize the configuration of thisContinuousQueryListenerContainer.- See Also:
-
applyContinuousQueryListenerContainerConfigurers
protected void applyContinuousQueryListenerContainerConfigurers(Iterable<ContinuousQueryListenerContainerConfigurer> configurers) Applies anIterableofContinuousQueryListenerContainerConfigurerobjects to customize the configuration of thisContinuousQueryListenerContainer.- Parameters:
configurers-IterableofContinuousQueryListenerContainerConfigurerused to customize the configuration of thisContinuousQueryListenerContainer.- See Also:
-
createDefaultTaskExecutor
Creates a defaultTaskExecutor.Called if no explicit
TaskExecutorhas been configured.The default implementation builds a
SimpleAsyncTaskExecutorwith the specified bean name (or the class name, if no bean name is specified) as the Thread name prefix.- Returns:
- an instance of the
TaskExecutorused to process CQ events asynchronously. - See Also:
-
isActive
public boolean isActive()Determines whether this container is currently active, i.e., whether it has been setup and initialized but not shutdown yet.- Returns:
- a boolean indicating whether the container is active.
-
setAutoStartup
public void setAutoStartup(boolean autoStartup) Sets whether the CQ listener container should automatically start on startup.- Parameters:
autoStartup- a boolean value indicating whether this CQ listener container should automatically start.
-
isAutoStartup
public boolean isAutoStartup()Determines whether this CQ listener container will automatically start on startup.- Specified by:
isAutoStartupin interfaceSmartLifecycle- Returns:
- a boolean value indicating whether this CQ listener container automatically starts.
- See Also:
-
isRunning
public boolean isRunning()Determines whether the container has be started and is currently running. -
setBeanFactory
Sets theBeanFactorycontaining this bean.- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Parameters:
beanFactory- the SpringBeanFactorycontaining this bean.- Throws:
BeansException- if an initialization error occurs.
-
getBeanFactory
Returns a reference to the configuredBeanFactory.- Returns:
- a reference to the configured
BeanFactory. - See Also:
-
setBeanName
Set the name of the bean in the bean factory that created this bean.Invoked after population of normal bean properties but before an init callback such as
InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
setBeanNamein interfaceBeanNameAware- Parameters:
name- the name of the bean in the factory.
-
getBeanName
Returns the configuredbean nameof this container.- Returns:
- the configured
bean nameof this container.
-
setCache
Set the underlying RegionService (GemFire Cache) used for registering Queries.- Parameters:
cache- the RegionService (GemFire Cache) used for registering Queries.- See Also:
-
getContinuousQueries
Returns a reference to all the configured/registeredContinuous Queries.- Returns:
- a reference to all the configured/registered
Continuous Queries. - See Also:
-
getContinuousQueryDefinitions
Returns a reference to all the configuredContinuousQueryDefinitions.- Returns:
- a reference to all the configured
ContinuousQueryDefinitions. - See Also:
-
setContinuousQueryListenerContainerConfigurers
public void setContinuousQueryListenerContainerConfigurers(ContinuousQueryListenerContainerConfigurer... configurers) Null-safe operation setting an array ofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.- Parameters:
configurers- array ofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.- See Also:
-
setContinuousQueryListenerContainerConfigurers
public void setContinuousQueryListenerContainerConfigurers(List<ContinuousQueryListenerContainerConfigurer> configurers) Null-safe operation setting anIterableofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.- Parameters:
configurers-IterableofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.- See Also:
-
getCompositeContinuousQueryListenerContainerConfigurer
protected ContinuousQueryListenerContainerConfigurer getCompositeContinuousQueryListenerContainerConfigurer()Returns a Composite object containing the collection ofContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer.- Returns:
- a Composite object containing a collection of
ContinuousQueryListenerContainerConfigurerobjects used to customize the configuration of thisContinuousQueryListenerContainer. - See Also:
-
setErrorHandler
Set anErrorHandlerto be invoked in case of any uncaughtExceptionsthrown while processing a CQ event. By default there is noErrorHandlerconfigured so error-level logging is the only result.- Parameters:
errorHandler-ErrorHandlerinvoked when uncaughtExceptionsare thrown while processing the CQ event.- See Also:
-
getErrorHandler
Returns anOptionalreference to the configuredErrorHandlerinvoked when any unhandledExceptionsare thrown when invoking CQ listeners processing CQ events.- Returns:
- an
Optionalreference to the configuredErrorHandler. - See Also:
-
setPhase
public void setPhase(int phase) Sets the phase in which this CQ listener container will start in the Spring container.- Parameters:
phase- the phase value of this CQ listener container.
-
getPhase
public int getPhase()Gets the phase in which this CQ listener container will start in the Spring container.- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle- Returns:
- the phase value of this CQ listener container.
- See Also:
-
setPoolName
Set the name of thePoolused for performing the queries by this container.- Parameters:
poolName- the name of the pool to be used by the container
-
getPoolName
Returns the configuredpool name.- Returns:
- the configured
pool name.
-
setPoolResolver
- Parameters:
poolResolver- the configuredPoolResolverused to resolvePoolobjects byname.- See Also:
-
getPoolResolver
- Returns:
- the configured
PoolResolver. - See Also:
-
setQueryListeners
Attaches the given query definitions.- Parameters:
queries- set of queries
-
setQueryService
Set the GemFire QueryService used by this container to create ContinuousQueries (CQ).- Parameters:
queryService- the GemFire QueryService object used by the container to create ContinuousQueries (CQ).- See Also:
-
getQueryService
Returns a reference to the configuredQueryService.- Returns:
- a reference to the configured
QueryService. - See Also:
-
setTaskExecutor
Sets the Task Executor used for running the event listeners when messages are received. If no task executor is set, an instance ofSimpleAsyncTaskExecutorwill be used by default. The task executor can be adjusted depending on the work done by the listeners and the number of messages coming in.- Parameters:
taskExecutor- The Task Executor used to run event listeners when query results messages are received.- See Also:
-
getTaskExecutor
Returns a reference to the configuredTaskExecutor.- Returns:
- a reference to the configured
TaskExecutor. - See Also:
-
addListener
Adds aContinuous Query (CQ) definitionto the (potentially running) container. If the container is running, the listener starts receiving (matching) messages as soon as possible.- Parameters:
definition-Continuous Query (CQ) definitionto register.- See Also:
-
addContinuousQueryDefinition
-
newCqListener
-
start
public void start() -
dispatchEvent
Asynchronously dispatches theCQ eventto the targetedContinuousQueryListener.- Parameters:
listener-ContinuousQueryListenerwhich will process/handle theCQ event.event-CQ eventto process.- See Also:
-
stop
- Specified by:
stopin interfaceSmartLifecycle
-
stop
public void stop() -
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean
-