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
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.
Modifier and Type | Field and Description |
---|---|
protected ResourceApplicationContext |
applicationContext |
protected String |
beanName |
protected org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
SpaceModeContextLoader() |
Modifier and Type | Method and Description |
---|---|
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(org.springframework.context.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(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 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(org.springframework.context.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 |
setBeanName(String name) |
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(org.springframework.core.io.Resource location)
The location of the Spring xml context application to be loaded.
|
protected final org.apache.commons.logging.Log logger
protected String beanName
protected volatile ResourceApplicationContext applicationContext
public void setLocation(org.springframework.core.io.Resource location)
public void setGigaSpace(GigaSpace gigaSpace)
public void setActiveWhenPrimary(boolean activeWhenPrimary)
PRIMARY
mode. Defaults to true
.public void setBeanLevelProperties(BeanLevelProperties beanLevelProperties)
BeanLevelProperties
to the newly created application context.setBeanLevelProperties
in interface BeanLevelPropertiesAware
public void setClusterInfo(ClusterInfo clusterInfo)
ClusterInfo
to the newly created application context.setClusterInfo
in interface ClusterInfoAware
clusterInfo
- The cluster information to be injectedpublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public void setBeanName(String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public void destroy() throws Exception
destroy
in interface org.springframework.beans.factory.DisposableBean
Exception
public void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)
setActiveWhenPrimary(boolean)
is set to true
(the default) will
listens for AfterSpaceModeChangeEvent
and load an application context if received.onApplicationEvent
in interface org.springframework.context.ApplicationListener
protected void loadApplicationContext() throws Exception
Exception
protected void closeApplicationContext()
protected void publishEvent(org.springframework.context.ApplicationEvent applicationEvent)
ApplicationEventPublisher.publishEvent(org.springframework.context.ApplicationEvent)
which will
create a recursive event calling.Copyright © GigaSpaces.