GigaSpaces XAP 7.0 API

org.openspaces.core.space.mode
Class SpaceModeContextLoader

java.lang.Object
  extended by org.openspaces.core.space.mode.SpaceModeContextLoader
All Implemented Interfaces:
EventListener, ClusterInfoAware, BeanLevelPropertiesAware, DisposableBean, InitializingBean, ApplicationContextAware, ApplicationListener
Direct Known Subclasses:
RefreshSpaceModeContextLoader

public class SpaceModeContextLoader
extends Object
implements ApplicationContextAware, InitializingBean, DisposableBean, ApplicationListener, BeanLevelPropertiesAware, ClusterInfoAware

A Space mode based Spring context loader allows to load Spring application context if the Space is in PRIMARY mode.

The space mode context loader allows to assemble beans that only operate when a space is in a PRIMARY mode which basically applies when directly working with cluster members and not a clustered space proxy (since in such cases it will always be PRIMARY).

The new Spring application context created will have the current context as its parent, allowing to use any beans defined within the current context within the loaded context.

The context loader accepts a Spring Resource as the location. A flag called setActiveWhenPrimary(boolean) which defaults to true allows to control if the context will be loaded only when the cluster member moves to PRIMARY mode.

Author:
kimchy

Field Summary
protected  Log logger
           
 
Constructor Summary
SpaceModeContextLoader()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void closeApplicationContext()
          Closes the application context.
 void destroy()
           
protected  void loadApplicationContext()
          Loads the application context and adding specific bean factory and bean post processors.
 void onApplicationEvent(ApplicationEvent applicationEvent)
          If setActiveWhenPrimary(boolean) is set to true (the default) will listens for AfterSpaceModeChangeEvent and load an application context if received.
protected  void publishEvent(ApplicationEvent applicationEvent)
          A hack to only send the application event on the child application context we are loading, without propogating it to the parent application context (when using ApplicationEventPublisher.publishEvent(org.springframework.context.ApplicationEvent) which will create a recursive event calling.
 void setActiveWhenPrimary(boolean activeWhenPrimary)
          Controls if the Spring context will be loaded when the space cluster member moves to PRIMARY mode.
 void setApplicationContext(ApplicationContext applicationContext)
          Injected by Spring and used as the parent application context for the newly created application context.
 void setBeanLevelProperties(BeanLevelProperties beanLevelProperties)
          Used to pass the BeanLevelProperties to the newly created application context.
 void setClusterInfo(ClusterInfo clusterInfo)
          Used to pass ClusterInfo to the newly created application context.
 void setGigaSpace(GigaSpace gigaSpace)
          Allows to set the GigaSpace instance that will control (based on its Space mode - PRIMARY or BACKUP) if the context will be loaded or not.
 void setLocation(Resource location)
          The location of the Spring xml context application to be loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Constructor Detail

SpaceModeContextLoader

public SpaceModeContextLoader()
Method Detail

setLocation

public void setLocation(Resource location)
The location of the Spring xml context application to be loaded.


setGigaSpace

public void setGigaSpace(GigaSpace gigaSpace)
Allows to set the GigaSpace instance that will control (based on its Space mode - PRIMARY or BACKUP) if the context will be loaded or not. Useful when more than one space is defined within a Spring context.


setActiveWhenPrimary

public void setActiveWhenPrimary(boolean activeWhenPrimary)
Controls if the Spring context will be loaded when the space cluster member moves to PRIMARY mode. Defaults to true.


setBeanLevelProperties

public void setBeanLevelProperties(BeanLevelProperties beanLevelProperties)
Used to pass the BeanLevelProperties to the newly created application context.

Specified by:
setBeanLevelProperties in interface BeanLevelPropertiesAware

setClusterInfo

public void setClusterInfo(ClusterInfo clusterInfo)
Used to pass ClusterInfo to the newly created application context.

Specified by:
setClusterInfo in interface ClusterInfoAware
Parameters:
clusterInfo - The cluster information to be injected

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Injected by Spring and used as the parent application context for the newly created application context.

Specified by:
setApplicationContext in interface ApplicationContextAware
Throws:
BeansException

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface DisposableBean
Throws:
Exception

onApplicationEvent

public void onApplicationEvent(ApplicationEvent applicationEvent)
If setActiveWhenPrimary(boolean) is set to true (the default) will listens for AfterSpaceModeChangeEvent and load an application context if received.

Specified by:
onApplicationEvent in interface ApplicationListener

loadApplicationContext

protected void loadApplicationContext()
                               throws Exception
Loads the application context and adding specific bean factory and bean post processors. Won't load an application context if one is already defined.

Throws:
Exception

closeApplicationContext

protected void closeApplicationContext()
Closes the application context. Won't close that application context if one is not defined.


publishEvent

protected void publishEvent(ApplicationEvent applicationEvent)
A hack to only send the application event on the child application context we are loading, without propogating it to the parent application context (when using ApplicationEventPublisher.publishEvent(org.springframework.context.ApplicationEvent) which will create a recursive event calling.


GigaSpaces XAP 7.0 API

Copyright © GigaSpaces.