Class GigaSpaceFactoryBean

java.lang.Object
org.openspaces.core.GigaSpaceFactoryBean
All Implemented Interfaces:
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

public class GigaSpaceFactoryBean extends Object implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.BeanNameAware

A factory bean creating GigaSpace implementation. The implementation created is DefaultGigaSpace which allows for pluggable IJSpace, TransactionProvider, and ExceptionTranslator.

The factory requires an IJSpace which can be either directly acquired or build using one of the several space factory beans provided in org.openspaces.core.space.

The factory accepts an optional TransactionProvider which defaults to DefaultTransactionProvider. The transactional context used is based on setTransactionManager(org.springframework.transaction.PlatformTransactionManager) and if no transaction manager is provided, will use the space as the context.

When using org.openspaces.core.transaction.manager.LocalJiniTransactionManager there is no need to pass the transaction manager to this factory, since both by default will use the space as the transactional context. When working with LookupJiniTransactionManager (which probably means Mahalo and support for more than one space as transaction resources) the transaction manager should be provided to this class.

The factory accepts an optional ExceptionTranslator which defaults to DefaultExceptionTranslator.

A clustered flag allows to control if this GigaSpace instance will work against a clustered view of the space or directly against a clustered member. This flag has no affect when not working in a clustered mode (partitioned or primary/backup). By default if this flag is not set it will be set automatically by this factory. It will be set to true if the space is an embedded one AND the space is not a local cache proxy. It will be set to false otherwise (i.e. the space is not an embedded space OR the space is a local cache proxy). A local cache proxy is an IJSpace that is injected using setSpace(com.j_spaces.core.IJSpace) and was created using either LocalViewSpaceFactoryBean or LocalCacheSpaceFactoryBean.

The factory allows to set the default read/take timeout and write lease when using the same operations without the relevant parameters.

The factory also allows to set the default isolation level for read operations that will be performed by GigaSpace API. The isolation level can be set either using setDefaultIsolationLevel(int) or setDefaultIsolationLevelName(String). Note, this setting will apply when not working under Spring declarative transactions or when using Spring declarative transaction with the default isolation level (TransactionDefinition.ISOLATION_DEFAULT).

