Class AbstractSpaceFactoryBean

java.lang.Object
org.openspaces.core.space.AbstractSpaceFactoryBean
All Implemented Interfaces:
InternalDumpProcessor, EventListener, MemberAliveIndicator, ServiceDetailsProvider, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener
Direct Known Subclasses:
DirectSpaceFactoryBean, EmbeddedSpaceFactoryBean, SpaceProxyFactoryBean, UrlSpaceFactoryBean

public abstract class AbstractSpaceFactoryBean extends Object implements org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener, MemberAliveIndicator, ServiceDetailsProvider, InternalDumpProcessor
Base class for most space factory beans responsible for creating/finding IJSpace implementation.

Provides support for raising Spring application events: BeforeSpaceModeChangeEvent and AfterSpaceModeChangeEvent alerting other beans of the current space mode (primary/backup). Beans that wish to be notified of it should implement Spring ApplicationListener. Note that this space mode events might be raised more than once for the same space mode, and beans that listen to it should take it into account.

The space mode event will be raised regardless of the space "type" that is used. For embedded spaces, an actual space mode event listener will be registered with the actual cluster member (if not in cluster mode, the actual space). For remote space lookups (jini/rmi), no listener will be registered and Space mode events will still be raised during context refresh with a PRIMARY mode in order to allow beans to be written regardless of how the space is looked up.

Derived classes should implement the doCreateSpace() to obtain the IJSpace.

