GigaSpaces XAP 9.7.2 API

org.openspaces.events
Class AbstractSpaceListeningContainer

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

public abstract class AbstractSpaceListeningContainer
extends Object
implements Lifecycle, BeanNameAware, InitializingBean, DisposableBean, ApplicationListener<ApplicationEvent>, ServiceDetailsProvider, ServiceMonitorsProvider

Common base class for all containers which need to implement listening based on Space events.

Provide lifecycle support for containers using doStart() and doStop(). By default, the container lifecycle will be bound to the space mode, starting when the space mode is PRIMARY and stopping otherwise. This behavior is controlled by setActiveWhenPrimary(boolean). Note that most operations can not be performed directly against a backup space cluster member (when working with the GigaSpaceFactoryBean.setClustered(boolean) flag set to false) so setting this flag to false (which means this container will operate when the space is in BACKUP mode as well) needs to be done with care.

This base class does not assume any specific listener programming model or listener invoker mechanism. It just provides the general runtime lifecycle management needed for any kind of Space event listening mechanism.

For a concrete listener programming model, check out the AbstractEventListenerContainer subclass. For a concrete listener invoker mechanism, check out the SimplePollingEventListenerContainer class.

Author:
kimchy

Field Summary
protected  String beanName
           
protected  Log logger
           
 
Constructor Summary
AbstractSpaceListeningContainer()
           
 
Method Summary
 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()
          Notify all invoker tasks.
protected  void doStop()
          Notify all invoker tasks to stop
protected  String getBeanName()
          Return the bean name that this listener container has been assigned in its containing bean factory, if any.
protected  GigaSpace getGigaSpace()
          Returns the GigaSpace instance to be used for Space operations.
protected  String getStatus()
           
 void initialize()
          Initialize this container.
 boolean isActive()
          Return whether this container is currently active, that is, whether it has been set up but not shut down yet.
 boolean isRunning()
          Return whether this container is currently running, that is, whether it has been started and not stopped yet.
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.
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 setAutoStart(boolean initOnStartup)
          Set whether this container will start once instantiated.
 void setBeanName(String beanName)
           
 void setGigaSpace(GigaSpace gigaSpace)
          Sets the GigaSpace instance to be used for space event listening operations.
 void setRegisterSpaceModeListener(boolean registerSpaceModeListener)
           
 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.
 
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

logger

protected final Log logger

beanName

protected String beanName
Constructor Detail

AbstractSpaceListeningContainer

public AbstractSpaceListeningContainer()
Method Detail

setGigaSpace

public void setGigaSpace(GigaSpace gigaSpace)
Sets the GigaSpace instance to be used for space event listening operations.


setAutoStart

public void setAutoStart(boolean initOnStartup)
Set whether this container will start once instantiated.

Default is true. Set to false in order for this container to be started using start().


getGigaSpace

protected final GigaSpace getGigaSpace()
Returns the GigaSpace instance to be used for Space operations.


setActiveWhenPrimary

public void setActiveWhenPrimary(boolean activeWhenPrimary)
Set whether this container will start only when it is primary (space mode).

Default is true. Set to false in order for this container to always start regardless of the space mode.


setBeanName

public void setBeanName(String beanName)
Specified by:
setBeanName in interface BeanNameAware

getBeanName

protected final String getBeanName()
Return the bean name that this listener container has been assigned in its containing bean factory, if any.


setRegisterSpaceModeListener

public void setRegisterSpaceModeListener(boolean registerSpaceModeListener)

afterPropertiesSet

public void afterPropertiesSet()
Delegates to validateConfiguration() and initialize().

Specified by:
afterPropertiesSet in interface InitializingBean

validateConfiguration

protected void validateConfiguration()
Validate the configuration of this container.


initialize

public void initialize()
                throws DataAccessException
Initialize this container. If this container is not configured with "activeWhenPrimary" flag set to 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.

Throws:
DataAccessException
See Also:
onApplicationEvent(org.springframework.context.ApplicationEvent)

destroy

public void destroy()
Calls shutdown() when the BeanFactory destroys the container instance.

Specified by:
destroy in interface DisposableBean
See Also:
shutdown()

shutdown

public void shutdown()
              throws DataAccessException
Stop container, call doShutdown(), and close this container.

Throws:
DataAccessException

isActive

public final boolean isActive()
Return whether this container is currently active, that is, whether it has been set up but not shut down yet.


onApplicationEvent

public void onApplicationEvent(ApplicationEvent applicationEvent)
If the 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.

Specified by:
onApplicationEvent in interface ApplicationListener<ApplicationEvent>

start

public void start()
           throws DataAccessException
Start this container.

Specified by:
start in interface Lifecycle
Throws:
DataAccessException
See Also:
doStart()

doStart

protected void doStart()
                throws DataAccessException
Notify all invoker tasks.

Throws:
DataAccessException

doAfterStart

protected void doAfterStart()
                     throws DataAccessException
Throws:
DataAccessException

stop

public void stop()
          throws DataAccessException
Stop this container.

Specified by:
stop in interface Lifecycle
Throws:
DataAccessException
See Also:
doStop()

doStop

protected void doStop()
               throws DataAccessException
Notify all invoker tasks to stop

Throws:
DataAccessException

doBeforeStop

protected void doBeforeStop()
                     throws DataAccessException
Throws:
DataAccessException

isRunning

public final boolean isRunning()
Return whether this container is currently running, that is, whether it has been started and not stopped yet.

Specified by:
isRunning in interface Lifecycle

getStatus

protected String getStatus()

waitWhileNotRunning

protected final void waitWhileNotRunning()
Wait while this container is not running.

To be called by asynchronous tasks that want to block while the container is in stopped state.


rescheduleTaskIfNecessary

protected final 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.

If this container has already been shut down, the task will not get rescheduled at all.

Parameters:
task - the task object to reschedule
Returns:
whether the task has been rescheduled (either immediately or for a restart of this container)
See Also:
doRescheduleTask(java.lang.Object)

doRescheduleTask

protected void doRescheduleTask(Object task)
Reschedule the given task object immediately.

To be implemented by subclasses if they ever call rescheduleTaskIfNecessary. This implementation throws an UnsupportedOperationException.

Parameters:
task - the task object to reschedule
See Also:
rescheduleTaskIfNecessary(java.lang.Object)

message

protected String message(String message)

doInitialize

protected abstract void doInitialize()
                              throws DataAccessException
A callback to perform custom initialization steps.

Throws:
DataAccessException

doShutdown

protected abstract void doShutdown()
                            throws DataAccessException
Perform any custom shutdown operations.

Throws:
DataAccessException
See Also:
shutdown()

GigaSpaces XAP 9.7.2 API

Copyright © GigaSpaces.