GigaSpaces XAP 7.0 API

org.openspaces.core.space.mode.registry
Class ModeAnnotationRegistry

java.lang.Object
  extended by org.openspaces.core.space.mode.registry.ModeAnnotationRegistry
All Implemented Interfaces:
SpaceAfterBackupListener, SpaceAfterPrimaryListener, SpaceBeforeBackupListener, SpaceBeforePrimaryListener

public class ModeAnnotationRegistry
extends Object
implements SpaceBeforePrimaryListener, SpaceAfterPrimaryListener, SpaceBeforeBackupListener, SpaceAfterBackupListener

Receives space mode change events and routs them to beans that use annotations to register as listeners on those events. When the application starts beans that has one or more of the annotation PreBackup, PostBackup, PrePrimary, PostPrimary are registered in this bean, and when events arrive they are routed to the registered beans' methods.

Author:
shaiw

Field Summary
protected  Hashtable<Class<?>,HashSet<org.openspaces.core.space.mode.registry.ModeAnnotationRegistry.RegistryEntry>> registry
          Maps the annotation to the list of beans' methods to invoke.
 
Constructor Summary
ModeAnnotationRegistry()
           
 
Method Summary
protected  void fireEvent(HashSet<org.openspaces.core.space.mode.registry.ModeAnnotationRegistry.RegistryEntry> entries, Object event)
          Invokes the registered beans' methods passing them the space mode change event.
 void onAfterBackup(AfterSpaceModeChangeEvent event)
          Invoked after a space changes its mode to SpaceMode.BACKUP.
 void onAfterPrimary(AfterSpaceModeChangeEvent event)
          Invoked after a space changes its mode to SpaceMode.PRIMARY.
 void onBeforeBackup(BeforeSpaceModeChangeEvent event)
          Invoked before a space changes its mode to SpaceMode.BACKUP.
 void onBeforePrimary(BeforeSpaceModeChangeEvent event)
          Invoked before a space changes its mode to SpaceMode.PRIMARY.
 void registerAnnotation(Class<?> annotation, Object object, Method method)
          Registers the bean as a listener for a space mode event specified by the annotation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registry

protected Hashtable<Class<?>,HashSet<org.openspaces.core.space.mode.registry.ModeAnnotationRegistry.RegistryEntry>> registry
Maps the annotation to the list of beans' methods to invoke.

Constructor Detail

ModeAnnotationRegistry

public ModeAnnotationRegistry()
Method Detail

registerAnnotation

public void registerAnnotation(Class<?> annotation,
                               Object object,
                               Method method)
                        throws IllegalArgumentException
Registers the bean as a listener for a space mode event specified by the annotation. When an event fires the specified bean method will be invoked. If the annotation is PreBackup or PrePrimary the target invocation method may have no parameters or a single parameter of type BeforeSpaceModeChangeEvent. If the annotation is PostBackup or PostPrimary the target invocation method may have no parameters or a single parameter of type AfterSpaceModeChangeEvent.

Parameters:
annotation - The space mode annotation that specifies the event the bean is registered to.
object - The bean instance.
method - The bean's method to invoke when the event fires.
Throws:
IllegalArgumentException - When the specified method has more than one parameter, or when the method's parameter is not of the types BeforeSpaceModeChangeEvent or AfterSpaceModeChangeEvent, or when the specified bean is not the one declaring the specified method.

onBeforePrimary

public void onBeforePrimary(BeforeSpaceModeChangeEvent event)
Invoked before a space changes its mode to SpaceMode.PRIMARY.

Specified by:
onBeforePrimary in interface SpaceBeforePrimaryListener

onAfterPrimary

public void onAfterPrimary(AfterSpaceModeChangeEvent event)
Invoked after a space changes its mode to SpaceMode.PRIMARY.

Specified by:
onAfterPrimary in interface SpaceAfterPrimaryListener

onBeforeBackup

public void onBeforeBackup(BeforeSpaceModeChangeEvent event)
Invoked before a space changes its mode to SpaceMode.BACKUP.

Specified by:
onBeforeBackup in interface SpaceBeforeBackupListener

onAfterBackup

public void onAfterBackup(AfterSpaceModeChangeEvent event)
Invoked after a space changes its mode to SpaceMode.BACKUP.

Specified by:
onAfterBackup in interface SpaceAfterBackupListener

fireEvent

protected void fireEvent(HashSet<org.openspaces.core.space.mode.registry.ModeAnnotationRegistry.RegistryEntry> entries,
                         Object event)
Invokes the registered beans' methods passing them the space mode change event.

Parameters:
entries - A list of beans and methods to invoke.
event - The event to pass to the methods in case they expect a parameter.

GigaSpaces XAP 7.0 API

Copyright © GigaSpaces.