Class ContinuousQueryListenerContainer
java.lang.Object
org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.SmartLifecycle
public class ContinuousQueryListenerContainer
extends Object
implements org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.context.SmartLifecycle
Container providing asynchronous processing/handling for Apache Geode Continuous Queries (CQ).
- Since:
- 1.1.0
- See Also:
-
Executor
RegionService
Pool
PoolManager
CqAttributes
CqEvent
CqListener
CqQuery
QueryService
BeanFactory
BeanFactoryAware
BeanNameAware
DisposableBean
InitializingBean
SmartLifecycle
SimpleAsyncTaskExecutor
TaskExecutor
PoolResolver
DefaultableDelegatingPoolAdapter
DelegatingPoolAdapter
ErrorHandler
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final PoolResolver
static final String
protected final org.slf4j.Logger
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
addListener
(ContinuousQueryDefinition definition) Adds aContinuous Query (CQ) definition
to the (potentially running) container.void
protected void
applyContinuousQueryListenerContainerConfigurers
(Iterable<ContinuousQueryListenerContainerConfigurer> configurers) Applies anIterable
ofContinuousQueryListenerContainerConfigurer
objects to customize the configuration of thisContinuousQueryListenerContainer
.protected void
applyContinuousQueryListenerContainerConfigurers
(ContinuousQueryListenerContainerConfigurer... configurers) Applies an array ofContinuousQueryListenerContainerConfigurer
objects to customize the configuration of thisContinuousQueryListenerContainer
.protected Executor
Creates a defaultTaskExecutor
.void
destroy()
protected void
dispatchEvent
(ContinuousQueryListener listener, org.apache.geode.cache.query.CqEvent event) Asynchronously dispatches theCQ event
to the targetedContinuousQueryListener
.protected org.springframework.beans.factory.BeanFactory
Returns a reference to the configuredBeanFactory
.protected String
Returns the configuredbean name
of this container.Returns a Composite object containing the collection ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.protected Queue<org.apache.geode.cache.query.CqQuery>
Returns a reference to all the configured/registeredContinuous Queries
.protected Set<ContinuousQueryDefinition>
Returns a reference to all the configuredContinuousQueryDefinitions
.Optional<org.springframework.util.ErrorHandler>
Returns anOptional
reference to the configuredErrorHandler
invoked when any unhandledExceptions
are thrown when invoking CQ listeners processing CQ events.int
getPhase()
Gets the phase in which this CQ listener container will start in the Spring container.Returns the configuredpool name
.org.apache.geode.cache.query.QueryService
Returns a reference to the configuredQueryService
.Returns a reference to the configuredTaskExecutor
.boolean
isActive()
Determines whether this container is currently active, i.e., whether it has been setup and initialized but not shutdown yet.boolean
Determines whether this CQ listener container will automatically start on startup.boolean
Determines whether the container has be started and is currently running.protected org.apache.geode.cache.query.CqListener
newCqListener
(ContinuousQueryListener listener) void
setAutoStartup
(boolean autoStartup) Sets whether the CQ listener container should automatically start on startup.void
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory) Sets theBeanFactory
containing this bean.void
setBeanName
(String name) Set the name of the bean in the bean factory that created this bean.void
setCache
(org.apache.geode.cache.RegionService cache) Set the underlying RegionService (GemFire Cache) used for registering Queries.void
setContinuousQueryListenerContainerConfigurers
(List<ContinuousQueryListenerContainerConfigurer> configurers) Null-safe operation setting anIterable
ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.void
setContinuousQueryListenerContainerConfigurers
(ContinuousQueryListenerContainerConfigurer... configurers) Null-safe operation setting an array ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.void
setErrorHandler
(org.springframework.util.ErrorHandler errorHandler) Set anErrorHandler
to be invoked in case of any uncaughtExceptions
thrown while processing a CQ event.void
setPhase
(int phase) Sets the phase in which this CQ listener container will start in the Spring container.void
setPoolName
(String poolName) Set the name of thePool
used for performing the queries by this container.void
setPoolResolver
(PoolResolver poolResolver) void
setQueryListeners
(Set<ContinuousQueryDefinition> queries) Attaches the given query definitions.void
setQueryService
(org.apache.geode.cache.query.QueryService queryService) Set the GemFire QueryService used by this container to create ContinuousQueries (CQ).void
setTaskExecutor
(Executor taskExecutor) Sets the Task Executor used for running the event listeners when messages are received.void
start()
void
stop()
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:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
applyContinuousQueryListenerContainerConfigurers
protected void applyContinuousQueryListenerContainerConfigurers(ContinuousQueryListenerContainerConfigurer... configurers) Applies an array ofContinuousQueryListenerContainerConfigurer
objects to customize the configuration of thisContinuousQueryListenerContainer
.- Parameters:
configurers
- array ofContinuousQueryListenerContainerConfigurer
used to customize the configuration of thisContinuousQueryListenerContainer
.- See Also:
-
applyContinuousQueryListenerContainerConfigurers
protected void applyContinuousQueryListenerContainerConfigurers(Iterable<ContinuousQueryListenerContainerConfigurer> configurers) Applies anIterable
ofContinuousQueryListenerContainerConfigurer
objects to customize the configuration of thisContinuousQueryListenerContainer
.- Parameters:
configurers
-Iterable
ofContinuousQueryListenerContainerConfigurer
used to customize the configuration of thisContinuousQueryListenerContainer
.- See Also:
-
createDefaultTaskExecutor
Creates a defaultTaskExecutor
.Called if no explicit
TaskExecutor
has been configured.The default implementation builds a
SimpleAsyncTaskExecutor
with the specified bean name (or the class name, if no bean name is specified) as the Thread name prefix.- Returns:
- an instance of the
TaskExecutor
used to process CQ events asynchronously. - See Also:
-
SimpleAsyncTaskExecutor
-
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:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
- Returns:
- a boolean value indicating whether this CQ listener container automatically starts.
- See Also:
-
SmartLifecycle.isAutoStartup()
-
isRunning
public boolean isRunning()Determines whether the container has be started and is currently running.- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
- Returns:
- a boolean value indicating whether the container has been started and is currently running.
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException Sets theBeanFactory
containing this bean.- Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
- Parameters:
beanFactory
- the SpringBeanFactory
containing this bean.- Throws:
org.springframework.beans.BeansException
- if an initialization error occurs.
-
getBeanFactory
protected org.springframework.beans.factory.BeanFactory getBeanFactory()Returns a reference to the configuredBeanFactory
.- Returns:
- a reference to the configured
BeanFactory
. - See Also:
-
BeanFactory
-
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:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
- Parameters:
name
- the name of the bean in the factory.
-
getBeanName
Returns the configuredbean name
of this container.- Returns:
- the configured
bean name
of this container.
-
setCache
public void setCache(org.apache.geode.cache.RegionService cache) Set the underlying RegionService (GemFire Cache) used for registering Queries.- Parameters:
cache
- the RegionService (GemFire Cache) used for registering Queries.- See Also:
-
RegionService
-
getContinuousQueries
Returns a reference to all the configured/registeredContinuous Queries
.- Returns:
- a reference to all the configured/registered
Continuous Queries
. - See Also:
-
CqQuery
Queue
-
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 ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.- Parameters:
configurers
- array ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.- See Also:
-
setContinuousQueryListenerContainerConfigurers
public void setContinuousQueryListenerContainerConfigurers(List<ContinuousQueryListenerContainerConfigurer> configurers) Null-safe operation setting anIterable
ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.- Parameters:
configurers
-Iterable
ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.- See Also:
-
getCompositeContinuousQueryListenerContainerConfigurer
protected ContinuousQueryListenerContainerConfigurer getCompositeContinuousQueryListenerContainerConfigurer()Returns a Composite object containing the collection ofContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
.- Returns:
- a Composite object containing a collection of
ContinuousQueryListenerContainerConfigurer
objects used to customize the configuration of thisContinuousQueryListenerContainer
. - See Also:
-
setErrorHandler
public void setErrorHandler(org.springframework.util.ErrorHandler errorHandler) Set anErrorHandler
to be invoked in case of any uncaughtExceptions
thrown while processing a CQ event. By default there is noErrorHandler
configured so error-level logging is the only result.- Parameters:
errorHandler
-ErrorHandler
invoked when uncaughtExceptions
are thrown while processing the CQ event.- See Also:
-
ErrorHandler
-
getErrorHandler
Returns anOptional
reference to the configuredErrorHandler
invoked when any unhandledExceptions
are thrown when invoking CQ listeners processing CQ events.- Returns:
- an
Optional
reference to the configuredErrorHandler
. - See Also:
-
ErrorHandler
-
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:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.springframework.context.SmartLifecycle
- Returns:
- the phase value of this CQ listener container.
- See Also:
-
Phased.getPhase()
-
setPoolName
Set the name of thePool
used 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 configuredPoolResolver
used to resolvePool
objects byname
.- See Also:
-
getPoolResolver
- Returns:
- the configured
PoolResolver
. - See Also:
-
setQueryListeners
Attaches the given query definitions.- Parameters:
queries
- set of queries
-
setQueryService
public void setQueryService(org.apache.geode.cache.query.QueryService queryService) 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:
-
QueryService
-
getQueryService
public org.apache.geode.cache.query.QueryService getQueryService()Returns a reference to the configuredQueryService
.- Returns:
- a reference to the configured
QueryService
. - See Also:
-
QueryService
-
setTaskExecutor
Sets the Task Executor used for running the event listeners when messages are received. If no task executor is set, an instance ofSimpleAsyncTaskExecutor
will 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) definition
to the (potentially running) container. If the container is running, the listener starts receiving (matching) messages as soon as possible.- Parameters:
definition
-Continuous Query (CQ) definition
to register.- See Also:
-
addContinuousQueryDefinition
-
newCqListener
-
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
dispatchEvent
protected void dispatchEvent(ContinuousQueryListener listener, org.apache.geode.cache.query.CqEvent event) Asynchronously dispatches theCQ event
to the targetedContinuousQueryListener
.- Parameters:
listener
-ContinuousQueryListener
which will process/handle theCQ event
.event
-CQ event
to process.- See Also:
-
ContinuousQueryListener
CqEvent
-
stop
- Specified by:
stop
in interfaceorg.springframework.context.SmartLifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-