GigaSpaces XAP 10.0.1 API

org.openspaces.events.polling
Class AbstractPollingEventListenerContainer

java.lang.Object
  extended by org.openspaces.events.AbstractSpaceListeningContainer
      extended by org.openspaces.events.AbstractEventListenerContainer
          extended by org.openspaces.events.AbstractTemplateEventListenerContainer
              extended by org.openspaces.events.AbstractTransactionalEventListenerContainer
                  extended by org.openspaces.events.polling.AbstractPollingEventListenerContainer
All Implemented Interfaces:
EventListener, ServiceDetailsProvider, ServiceMonitorsProvider, Aware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ApplicationListener<ApplicationEvent>, Lifecycle
Direct Known Subclasses:
SimplePollingEventListenerContainer

public abstract class AbstractPollingEventListenerContainer
extends AbstractTransactionalEventListenerContainer

Base class for listener container implementations which are based on polling. Provides support for listener handling based on Space take operations.

This listener container variant is built for repeated polling attempts, each invoking the receiveAndExecute(org.openspaces.events.SpaceDataEventListener) method. The receive timeout for each attempt can be configured through the "receiveTimeout" property.

The container allows to set the template object used for the operations. Note, this can be a Pojo based template, or one of GigaSpace's query classes such as SQLQuery.

A pluggable receive operation handler can be provided by setting setReceiveOperationHandler(org.openspaces.events.polling.receive.ReceiveOperationHandler). The default handler used it SingleTakeReceiveOperationHandler.

Event reception and listener execution can automatically be wrapped in transactions through passing a Spring PlatformTransactionManager into the transactionManager property. This will usually be a LocalJiniTransactionManager.

This base class does not assume any specific mechanism for asynchronous execution of polling invokers. Check out SimplePollingEventListenerContainer for a concrete implementation which is based on Spring's TaskExecutor abstraction, including dynamic scaling of concurrent consumers and automatic self recovery.

The AbstractTemplateEventListenerContainer.setTemplate(Object) parameter is required in order to perform matching on which events to receive. If the AbstractEventListenerContainer.setEventListener(org.openspaces.events.SpaceDataEventListener) implements EventTemplateProvider and the template is directly set, the event listener will be used to get the template. This feature helps when event listeners directly can only work with a certain template and removes the requirement of configuring the template as well.

An advance feature allows for pluggable triggerOperationHandler which mainly makes sense when using transactions. The trigger operations handler allows to perform a trigger receive outside of a transaction scope, and if it returned a value, perform the take within a transaction. A useful implementation of it is ReadTriggerOperationHandler.

Author:
kimchy

Field Summary
static long DEFAULT_RECEIVE_TIMEOUT
          The default receive timeout: 60000 ms = 60 seconds = 1 minute.
 
Fields inherited from class org.openspaces.events.AbstractTransactionalEventListenerContainer
disableTransactionValidation
 
Fields inherited from class org.openspaces.events.AbstractEventListenerContainer
exceptionHandler, failedEvents, processedEvents
 
Fields inherited from class org.openspaces.events.AbstractSpaceListeningContainer
beanName, logger
 
Constructor Summary
AbstractPollingEventListenerContainer()
           
 
Method Summary
protected  boolean doReceiveAndExecute(SpaceDataEventListener eventListener, Object template, TransactionStatus status)
           
protected  void eventReceived(Object event)
          Template method that gets called right when a new message has been received, before attempting to process it.
protected  ReceiveOperationHandler getReceiveOperationHandler()
           
protected  long getReceiveTimeout()
          Returns the timeout used for receive calls, in millisecond.
protected  TriggerOperationHandler getTriggerOperationHandler()
           
 void initialize()
          Initialize this container.
protected  boolean isPassArrayAsIs()
           
protected  boolean receiveAndExecute(SpaceDataEventListener eventListener)
          Execute the listener for a message received from the given consumer, wrapping the entire operation in an external transaction if demanded.
protected  Object receiveEvent(Object template)
          Receive an event
 void setPassArrayAsIs(boolean passArrayAsIs)
          If set to true will pass an array value returned from a ReceiveOperationHandler directly to the listener without "serializing" it as one array element each time.
 void setReceiveOperationHandler(ReceiveOperationHandler receiveOperationHandler)
          Allows to set a receive operation handler that will perform the actual receive operation.
 void setReceiveTimeout(long receiveTimeout)
          Set the timeout to use for receive calls, in milliseconds.
 void setTriggerOperationHandler(TriggerOperationHandler triggerOperationHandler)
          An advance feature allows for pluggable triggerOperationHandler which mainly makes sense when using transactions.
protected  void validateConfiguration()
          Validate the configuration of this container.
 
Methods inherited from class org.openspaces.events.AbstractTransactionalEventListenerContainer
getTransactionDefinition, getTransactionManager, getTransactionManagerName, isTransactional, setDisableTransactionValidation, setTransactionIsolationLevel, setTransactionIsolationLevelName, setTransactionManager, setTransactionName, setTransactionTimeout
 
