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:
  • Field Details

    • DEFAULT_THREAD_NAME_PREFIX

      public static final String DEFAULT_THREAD_NAME_PREFIX
    • DEFAULT_POOL_RESOLVER

      protected static final PoolResolver 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 interface org.springframework.beans.factory.InitializingBean
    • applyContinuousQueryListenerContainerConfigurers

      protected void applyContinuousQueryListenerContainerConfigurers(ContinuousQueryListenerContainerConfigurer... configurers)
      Applies an array of ContinuousQueryListenerContainerConfigurer objects to customize the configuration of this ContinuousQueryListenerContainer.
      Parameters:
      configurers - array of ContinuousQueryListenerContainerConfigurer used to customize the configuration of this ContinuousQueryListenerContainer.
      See Also:
    • applyContinuousQueryListenerContainerConfigurers

      protected void applyContinuousQueryListenerContainerConfigurers(Iterable<ContinuousQueryListenerContainerConfigurer> configurers)
      Applies an Iterable of ContinuousQueryListenerContainerConfigurer objects to customize the configuration of this ContinuousQueryListenerContainer.
      Parameters:
      configurers - Iterable of ContinuousQueryListenerContainerConfigurer used to customize the configuration of this ContinuousQueryListenerContainer.
      See Also:
    • createDefaultTaskExecutor

      protected Executor createDefaultTaskExecutor()
      Creates a default TaskExecutor.

      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 interface org.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 interface org.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 the BeanFactory containing this bean.
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Parameters:
      beanFactory - the Spring BeanFactory 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 configured BeanFactory.
      Returns:
      a reference to the configured BeanFactory.
      See Also:
      • BeanFactory
    • setBeanName

      public void setBeanName(String name)
      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 interface org.springframework.beans.factory.BeanNameAware
      Parameters:
      name - the name of the bean in the factory.
    • getBeanName

      protected String getBeanName()
      Returns the configured bean 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

      protected Queue<org.apache.geode.cache.query.CqQuery> getContinuousQueries()
      Returns a reference to all the configured/registered Continuous Queries.
      Returns:
      a reference to all the configured/registered Continuous Queries.
      See Also:
    • getContinuousQueryDefinitions

      protected Set<ContinuousQueryDefinition> getContinuousQueryDefinitions()
      Returns a reference to all the configured ContinuousQueryDefinitions.
      Returns:
      a reference to all the configured ContinuousQueryDefinitions.
      See Also:
    • setContinuousQueryListenerContainerConfigurers

      public void setContinuousQueryListenerContainerConfigurers(ContinuousQueryListenerContainerConfigurer... configurers)
      Null-safe operation setting an array of ContinuousQueryListenerContainerConfigurer objects used to customize the configuration of this ContinuousQueryListenerContainer.
      Parameters:
      configurers - array of ContinuousQueryListenerContainerConfigurer objects used to customize the configuration of this ContinuousQueryListenerContainer.
      See Also:
    • setContinuousQueryListenerContainerConfigurers

      public void setContinuousQueryListenerContainerConfigurers(List<ContinuousQueryListenerContainerConfigurer> configurers)
      Null-safe operation setting an Iterable of ContinuousQueryListenerContainerConfigurer objects used to customize the configuration of this ContinuousQueryListenerContainer.
      Parameters:
      configurers - Iterable of ContinuousQueryListenerContainerConfigurer objects used to customize the configuration of this ContinuousQueryListenerContainer.
      See Also:
    • getCompositeContinuousQueryListenerContainerConfigurer

      protected ContinuousQueryListenerContainerConfigurer getCompositeContinuousQueryListenerContainerConfigurer()
      Returns a Composite object containing the collection of ContinuousQueryListenerContainerConfigurer objects used to customize the configuration of this ContinuousQueryListenerContainer.
      Returns:
      a Composite object containing a collection of ContinuousQueryListenerContainerConfigurer objects used to customize the configuration of this ContinuousQueryListenerContainer.
      See Also:
    • setErrorHandler

      public void setErrorHandler(org.springframework.util.ErrorHandler errorHandler)
      Set an ErrorHandler to be invoked in case of any uncaught Exceptions thrown while processing a CQ event. By default there is no ErrorHandler configured so error-level logging is the only result.
      Parameters:
      errorHandler - ErrorHandler invoked when uncaught Exceptions are thrown while processing the CQ event.
      See Also:
      • ErrorHandler
    • getErrorHandler

      public Optional<org.springframework.util.ErrorHandler> getErrorHandler()
      Returns an Optional reference to the configured ErrorHandler invoked when any unhandled Exceptions are thrown when invoking CQ listeners processing CQ events.
      Returns:
      an Optional reference to the configured ErrorHandler.
      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 interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
      Returns:
      the phase value of this CQ listener container.
      See Also:
      • Phased.getPhase()
    • 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
    • getPoolName

      public String getPoolName()
      Returns the configured pool name.
      Returns:
      the configured pool name.
    • setPoolResolver

      public void setPoolResolver(PoolResolver poolResolver)
      Configures the PoolResolver to resolve Pool objects by name from the Apache Geode cache.
      Parameters:
      poolResolver - the configured PoolResolver used to resolve Pool objects by name.
      See Also:
    • getPoolResolver

      public PoolResolver getPoolResolver()
      Returns the configured PoolResolver used to resolve Pool object by name.
      Returns:
      the configured PoolResolver.
      See Also:
    • setQueryListeners

      public void setQueryListeners(Set<ContinuousQueryDefinition> queries)
      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 configured QueryService.
      Returns:
      a reference to the configured QueryService.
      See Also:
      • QueryService
    • 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 Task Executor used to run event listeners when query results messages are received.
      See Also:
    • getTaskExecutor

      public Executor getTaskExecutor()
      Returns a reference to the configured TaskExecutor.
      Returns:
      a reference to the configured TaskExecutor.
      See Also:
    • addListener

      public void addListener(ContinuousQueryDefinition definition)
      Adds a Continuous 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

      public boolean addContinuousQueryDefinition(ContinuousQueryDefinition definition)
    • newCqListener

      protected org.apache.geode.cache.query.CqListener newCqListener(ContinuousQueryListener listener)
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • dispatchEvent

      protected void dispatchEvent(ContinuousQueryListener listener, org.apache.geode.cache.query.CqEvent event)
      Asynchronously dispatches the CQ event to the targeted ContinuousQueryListener.
      Parameters:
      listener - ContinuousQueryListener which will process/handle the CQ event.
      event - CQ event to process.
      See Also:
    • stop

      public void stop(Runnable callback)
      Specified by:
      stop in interface org.springframework.context.SmartLifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean