public abstract class AbstractEventListenerContainer extends Object implements org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>, ServiceDetailsProvider, ServiceMonitorsProvider, ProcessingUnitContainerContextAware, 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 org.apache.commons.logging.Log |
logger |
protected ThreadLocal<EntrySnapshot> |
snapshotTemplateThreadLocal |
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,
org.springframework.transaction.TransactionStatus txStatus,
Object source)
Executes the given listener if the container is running (
isRunning() . |
protected Object |
getActualEventListener() |
org.springframework.context.ApplicationContext |
getApplicationContext() |
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() |
EventExceptionHandler |
getExceptionHandler() |
long |
getFailedEvents() |
GigaSpace |
getGigaSpace()
Returns the GigaSpace instance to be used for Space operations.
|
long |
getProcessedEvents() |
Object |
getReceiveTemplate()
Returns the template to be used for receive operations.
|
protected String |
getStatus() |
Object |
getTemplate()
Returns the template that will be used.
|
protected org.springframework.transaction.support.DefaultTransactionDefinition |
getTransactionDefinition() |
org.springframework.transaction.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.
|
protected void |
incrementFailedEvents() |
void |
initialize()
Initialize this container.
|
protected void |
invokeExceptionListener(Exception e)
A callback to handle exception.
|
protected void |
invokeListener(SpaceDataEventListener eventListener,
Object eventData,
org.springframework.transaction.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.
|
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.
|
boolean |
isTransactional() |
protected String |
message(String message) |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)
If the
setActiveWhenPrimary(boolean) is set to true (the default), the
container lifecycle will be controlled by the space mode. |
void |
process(InternalDump dump) |
protected void |
registerMetrics() |
protected boolean |
requiresStopStart() |
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(org.springframework.context.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 |
setPerformSnapshot(boolean performSnapshot)
If set to
true will perform prepareTemplate operation on the provided template before
invoking registering as an event listener. |
void |
setProcessingUnitContainerContext(ProcessingUnitContainerContext processingUnitContainerContext)
Sets the processing unit container context.
|
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(org.springframework.transaction.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 |
unregisterMetrics() |
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
getName
protected final org.apache.commons.logging.Log logger
protected String beanName
protected EventExceptionHandler exceptionHandler
protected boolean disableTransactionValidation
protected ThreadLocal<EntrySnapshot> snapshotTemplateThreadLocal
public void setGigaSpace(GigaSpace gigaSpace)
public final GigaSpace getGigaSpace()
public void setBeanName(String beanName)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public 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()
isRunning
in interface org.springframework.context.Lifecycle
public final boolean isActive()
protected String getStatus()
public 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(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
public void setProcessingUnitContainerContext(ProcessingUnitContainerContext processingUnitContainerContext)
ProcessingUnitContainerContextAware
setProcessingUnitContainerContext
in interface ProcessingUnitContainerContextAware
processingUnitContainerContext
- The processing unit container context to be injectedpublic org.springframework.context.ApplicationContext getApplicationContext()
protected Class<?> getEventListenerClass()
public void afterPropertiesSet()
validateConfiguration()
and initialize()
.afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public void initialize() throws org.springframework.dao.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.org.springframework.dao.DataAccessException
onApplicationEvent(org.springframework.context.ApplicationEvent)
protected abstract void doInitialize() throws org.springframework.dao.DataAccessException
org.springframework.dao.DataAccessException
protected void validateConfiguration()
public void destroy()
shutdown()
when the BeanFactory destroys the container instance.destroy
in interface org.springframework.beans.factory.DisposableBean
shutdown()
public void shutdown() throws org.springframework.dao.DataAccessException
doShutdown()
, and close this container.org.springframework.dao.DataAccessException
protected abstract void doShutdown() throws org.springframework.dao.DataAccessException
org.springframework.dao.DataAccessException
shutdown()
public void start() throws org.springframework.dao.DataAccessException
start
in interface org.springframework.context.Lifecycle
org.springframework.dao.DataAccessException
doStart()
protected void doStart() throws org.springframework.dao.DataAccessException
org.springframework.dao.DataAccessException
protected void doAfterStart() throws org.springframework.dao.DataAccessException
org.springframework.dao.DataAccessException
public void stop() throws org.springframework.dao.DataAccessException
stop
in interface org.springframework.context.Lifecycle
org.springframework.dao.DataAccessException
doStop()
protected void doStop() throws org.springframework.dao.DataAccessException
org.springframework.dao.DataAccessException
protected void doBeforeStop() throws org.springframework.dao.DataAccessException
org.springframework.dao.DataAccessException
public void onApplicationEvent(org.springframework.context.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 org.springframework.context.ApplicationListener<org.springframework.context.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, org.springframework.transaction.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, org.springframework.transaction.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)Throwable
protected void handleListenerException(Throwable ex)
ex
- the exception to handleprotected void invokeExceptionListener(Exception e)
public long getProcessedEvents()
public long getFailedEvents()
protected void incrementFailedEvents()
public void setTemplate(Object template)
GigaSpace.take(Object, long)
public 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
public boolean isDynamicTemplate()
public void setPerformSnapshot(boolean performSnapshot)
true
will perform prepareTemplate operation on the provided template before
invoking registering as an event listener.GigaSpace.prepareTemplate(Object)
protected boolean isPerformSnapshot()
public Object getReceiveTemplate()
setPerformSnapshot(boolean)
is set to true
(the default) will return the
snapshot of the provided template.public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
PlatformTransactionManager
to use
for transactional wrapping of listener execution.
Default is none, not performing any transactional wrapping.
public final org.springframework.transaction.PlatformTransactionManager getTransactionManager()
public void setTransactionName(String transactionName)
TransactionDefinition.getName()
public void setTransactionTimeout(int transactionTimeout)
TransactionDefinition.getTimeout()
public void setTransactionIsolationLevel(int transactionIsolationLevel)
DefaultTransactionDefinition.setIsolationLevel(int)
public void setTransactionIsolationLevelName(String transactionIsolationLevelName)
DefaultTransactionDefinition.setIsolationLevelName(String)
protected org.springframework.transaction.support.DefaultTransactionDefinition getTransactionDefinition()
public void setDisableTransactionValidation(boolean disableTransactionValidation)
false
.public String getTransactionManagerName()
public boolean isTransactional()
protected boolean requiresStopStart()
public void process(InternalDump dump) throws InternalDumpProcessorFailedException
process
in interface InternalDumpProcessor
InternalDumpProcessorFailedException
protected void dump(PrintWriter writer)
protected abstract String getEventListenerContainerType()
protected void registerMetrics()
protected void unregisterMetrics()
Copyright © GigaSpaces.