Package org.openspaces.core.space.mode
Class SpaceModeContextLoader
java.lang.Object
org.openspaces.core.space.mode.SpaceModeContextLoader
- All Implemented Interfaces:
EventListener,ClusterInfoAware,BeanLevelPropertiesAware,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener
- Direct Known Subclasses:
RefreshSpaceModeContextLoader
public class SpaceModeContextLoader
extends Object
implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationListener, BeanLevelPropertiesAware, ClusterInfoAware, org.springframework.beans.factory.BeanNameAware
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
FieldsModifier and TypeFieldDescriptionprotected ResourceApplicationContextprotected Stringprotected final org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidCloses the application context.voiddestroy()protected voidLoads the application context and adding specific bean factory and bean post processors.voidonApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent) IfsetActiveWhenPrimary(boolean)is set totrue(the default) will listens forAfterSpaceModeChangeEventand load an application context if received.protected voidpublishEvent(org.springframework.context.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 usingApplicationEventPublisher.publishEvent(org.springframework.context.ApplicationEvent)which will create a recursive event calling.voidsetActiveWhenPrimary(boolean activeWhenPrimary) Controls if the Spring context will be loaded when the space cluster member moves toPRIMARYmode.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) Injected by Spring and used as the parent application context for the newly created application context.voidsetBeanLevelProperties(BeanLevelProperties beanLevelProperties) Used to pass theBeanLevelPropertiesto the newly created application context.voidsetBeanName(String name) voidsetClusterInfo(ClusterInfo clusterInfo) Used to passClusterInfoto the newly created application context.voidsetGigaSpace(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.voidsetLocation(org.springframework.core.io.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, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger -
beanName
-
applicationContext
-
-
Constructor Details
-
SpaceModeContextLoader
public SpaceModeContextLoader()
-
-
Method Details
-
setLocation
public void setLocation(org.springframework.core.io.Resource location) The location of the Spring xml context application to be loaded. -
setGigaSpace
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 toPRIMARYmode. Defaults totrue. -
setBeanLevelProperties
Used to pass theBeanLevelPropertiesto the newly created application context.- Specified by:
setBeanLevelPropertiesin interfaceBeanLevelPropertiesAware
-
setClusterInfo
Used to passClusterInfoto the newly created application context.- Specified by:
setClusterInfoin interfaceClusterInfoAware- Parameters:
clusterInfo- The cluster information to be injected
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException Injected by Spring and used as the parent application context for the newly created application context.- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent) IfsetActiveWhenPrimary(boolean)is set totrue(the default) will listens forAfterSpaceModeChangeEventand load an application context if received.- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener
-
loadApplicationContext
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(org.springframework.context.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 usingApplicationEventPublisher.publishEvent(org.springframework.context.ApplicationEvent)which will create a recursive event calling.
-