Methods inherited from class org.openspaces.events.AbstractTemplateEventListenerContainer
getReceiveTemplate, getTemplate, isDynamicTemplate, isPerformSnapshot, setDynamicTemplate, setPerformSnapshot, setTemplate
 
Methods inherited from class org.openspaces.events.AbstractEventListenerContainer
doStart, executeListener, getActualEventListener, getApplicationContext, getEventListener, getEventListenerClass, getExceptionHandler, getFailedEvents, getProcessedEvents, handleListenerException, invokeExceptionListener, invokeListener, setApplicationContext, setEventListener, setEventListenerRef, setExceptionHandler
 
Methods inherited from class org.openspaces.events.AbstractSpaceListeningContainer
afterPropertiesSet, destroy, doAfterStart, doBeforeStop, doInitialize, doRescheduleTask, doShutdown, doStop, getBeanName, getGigaSpace, getStatus, isActive, isRunning, message, onApplicationEvent, rescheduleTaskIfNecessary, setActiveWhenPrimary, setAutoStart, setBeanName, setGigaSpace, setRegisterSpaceModeListener, shutdown, start, stop, waitWhileNotRunning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openspaces.pu.service.ServiceDetailsProvider
getServicesDetails
 
Methods inherited from interface org.openspaces.pu.service.ServiceMonitorsProvider
getServicesMonitors
 

Field Detail

DEFAULT_RECEIVE_TIMEOUT

public static final long DEFAULT_RECEIVE_TIMEOUT
The default receive timeout: 60000 ms = 60 seconds = 1 minute.

See Also:
Constant Field Values
Constructor Detail

AbstractPollingEventListenerContainer

public AbstractPollingEventListenerContainer()
Method Detail

validateConfiguration

protected void validateConfiguration()
Description copied from class: AbstractSpaceListeningContainer
Validate the configuration of this container.

Overrides:
validateConfiguration in class AbstractTransactionalEventListenerContainer

setPassArrayAsIs

public void setPassArrayAsIs(boolean passArrayAsIs)
If set to true will pass an array value returned from a ReceiveOperationHandler directly to the listener without "serializing" it as one array element each time. Defaults to false


isPassArrayAsIs

protected boolean isPassArrayAsIs()

setReceiveTimeout

public void setReceiveTimeout(long receiveTimeout)
Set the timeout to use for receive calls, in milliseconds. The default is 60000 ms, that is, 1 minute.

NOTE: This value needs to be smaller than the transaction timeout used by the transaction manager (in the appropriate unit, of course).

See Also:
GigaSpace.take(Object,long)

getReceiveTimeout

protected long getReceiveTimeout()
Returns the timeout used for receive calls, in millisecond. The default is 60000 ms, that is, 1 minute.


setReceiveOperationHandler

public void setReceiveOperationHandler(ReceiveOperationHandler receiveOperationHandler)
Allows to set a receive operation handler that will perform the actual receive operation. Defaults to SingleTakeReceiveOperationHandler.


getReceiveOperationHandler

protected ReceiveOperationHandler getReceiveOperationHandler()

setTriggerOperationHandler

public void setTriggerOperationHandler(TriggerOperationHandler triggerOperationHandler)
An advance feature allows for pluggable triggerOperationHandler which mainly makes sense when using transactions. The trigger operations handler allows to perform a trigger receive outside of a transaction scope, and if it returned a value, perform the take within a transaction. A useful implementation of it is ReadTriggerOperationHandler. Defaults to null.


getTriggerOperationHandler

protected TriggerOperationHandler getTriggerOperationHandler()

initialize

public void initialize()
Description copied from class: AbstractSpaceListeningContainer
Initialize this container. If this container is not configured with "activeWhenPrimary" flag set to true will call AbstractSpaceListeningContainer.doStart() (if it is set to true, lifecycle of the container will be controlled by the current space mode). AbstractSpaceListeningContainer.doInitialize() will be called for additional initialization after the possible AbstractSpaceListeningContainer.doStart() call.

Overrides:
initialize in class AbstractTransactionalEventListenerContainer
See Also:
AbstractSpaceListeningContainer.onApplicationEvent(org.springframework.context.ApplicationEvent)

receiveAndExecute

protected boolean receiveAndExecute(SpaceDataEventListener eventListener)
                             throws Throwable,
                                    TransactionException
Execute the listener for a message received from the given consumer, wrapping the entire operation in an external transaction if demanded.

Throws:
Throwable
TransactionException
See Also:
doReceiveAndExecute(org.openspaces.events.SpaceDataEventListener, java.lang.Object, org.springframework.transaction.TransactionStatus)

doReceiveAndExecute

protected boolean doReceiveAndExecute(SpaceDataEventListener eventListener,
                                      Object template,
                                      TransactionStatus status)

receiveEvent

protected Object receiveEvent(Object template)
                       throws DataAccessException
Receive an event

Throws:
DataAccessException

eventReceived

protected void eventReceived(Object event)
Template method that gets called right when a new message has been received, before attempting to process it. Allows subclasses to react to the event of an actual incoming message, for example adapting their consumer count.


GigaSpaces XAP 10.0.1 API

Copyright © GigaSpaces.