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 Details

    • logger

      protected final org.apache.commons.logging.Log logger
    • beanName

      protected String beanName
    • applicationContext

      protected volatile ResourceApplicationContext 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

      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(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:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception
    • onApplicationEvent

      public 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.
      Specified by:
      onApplicationEvent in interface org.springframework.context.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(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.