GigaSpaces XAP 9.7.2 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, Aware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ApplicationListener<ApplicationEvent>, 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  EventExceptionHandler exceptionHandler
           
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()
           
protected  EventExceptionHandler getExceptionHandler()
           
 long getFailedEvents()
           
 long getProcessedEvents()
           
protected  void handleListenerException(Throwable ex)
          Handles exception that occurs during the event listening process.
 void initialize()
          Initialize this container.
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).
 void setExceptionHandler(EventExceptionHandler exceptionHandler)
          Sets an exception handler that will be invoked when an exception occurs on the listener allowing to customize the handling of such cases.
 
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, 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

exceptionHandler

protected EventExceptionHandler exceptionHandler

processedEvents

protected final AtomicLong processedEvents

failedEvents

protected final AtomicLong failedEvents
Constructor Detail

AbstractEventListenerContainer

public AbstractEventListenerContainer()
Method Detail

getExceptionHandler

protected EventExceptionHandler getExceptionHandler()

setExceptionHandler

public void setExceptionHandler(EventExceptionHandler exceptionHandler)
Sets an exception handler that will be invoked when an exception occurs on the listener allowing to customize the handling of such cases.


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()

initialize

public void initialize()
                throws DataAccessException
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 AbstractSpaceListeningContainer
Throws:
DataAccessException
See Also:
AbstractSpaceListeningContainer.onApplicationEvent(org.springframework.context.ApplicationEvent)

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 Throwable
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:
Throwable

invokeListener

protected void invokeListener(SpaceDataEventListener eventListener,
                              Object eventData,
                              TransactionStatus txStatus,
                              Object source)
                       throws Throwable
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
Throwable

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 9.7.2 API

Copyright © GigaSpaces.