Author:
kimchy
  • Field Details

    • logger

      protected org.apache.commons.logging.Log logger
  • Constructor Details

    • AbstractSpaceFactoryBean

      public AbstractSpaceFactoryBean()
  • Method Details

    • setRegisterForSpaceModeNotifications

      public void setRegisterForSpaceModeNotifications(boolean registerForSpaceMode)
      Sets if the space should register for primary backup (mode) notifications. Default behavior (if the flag was not set) will register to primary backup notification if the space was found using an embedded protocol, and will not register for notification if the space was found using rmi or jini protocols.
    • setUserDetails

      public void setUserDetails(UserDetails userDetails)
      Sets the security configuration with the provided custom user details.
      Parameters:
      userDetails - a custom user details.
    • setCredentialsProvider

      public void setCredentialsProvider(CredentialsProvider credentialsProvider)
      Sets the security configuration with the provided custom credentials provider.
      Parameters:
      credentialsProvider - a custom credentials provider.
    • setSecurityConfig

      public void setSecurityConfig(SecurityConfig securityConfig)
      Sets security configuration for the Space. If not set, no security will be used.
    • getSecurityConfig

      protected SecurityConfig getSecurityConfig()
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Injected by Spring thanks to ApplicationContextAware.
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • getApplicationContext

      protected org.springframework.context.ApplicationContext getApplicationContext()
    • setBeanName

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

      public void setPrimaryBackupListener(ISpaceModeListener primaryBackupListener)
      Sets a custom primary backup listener
    • setEnableMemberAliveIndicator

      public void setEnableMemberAliveIndicator(Boolean enableMemberAliveIndicator)
      Should this Space bean control if the cluster member is alive or not. Defaults to true if the Space started is an embedded Space, and false if the it is connected to a remote Space.
    • afterPropertiesSet

      public void afterPropertiesSet() throws org.springframework.dao.DataAccessException
      Initializes the space by calling the doCreateSpace().

      Registers with the Space an internal space mode listener in order to be able to send Spring level BeforeSpaceModeChangeEvent and AfterSpaceModeChangeEvent for primary and backup handling of different beans within the context. The registration is based on isRegisterForSpaceModeNotifications().

      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      org.springframework.dao.DataAccessException
    • destroy

      public void destroy() throws Exception
      Destroys the space and unregisters the internal space mode listener (if registered).
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception
    • close

      public void close()
      Destroys the space and unregisters the internal space mode listener (if registered).
    • onApplicationEvent

      public void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)
      If ContextRefreshedEvent is raised will send two extra events: BeforeSpaceModeChangeEvent and AfterSpaceModeChangeEvent with the current space mode. This is done since other beans that use this events might not catch them while the context is constructed.

      Note, this will mean that events with the same Space mode might be raised, one after the other, and Spring beans that listens for them should take it into account.

      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener
    • getObject

      public Object getObject()
      Spring factory bean returning the IJSpace created during the bean initialization (afterPropertiesSet()).
      Specified by:
      getObject in interface org.springframework.beans.factory.FactoryBean
      Returns:
      The IJSpace implementation
    • getObjectType

      public Class<? extends IJSpace> getObjectType()
      Returns the object type of the factory bean. Defaults to IJSpace class or the actual IJSpace implementation class.
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean
    • isSingleton

      public boolean isSingleton()
      Returns true since this factory is a singleton.
      Specified by:
      isSingleton in interface org.springframework.beans.factory.FactoryBean
    • isMemberAliveEnabled

      public boolean isMemberAliveEnabled()
      Should this space be checked to see if it is alive or not.
      Specified by:
      isMemberAliveEnabled in interface MemberAliveIndicator
    • isAlive

      public boolean isAlive() throws Exception
      Returns if this space is alive or not by pinging the Space and if it is considered healthy.
      Specified by:
      isAlive in interface MemberAliveIndicator
      Throws:
      Exception
    • doCreateSpace

      protected abstract IJSpace doCreateSpace() throws org.springframework.dao.DataAccessException
      Responsible for creating/finding the actual IJSpace implementation.
      Returns:
      The IJSpace implementation used for the factory bean
      Throws:
      org.springframework.dao.DataAccessException
    • isRegisterForSpaceModeNotifications

      protected boolean isRegisterForSpaceModeNotifications()
      Returns if the space should register for primary backup notifications. If setRegisterForSpaceModeNotifications(boolean) was set, will return this flag. If not, will register to primary backup notification if the space was found using an embedded protocol, and will not register for notification if the space was found using rmi or jini protocols.
    • fireSpaceBeforeBackupEvent

      protected void fireSpaceBeforeBackupEvent()
      Sends BeforeSpaceModeChangeEvent events with space mode SpaceMode.BACKUP to all beans in the application context that implement the SpaceBeforeBackupListener interface.
    • fireSpaceAfterBackupEvent

      protected void fireSpaceAfterBackupEvent()
      Sends AfterSpaceModeChangeEvent events with space mode SpaceMode.BACKUP to all beans in the application context that implement the SpaceAfterBackupListener interface.
    • fireSpaceBeforePrimaryEvent

      protected void fireSpaceBeforePrimaryEvent()
      Sends BeforeSpaceModeChangeEvent events with space mode SpaceMode.PRIMARY to all beans in the application context that implement the SpaceBeforePrimaryListener interface.
    • fireSpaceAfterPrimaryEvent

      protected void fireSpaceAfterPrimaryEvent()
      Sends AfterSpaceModeChangeEvent events with space mode SpaceMode.PRIMARY to all beans in the application context that implement the SpaceAfterPrimaryListener interface
    • getServicesDetails

      public ServiceDetails[] getServicesDetails()
      Description copied from interface: ServiceDetailsProvider
      Retruns one or more service details that the service exposes.
      Specified by:
      getServicesDetails in interface ServiceDetailsProvider
    • addServiceDetails

      public void addServiceDetails(ServiceDetailsProvider serviceDetailsProvider)
    • getName

      public String getName()
      Specified by:
      getName in interface InternalDumpProcessor
    • process

      public void process(InternalDump dump) throws InternalDumpProcessorFailedException
      Specified by:
      process in interface InternalDumpProcessor
      Throws:
      InternalDumpProcessorFailedException
    • toString

      public String toString()
      Overrides:
      toString in class Object