Author:
kimchy
See Also:
  • Field Details

    • PREFIX_ISOLATION

      public static final String PREFIX_ISOLATION
      Prefix for the isolation constants defined in TransactionDefinition
      See Also:
  • Constructor Details

    • GigaSpaceFactoryBean

      public GigaSpaceFactoryBean()
  • Method Details

    • setSpace

      public void setSpace(IJSpace space)

      Sets the space that will be used by the created GigaSpace. This is a required parameter to the factory.

      Parameters:
      space - The space used
    • setTxProvider

      public void setTxProvider(TransactionProvider txProvider)

      Sets the transaction provider that will be used by the created GigaSpace. This is an optional parameter and defaults to DefaultTransactionProvider.

      Parameters:
      txProvider - The transaction provider to use
    • setExTranslator

      public void setExTranslator(ExceptionTranslator exTranslator)

      Sets the exception translator that will be used by the created GigaSpace. This is an optional parameter and defaults to DefaultExceptionTranslator.

      Parameters:
      exTranslator - The exception translator to use
    • setClustered

      public void setClustered(boolean clustered)

      Sets the cluster flag controlling if this GigaSpace will work with a clustered view of the space or directly with a cluster member. By default if this flag is not set it will be set automatically by this factory. It will be set to false if the space is an embedded one AND the space is not a local cache proxy. It will be set to true otherwise (i.e. the space is not an embedded space OR the space is a local cache proxy).

      Parameters:
      clustered - If the GigaSpace is going to work with a clustered view of the space or directly with a cluster member
    • setDefaultReadTimeout

      public void setDefaultReadTimeout(long defaultReadTimeout)

      Sets the default read timeout for GigaSpace.read(Object) and GigaSpace.readIfExists(Object) operations. Default to 0.

    • setDefaultTakeTimeout

      public void setDefaultTakeTimeout(long defaultTakeTimeout)

      Sets the default take timeout for GigaSpace.take(Object) and GigaSpace.takeIfExists(Object) operations. Default to 0.

    • setDefaultWriteLease

      public void setDefaultWriteLease(long defaultWriteLease)

      Sets the default write lease for GigaSpace.write(Object) operation. Default to Lease.FOREVER.

    • setDefaultIsolationLevelName

      public final void setDefaultIsolationLevelName(String constantName) throws IllegalArgumentException
      Set the default isolation level by the name of the corresponding constant in TransactionDefinition, e.g. "ISOLATION_DEFAULT".
      Parameters:
      constantName - name of the constant
      Throws:
      IllegalArgumentException - if the supplied value is not resolvable to one of the ISOLATION_ constants or is null
      See Also:
    • setDefaultIsolationLevel

      public void setDefaultIsolationLevel(int defaultIsolationLevel)
      Set the default isolation level. Must be one of the isolation constants in the TransactionDefinition interface. Default is ISOLATION_DEFAULT.
      Throws:
      IllegalArgumentException - if the supplied value is not one of the ISOLATION_ constants
      See Also:
      • TransactionDefinition.ISOLATION_DEFAULT
    • setDefaultWriteModifiers

      public void setDefaultWriteModifiers(WriteModifiers[] defaultWriteModifiers)
      Set the default WriteModifiers to be used for write operations on the GigaSpace instance. Defaults to WriteModifiers.UPDATE_OR_WRITE
      Parameters:
      defaultWriteModifiers - The default write modifiers.
      See Also:
    • setDefaultReadModifiers

      public void setDefaultReadModifiers(ReadModifiers[] defaultReadModifiers)
      Set the default ReadModifiers to be used for read operations on the GigaSpace instance. Defaults to ReadModifiers.READ_COMMITTED
      Parameters:
      defaultReadModifiers - The default read modifiers.
      See Also:
    • setDefaultTakeModifiers

      public void setDefaultTakeModifiers(TakeModifiers[] defaultTakeModifiers)
      Set the default TakeModifiers to be used for take operations on the GigaSpace instance. Defaults to TakeModifiers.NONE
      Parameters:
      defaultTakeModifiers - The default take modifiers.
      See Also:
    • setDefaultCountModifiers

      public void setDefaultCountModifiers(CountModifiers[] defaultCountModifiers)
      Set the default CountModifiers to be used for count operations on the GigaSpace instance. Defaults to CountModifiers.NONE
      Parameters:
      defaultCountModifiers - The default count modifiers.
      See Also:
    • setDefaultClearModifiers

      public void setDefaultClearModifiers(ClearModifiers[] defaultClearModifiers)
      Set the default ClearModifiers to be used for clear operations on the GigaSpace instance. Defaults to ClearModifiers.NONE
      Parameters:
      defaultClearModifiers - The default clear modifiers.
      See Also:
    • setDefaultChangeModifiers

      public void setDefaultChangeModifiers(ChangeModifiers[] defaultChangeModifiers)
      Set the default ChangeModifiers to be used for change operations on the GigaSpace instance. Defaults to ChangeModifiers.NONE
      Parameters:
      defaultChangeModifiers - The default change modifiers.
      See Also:
    • setTransactionManager

      public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)

      Set the transaction manager to enable transactional operations. Can be null if transactional support is not required or the default space is used as a transactional context.

    • setBeanName

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

      public void afterPropertiesSet()
      Constructs the GigaSpace instance using the DefaultGigaSpace implementation. Uses the clustered flag to get a cluster member directly (if set to false) and applies the different defaults).
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • getObject

      public Object getObject()
      Return GigaSpace implementation constructed in the afterPropertiesSet() phase.
      Specified by:
      getObject in interface org.springframework.beans.factory.FactoryBean
    • getObjectType

      public Class<? extends GigaSpace> getObjectType()
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean
    • isSingleton

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

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