public abstract class AbstractEventListenerContainer extends Object implements ApplicationContextAware, Lifecycle, BeanNameAware, InitializingBean, DisposableBean, ApplicationListener<ApplicationEvent>, QuiesceStateChangedListener, ServiceDetailsProvider, ServiceMonitorsProvider, ServiceMetricProvider, com.gigaspaces.internal.dump.InternalDumpProcessor
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.Modifier and Type | Field and Description |
---|---|
protected String |
beanName |
protected boolean |
disableTransactionValidation |
protected EventExceptionHandler |
exceptionHandler |
protected Log |
logger |
Constructor and Description |
---|
AbstractEventListenerContainer() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Delegates to
validateConfiguration() and initialize() . |
void |
destroy()
Calls
shutdown() when the BeanFactory destroys the container instance. |
protected void |
doAfterStart() |
protected void |
doBeforeStop() |
protected abstract void |
doInitialize()
A callback to perform custom initialization steps.
|
protected void |
doRescheduleTask(Object task)
Reschedule the given task object immediately.
|
protected abstract void |
doShutdown()
Perform any custom shutdown operations.
|
protected void |
doStart()
Only start if we have a listener registered.
|
protected void |
doStop()
Notify all invoker tasks to stop
|
protected void |
dump(PrintWriter writer) |
protected void |
executeListener(SpaceDataEventListener eventListener,
Object eventData,
TransactionStatus txStatus,
Object source)
Executes the given listener if the container is running (
isRunning() . |
protected Object |
getActualEventListener() |
protected ApplicationContext |
getApplicationContext() |
protected String |
getBeanName()
Return the bean name that this listener container has been assigned in its containing bean
factory, if any.
|
protected SpaceDataEventListener |
getEventListener() |
protected Class<?> |
getEventListenerClass() |
protected abstract String |
getEventListenerContainerType() |
protected EventExceptionHandler |
getExceptionHandler() |
long |
getFailedEvents() |
protected GigaSpace |
getGigaSpace()
Returns the GigaSpace instance to be used for Space operations.
|
String |
getMetricPrefix() |
long |
getProcessedEvents() |
protected Object |
getReceiveTemplate()
Returns the template to be used for receive operations.
|
protected String |
getStatus() |
protected Object |
getTemplate()
Returns the template that will be used.
|
protected DefaultTransactionDefinition |
getTransactionDefinition() |
protected PlatformTransactionManager |
getTransactionManager()
Return the Spring PlatformTransactionManager to use for transactional wrapping of message
reception plus listener execution.
|
String |
getTransactionManagerName() |
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. |
boolean |
isActive()
Return whether this container is currently active, that is, whether it has been set up but
not shut down yet.
|
protected boolean |
isDynamicTemplate()
Returns whether dynamic template is configured
|
protected boolean |
isPerformSnapshot() |
boolean |
isRunning()
Return whether this container is currently running, that is, whether it has been started and
not stopped yet.
|
protected boolean |
isTransactional() |
protected String |
message(String message) |
void |
onApplicationEvent(ApplicationEvent applicationEvent)
If the
setActiveWhenPrimary(boolean) is set to true (the default),
the container lifecycle will be controlled by the space mode. |
void |
process(com.gigaspaces.internal.dump.InternalDump dump) |
void |
quiesceStateChanged(com.gigaspaces.admin.quiesce.QuiesceStateChangedEvent event) |
protected void |
registerMetrics() |
protected boolean |
rescheduleTaskIfNecessary(Object task)
Take the given task object and reschedule it, either immediately if this container is
currently running, or later once this container has been restarted.
|
void |
setActiveWhenPrimary(boolean activeWhenPrimary)
Set whether this container will start only when it is primary (space mode).
|
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setAutoStart(boolean initOnStartup)
Set whether this container will start once instantiated.
|
void |
setBeanName(String beanName) |
void |
setDisableTransactionValidation(boolean disableTransactionValidation)
Should transaction validation be enabled or not (verify and fail if transaction manager is
provided and the GigaSpace is not transactional).
|
void |
setDynamicTemplate(Object dynamicTemplate)
Called before each take and read polling operation to change the template
Overrides any template defined with
setTemplate(Object) |
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.
|
void |
setGigaSpace(GigaSpace gigaSpace)
Sets the GigaSpace instance to be used for space event listening operations.
|
void |
setMetricRegistrator(com.gigaspaces.metrics.MetricRegistrator metricRegistrator) |
void |
setPerformSnapshot(boolean performSnapshot)
If set to
true will perform snapshot operation on the provided template
before invoking registering as an event listener. |
void |
setRegisterSpaceModeListener(boolean registerSpaceModeListener) |
void |
setTemplate(Object template)
Sets the specified template to be used with the polling space operation.
|
void |
setTransactionIsolationLevel(int transactionIsolationLevel)
Specify the transaction isolation to use for transactional wrapping.
|
void |
setTransactionIsolationLevelName(String transactionIsolationLevelName)
Specify the transaction isolation to use for transactional wrapping.
|
void |
setTransactionManager(PlatformTransactionManager transactionManager)
Specify the Spring
PlatformTransactionManager to use
for transactional wrapping of listener execution. |
void |
setTransactionName(String transactionName)
Specify the transaction name to use for transactional wrapping.
|
void |
setTransactionTimeout(int transactionTimeout)
Specify the transaction timeout to use for transactional wrapping, in seconds.
|
void |
shutdown()
Stop container, call
doShutdown() , and close this container. |
void |
start()
Start this container.
|
void |
stop()
Stop this container.
|
protected void |
validateConfiguration()
Validate the configuration of this container.
|
protected void |
waitWhileNotRunning()
Wait while this container is not running.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getServicesDetails
getServicesMonitors
protected final Log logger
protected String beanName
protected EventExceptionHandler exceptionHandler
protected boolean disableTransactionValidation
public void setGigaSpace(GigaSpace gigaSpace)
protected final GigaSpace getGigaSpace()
public void setBeanName(String beanName)
setBeanName
in interface BeanNameAware
protected final String getBeanName()
public void setActiveWhenPrimary(boolean activeWhenPrimary)
Default is true
. Set to false
in order for this container to
always start regardless of the space mode.
public void setRegisterSpaceModeListener(boolean registerSpaceModeListener)
public void setAutoStart(boolean initOnStartup)
Default is true
. Set to false
in order for this container to
be started using start()
.
public final boolean isRunning()
public final boolean isActive()
protected String getStatus()
protected EventExceptionHandler getExceptionHandler()
public void setExceptionHandler(EventExceptionHandler exceptionHandler)
public void setEventListener(SpaceDataEventListener eventListener)
eventListener
- The event listener usedpublic void setEventListenerRef(String eventListenerRef)
getBean
for each
request of the listener.protected SpaceDataEventListener getEventListener()
protected Object getActualEventListener()
public void setApplicationContext(ApplicationContext applicationContext)
setApplicationContext
in interface ApplicationContextAware
protected ApplicationContext getApplicationContext()
protected Class<?> getEventListenerClass()
public void afterPropertiesSet()
validateConfiguration()
and initialize()
.afterPropertiesSet
in interface InitializingBean
public void initialize() throws DataAccessException
true
will call doStart()
(if it is set to true
,
lifecycle of the container will be controlled by the current space mode).
doInitialize()
will be called for additional initialization after the possible
doStart()
call.protected abstract void doInitialize() throws DataAccessException
DataAccessException
protected void validateConfiguration()
public void destroy()
shutdown()
when the BeanFactory destroys the container instance.destroy
in interface DisposableBean
shutdown()
public void shutdown() throws DataAccessException
doShutdown()
, and close this container.DataAccessException
protected abstract void doShutdown() throws DataAccessException
DataAccessException
shutdown()
public void start() throws DataAccessException
start
in interface Lifecycle
DataAccessException
doStart()
protected void doStart() throws DataAccessException
DataAccessException
protected void doAfterStart() throws DataAccessException
DataAccessException
public void stop() throws DataAccessException
stop
in interface Lifecycle
DataAccessException
doStop()
protected void doStop() throws DataAccessException
DataAccessException
protected void doBeforeStop() throws DataAccessException
DataAccessException
public void onApplicationEvent(ApplicationEvent applicationEvent)
setActiveWhenPrimary(boolean)
is set to true
(the default),
the container lifecycle will be controlled by the space mode. The container will start when
the space is in PRIMARY
mode, and will stop when the space is in
BACKUP
mode.
Note, this might cause doStart()
or doStop()
to be called several times in
a row, and sub classes should take this into account.
onApplicationEvent
in interface ApplicationListener<ApplicationEvent>
protected final void waitWhileNotRunning()
To be called by asynchronous tasks that want to block while the container is in stopped state.
protected final boolean rescheduleTaskIfNecessary(Object task)
If this container has already been shut down, the task will not get rescheduled at all.
task
- the task object to rescheduledoRescheduleTask(java.lang.Object)
protected void doRescheduleTask(Object task)
To be implemented by subclasses if they ever call rescheduleTaskIfNecessary
.
This implementation throws an UnsupportedOperationException.
task
- the task object to reschedulerescheduleTaskIfNecessary(java.lang.Object)
protected void executeListener(SpaceDataEventListener eventListener, Object eventData, TransactionStatus txStatus, Object source) throws Throwable
isRunning()
.eventData
- The event data objecttxStatus
- An optional transaction status allowing to rollback a transaction programmaticallysource
- An optional source (or additional event information)Throwable
protected void invokeListener(SpaceDataEventListener eventListener, Object eventData, TransactionStatus txStatus, Object source) throws Throwable
SpaceDataEventListener
based on the
provided data. Currently simply delegates to
SpaceDataEventListener.onEvent(Object,org.openspaces.core.GigaSpace,org.springframework.transaction.TransactionStatus,Object)
.eventData
- The event data objecttxStatus
- An optional transaction status allowing to rollback a transaction programmaticallysource
- An optional source (or additional event information)DataAccessException
Throwable
protected void handleListenerException(Throwable ex)
ex
- the exception to handleprotected void invokeExceptionListener(Exception e)
public long getProcessedEvents()
public long getFailedEvents()
public void setTemplate(Object template)
GigaSpace.take(Object,long)
protected Object getTemplate()
getReceiveTemplate()
should be used.public void setDynamicTemplate(Object dynamicTemplate)
setTemplate(Object)
dynamicTemplate
- -
An object that implements DynamicEventTemplateProvider
or has a method annotated with DynamicEventTemplateProvider
protected boolean isDynamicTemplate()
public void setPerformSnapshot(boolean performSnapshot)
true
will perform snapshot operation on the provided template
before invoking registering as an event listener.GigaSpace.snapshot(Object)
protected boolean isPerformSnapshot()
protected Object getReceiveTemplate()
setPerformSnapshot(boolean)
is set to true
(the default)
will return the snapshot of the provided template.public void setTransactionManager(PlatformTransactionManager transactionManager)
PlatformTransactionManager
to use
for transactional wrapping of listener execution.
Default is none, not performing any transactional wrapping.
protected final PlatformTransactionManager getTransactionManager()
public void setTransactionName(String transactionName)
TransactionDefinition.getName()
public void setTransactionTimeout(int transactionTimeout)
TransactionDefinition.getTimeout()
public void setTransactionIsolationLevel(int transactionIsolationLevel)
public void setTransactionIsolationLevelName(String transactionIsolationLevelName)
protected DefaultTransactionDefinition getTransactionDefinition()
public void setDisableTransactionValidation(boolean disableTransactionValidation)
false
.public String getTransactionManagerName()
protected boolean isTransactional()
public void quiesceStateChanged(com.gigaspaces.admin.quiesce.QuiesceStateChangedEvent event)
quiesceStateChanged
in interface QuiesceStateChangedListener
public void process(com.gigaspaces.internal.dump.InternalDump dump) throws com.gigaspaces.internal.dump.InternalDumpProcessorFailedException
process
in interface com.gigaspaces.internal.dump.InternalDumpProcessor
com.gigaspaces.internal.dump.InternalDumpProcessorFailedException
protected void dump(PrintWriter writer)
protected abstract String getEventListenerContainerType()
public String getMetricPrefix()
getMetricPrefix
in interface ServiceMetricProvider
public void setMetricRegistrator(com.gigaspaces.metrics.MetricRegistrator metricRegistrator)
setMetricRegistrator
in interface ServiceMetricProvider
protected void registerMetrics()
Copyright © GigaSpaces.