org.springframework.data.gemfire.listener
Class ContinuousQueryListenerContainer

java.lang.Object
  extended by org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer
All Implemented Interfaces:
Aware, BeanNameAware, DisposableBean, InitializingBean, Lifecycle, Phased, SmartLifecycle

public class ContinuousQueryListenerContainer
extends Object
implements InitializingBean, DisposableBean, BeanNameAware, SmartLifecycle

Container providing asynchronous behaviour for GemFire continuous queries.


Field Summary
static String DEFAULT_THREAD_NAME_PREFIX
          Default thread name prefix: "ContinousQueryListenerContainer-".
protected  org.apache.commons.logging.Log logger
          Logger available to subclasses
 
Constructor Summary
ContinuousQueryListenerContainer()
           
 
Method Summary
 void addListener(ContinuousQueryDefinition cqQuery)
          Adds a query definition to the (potentially running) container.
 void afterPropertiesSet()
           
protected  TaskExecutor createDefaultTaskExecutor()
          Creates a default TaskExecutor.
 void destroy()
           
protected  void executeListener(ContinuousQueryListener listener, com.gemstone.gemfire.cache.query.CqEvent event)
          Execute the specified listener.
 int getPhase()
           
protected  void handleListenerException(Throwable ex)
          Handle the given exception that arose during listener execution.
protected  void invokeErrorHandler(Throwable ex)
          Invoke the registered ErrorHandler, if any.
 boolean isActive()
          Return whether this container is currently active, that is, whether it has been set up but not shut down yet.
 boolean isAutoStartup()
           
 boolean isRunning()
           
 void setBeanName(String name)
           
 void setCache(com.gemstone.gemfire.cache.RegionService cache)
          Set the underlying cache used for registering queries.
 void setErrorHandler(ErrorHandler errorHandler)
          Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a event.
 void setPoolName(String poolName)
          Set the name of the Pool used for performing the queries by this container.
 void setQueryListeners(Set<ContinuousQueryDefinition> queries)
          Attaches the given query definitions.
 void setQueryService(com.gemstone.gemfire.cache.query.QueryService service)
          Set the query service to be used by this container.
 void setTaskExecutor(Executor taskExecutor)
          Sets the task executor used for running the event listeners when messages are received.
 void start()
           
 void stop()
           
 void stop(Runnable callback)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses


DEFAULT_THREAD_NAME_PREFIX

public static final String DEFAULT_THREAD_NAME_PREFIX
Default thread name prefix: "ContinousQueryListenerContainer-".

Constructor Detail

ContinuousQueryListenerContainer

public ContinuousQueryListenerContainer()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

createDefaultTaskExecutor

protected TaskExecutor createDefaultTaskExecutor()
Creates a default TaskExecutor. Called if no explicit TaskExecutor has been specified.

The default implementation builds a SimpleAsyncTaskExecutor with the specified bean name (or the class name, if no bean name specified) as thread name prefix.

See Also:
SimpleAsyncTaskExecutor.SimpleAsyncTaskExecutor(String)

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface DisposableBean
Throws:
Exception

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface SmartLifecycle

stop

public void stop(Runnable callback)
Specified by:
stop in interface SmartLifecycle

getPhase

public int getPhase()
Specified by:
getPhase in interface Phased

isRunning

public boolean isRunning()
Specified by:
isRunning in interface Lifecycle

start

public void start()
Specified by:
start in interface Lifecycle

stop

public void stop()
Specified by:
stop in interface Lifecycle

executeListener

protected void executeListener(ContinuousQueryListener listener,
                               com.gemstone.gemfire.cache.query.CqEvent event)
Execute the specified listener.

See Also:
handleListenerException(java.lang.Throwable)

isActive

public final boolean isActive()
Return whether this container is currently active, that is, whether it has been set up but not shut down yet.


handleListenerException

protected void handleListenerException(Throwable ex)
Handle the given exception that arose during listener execution.

The default implementation logs the exception at error level. This can be overridden in subclasses.

Parameters:
ex - the exception to handle

invokeErrorHandler

protected void invokeErrorHandler(Throwable ex)
Invoke the registered ErrorHandler, if any. Log at error level otherwise.

Parameters:
ex - the uncaught error that arose during event processing.
See Also:
setErrorHandler(org.springframework.util.ErrorHandler)

setBeanName

public void setBeanName(String name)
Specified by:
setBeanName in interface BeanNameAware

setTaskExecutor

public void setTaskExecutor(Executor taskExecutor)
Sets the task executor used for running the event listeners when messages are received. If no task executor is set, an instance of SimpleAsyncTaskExecutor 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 taskExecutor to set.

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a event. By default there will be no ErrorHandler so that error-level logging is the only result.


setCache

public void setCache(com.gemstone.gemfire.cache.RegionService cache)
Set the underlying cache used for registering queries.

Parameters:
cache - cache used for registering queries

setQueryService

public void setQueryService(com.gemstone.gemfire.cache.query.QueryService service)
Set the query service to be used by this container.

Parameters:
service - query service used by the container

setPoolName

public void setPoolName(String poolName)
Set the name of the Pool used for performing the queries by this container.

Parameters:
poolName - the name of the pool to be used by the container

setQueryListeners

public void setQueryListeners(Set<ContinuousQueryDefinition> queries)
Attaches the given query definitions.

Parameters:
queries - set of queries

addListener

public void addListener(ContinuousQueryDefinition cqQuery)
Adds a query definition to the (potentially running) container. If the container is running, the listener starts receiving (matching) messages as soon as possible.

Parameters:
cqQuery - cqQuery definition