GigaSpaces XAP 7.0 API

org.openspaces.events
Class AbstractEventListenerContainer

java.lang.Object
  extended by org.openspaces.events.AbstractSpaceListeningContainer
      extended by org.openspaces.events.AbstractEventListenerContainer
All Implemented Interfaces:
EventListener, ServiceDetailsProvider, ServiceMonitorsProvider, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ApplicationListener, Lifecycle
Direct Known Subclasses:
AbstractTemplateEventListenerContainer

public abstract class AbstractEventListenerContainer
extends AbstractSpaceListeningContainer
implements ApplicationContextAware

A simple based class for SpaceDataEventListener based containers. Allowing to register a listener and provides several support methods like invokeListener(SpaceDataEventListener, Object, org.springframework.transaction.TransactionStatus, Object) in order to simplify event listener based containers.

Author:
kimchy

Field Summary
protected  AtomicLong failedEvents
           
protected  AtomicLong processedEvents
           
 
Fields inherited from class org.openspaces.events.AbstractSpaceListeningContainer
beanName, logger
 
Constructor Summary
AbstractEventListenerContainer()
           
 
Method Summary
protected  void doStart()
          Only start if we have a listener registered.
protected  void executeListener(SpaceDataEventListener eventListener, Object eventData, TransactionStatus txStatus, Object source)
          Executes the given listener if the container is running (AbstractSpaceListeningContainer.isRunning().
protected  Object getActualEventListener()
           
protected  ApplicationContext getApplicationContext()
           
protected  SpaceDataEventListener getEventListener()
           
protected  Class getEventListenerClass()
           
 long getFailedEvents()
           
 long getProcessedEvents()
           
protected  void handleListenerException(Throwable ex)
          Handles exception that occurs during the event listening process.
protected  void invokeExceptionListener(Exception e)
          A callback to handle exception.
protected  void invokeListener(SpaceDataEventListener eventListener, Object eventData, TransactionStatus txStatus, Object source)
          Invokes the configured SpaceDataEventListener based on the provided data.
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setEventListener(SpaceDataEventListener eventListener)
          Sets the event listener implementation that will be used to delegate events to.
 void setEventListenerRef(String eventListenerRef)
          Sets an event listener bean reference name that will be used to lookup the actual listener bean (based on its name).
 
Methods inherited from class org.openspaces.events.AbstractSpaceListeningContainer
afterPropertiesSet, destroy, doAfterStart, doBeforeStop, doInitialize, doRescheduleTask, doShutdown, doStop, getBeanName, getGigaSpace, getStatus, initialize, isActive, isRunning, message, onApplicationEvent, rescheduleTaskIfNecessary, setActiveWhenPrimary, setAutoStart, setBeanName, setGigaSpace, setRegisterSpaceModeListener, shutdown, start, stop, validateConfiguration, 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

processedEvents

protected final AtomicLong processedEvents

failedEvents

protected final AtomicLong failedEvents
Constructor Detail

AbstractEventListenerContainer

public AbstractEventListenerContainer()
Method Detail

setEventListener

public void setEventListener(SpaceDataEventListener eventListener)
Sets the event listener implementation that will be used to delegate events to. Also see different adapter classes provided for simpler event listeners integration.

Parameters:
eventListener - The event listener used

setEventListenerRef

public void setEventListenerRef(String eventListenerRef)
Sets an event listener bean reference name that will be used to lookup the actual listener bean (based on its name). Mainly used when configuring a listener with specific scope setting (such as prototype) allowing to scope to take affect by using getBean for each request of the listener.


getEventListener

protected SpaceDataEventListener getEventListener()

getActualEventListener

protected Object getActualEventListener()

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
Specified by:
setApplicationContext in interface ApplicationContextAware

getApplicationContext

protected ApplicationContext getApplicationContext()

getEventListenerClass

protected Class getEventListenerClass()

doStart

protected void doStart()
                throws DataAccessException
Only start if we have a listener registered. If we don't, then explicit start should be called.

Overrides:
doStart in class AbstractSpaceListeningContainer
Throws:
DataAccessException

executeListener

protected void executeListener(SpaceDataEventListener eventListener,
                               Object eventData,
                               TransactionStatus txStatus,
                               Object source)
                        throws DataAccessException
Executes the given listener if the container is running (AbstractSpaceListeningContainer.isRunning().

Parameters:
eventData - The event data object
txStatus - An optional transaction status allowing to rollback a transaction programmatically
source - An optional source (or additional event information)
Throws:
DataAccessException

invokeListener

protected void invokeListener(SpaceDataEventListener eventListener,
                              Object eventData,
                              TransactionStatus txStatus,
                              Object source)
                       throws DataAccessException
Invokes the configured SpaceDataEventListener based on the provided data. Currently simply delegates to SpaceDataEventListener.onEvent(Object,org.openspaces.core.GigaSpace,org.springframework.transaction.TransactionStatus,Object).

Parameters:
eventData - The event data object
txStatus - An optional transaction status allowing to rollback a transaction programmatically
source - An optional source (or additional event information)
Throws:
DataAccessException

handleListenerException

protected void handleListenerException(Throwable ex)
Handles exception that occurs during the event listening process. Currently simply logs it.

Parameters:
ex - the exception to handle

invokeExceptionListener

protected void invokeExceptionListener(Exception e)
A callback to handle exception. Possible extension point for registered exception listeners.


getProcessedEvents

public long getProcessedEvents()

getFailedEvents

public long getFailedEvents()

GigaSpaces XAP 7.0 API

Copyright © GigaSpaces.