org.springframework.data.gemfire
Class RegionFactoryBean<K,V>

java.lang.Object
  extended by org.springframework.data.gemfire.RegionLookupFactoryBean<K,V>
      extended by org.springframework.data.gemfire.RegionFactoryBean<K,V>
All Implemented Interfaces:
Aware, BeanNameAware, DisposableBean, FactoryBean<com.gemstone.gemfire.cache.Region<K,V>>, InitializingBean, Lifecycle, Phased, SmartLifecycle
Direct Known Subclasses:
LocalRegionFactoryBean, PartitionedRegionFactoryBean, ReplicatedRegionFactoryBean

public class RegionFactoryBean<K,V>
extends RegionLookupFactoryBean<K,V>
implements DisposableBean, SmartLifecycle

Base class for FactoryBeans used to create GemFire Regions. Will try to first locate the region (by name) and, in case none if found, proceed to creating one using the given settings. Note that this factory bean allows for very flexible creation of GemFire Region. For "client" regions however, see ClientRegionFactoryBean which offers easier configuration and defaults.


Field Summary
protected  org.apache.commons.logging.Log log
           
 
Constructor Summary
RegionFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void assertDataPolicyAndPersistentAttributesAreCompatible(com.gemstone.gemfire.cache.DataPolicy resolvedDataPolicy)
          Validates that the settings for Data Policy and the 'persistent' attribute in <gfe:*-region> elements are compatible.
protected  com.gemstone.gemfire.cache.RegionFactory<K,V> createRegionFactory(com.gemstone.gemfire.cache.Cache cache)
          Creates an instance of RegionFactory using the given Cache instance used to configure and construct the Region created by this FactoryBean.
 void destroy()
           
 com.gemstone.gemfire.cache.RegionAttributes getAttributes()
          Returns the attributes used to configure the Region created by this factory as set in the SDG XML namespace configuration meta-data, or as set with the setAttributes(:Attributes) method.
 com.gemstone.gemfire.cache.DataPolicy getDataPolicy()
          Gets the "resolved" Data Policy as determined by this RegionFactory when configuring the attributes of the Region to be created.
 int getPhase()
           
protected  com.gemstone.gemfire.cache.RegionShortcut getShortcut()
           
 boolean isAutoStartup()
           
protected  boolean isNotPersistent()
          Returns true when the user explicitly specified a value for the persistent attribute and it is false.
protected  boolean isPersistent()
          Returns true when the user explicitly specified a value for the persistent attribute and it is true.
protected  boolean isPersistentUnspecified()
          Determines whether the user explicitly set the 'persistent' attribute or not.
 boolean isRunning()
           
protected  com.gemstone.gemfire.cache.Region<K,V> lookupFallback(com.gemstone.gemfire.cache.GemFireCache gemfireCache, String regionName)
          Fall back method in case the named region does not exist.
protected
<K,V> void
mergePartitionAttributes(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory, com.gemstone.gemfire.cache.RegionAttributes<K,V> regionAttributes)
           
protected
<K,V> com.gemstone.gemfire.cache.RegionFactory<K,V>
mergeRegionAttributes(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory, com.gemstone.gemfire.cache.RegionAttributes<K,V> regionAttributes)
          Intelligently merges the given RegionAttributes with the configuration setting of the RegionFactory.
protected  void postProcess(com.gemstone.gemfire.cache.Region<K,V> region)
          Post-process the Region for this factory bean during the initialization process.
protected  void postProcess(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory)
          Post-process the RegionFactory used to create the GemFire Region for this factory bean during the initialization process.
protected  void resolveDataPolicy(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory, Boolean persistent, com.gemstone.gemfire.cache.DataPolicy dataPolicy)
          Validates and sets the Data Policy on the RegionFactory used to create and configure the Region from this FactoryBean.
protected  void resolveDataPolicy(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory, Boolean persistent, String dataPolicy)
          Validates the configured Data Policy and may override it, taking into account the 'persistent' attribute and constraints for the Region type.
 void setAsyncEventQueues(Object[] asyncEventQueues)
          The list of AsyncEventQueues to use with this Region.
 void setAttributes(com.gemstone.gemfire.cache.RegionAttributes<K,V> attributes)
          Sets the region attributes used for the region used by this factory.
 void setCacheListeners(com.gemstone.gemfire.cache.CacheListener<K,V>[] cacheListeners)
          Sets the cache listeners used for the region used by this factory.
 void setCacheLoader(com.gemstone.gemfire.cache.CacheLoader<K,V> cacheLoader)
          Sets the cache loader used for the region used by this factory.
 void setCacheWriter(com.gemstone.gemfire.cache.CacheWriter<K,V> cacheWriter)
          Sets the cache writer used for the region used by this factory.
 void setClose(boolean close)
          Indicates whether the region referred by this factory bean, will be closed on shutdown (default true).
 void setDataPolicy(com.gemstone.gemfire.cache.DataPolicy dataPolicy)
          Sets the DataPolicy of the Region.
 void setDataPolicy(String dataPolicyName)
          Deprecated. as of 1.4.0, use setDataPolicy(:DataPolicy) instead.
 void setDestroy(boolean destroy)
          Indicates whether the region referred by this factory bean, will be destroyed on shutdown (default false).
 void setDiskStoreName(String diskStoreName)
          Sets the name of Disk Store used for either overflow or persistence, or both.
 void setEnableGateway(boolean enableGateway)
           
 void setGatewaySenders(Object[] gatewaySenders)
           
 void setHubId(String hubId)
           
 void setPersistent(Boolean persistent)
           
 void setScope(com.gemstone.gemfire.cache.Scope scope)
          Sets the region scope.
 void setShortcut(com.gemstone.gemfire.cache.RegionShortcut shortcut)
          Configures the Region with a RegionShortcut.
 void setSnapshot(Resource snapshot)
          Sets the snapshots used for loading a newly created region.
 void start()
           
 void stop()
           
 void stop(Runnable callback)
           
 
Methods inherited from class org.springframework.data.gemfire.RegionLookupFactoryBean
getLookupEnabled, getObject, getObjectType, getParent, getRegion, isSingleton, setBeanName, setCache, setLookupEnabled, setName, setParent, setRegionName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
Constructor Detail

RegionFactoryBean

public RegionFactoryBean()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class RegionLookupFactoryBean<K,V>
Throws:
Exception

lookupFallback

protected com.gemstone.gemfire.cache.Region<K,V> lookupFallback(com.gemstone.gemfire.cache.GemFireCache gemfireCache,
                                                                String regionName)
                                                         throws Exception
Description copied from class: RegionLookupFactoryBean
Fall back method in case the named region does not exist. By default, this implementation throws an exception.

Overrides:
lookupFallback in class RegionLookupFactoryBean<K,V>
Parameters:
gemfireCache - GemFire cache
regionName - region name
Throws:
Exception

assertDataPolicyAndPersistentAttributesAreCompatible

protected void assertDataPolicyAndPersistentAttributesAreCompatible(com.gemstone.gemfire.cache.DataPolicy resolvedDataPolicy)
Validates that the settings for Data Policy and the 'persistent' attribute in <gfe:*-region> elements are compatible.

Parameters:
resolvedDataPolicy - the GemFire Data Policy resolved form the Spring GemFire XML namespace configuration meta-data.
See Also:
isPersistent(), isNotPersistent(), DataPolicy

isPersistentUnspecified

protected boolean isPersistentUnspecified()
Determines whether the user explicitly set the 'persistent' attribute or not.

Returns:
a boolean value indicating whether the user explicitly set the 'persistent' attribute to true or false.
See Also:
isPersistent(), isNotPersistent()

isPersistent

protected boolean isPersistent()
Returns true when the user explicitly specified a value for the persistent attribute and it is true. If the persistent attribute was not explicitly specified, then the persistence setting is implicitly undefined and will be determined by the Data Policy.

Returns:
true when the user specified an explicit value for the persistent attribute and it is true; false otherwise.
See Also:
isNotPersistent(), isPersistentUnspecified()

isNotPersistent

protected boolean isNotPersistent()
Returns true when the user explicitly specified a value for the persistent attribute and it is false. If the persistent attribute was not explicitly specified, then the persistence setting is implicitly undefined and will be determined by the Data Policy.

Returns:
true when the user specified an explicit value for the persistent attribute and it is false; false otherwise.
See Also:
isPersistent(), isPersistentUnspecified()

createRegionFactory

protected com.gemstone.gemfire.cache.RegionFactory<K,V> createRegionFactory(com.gemstone.gemfire.cache.Cache cache)
Creates an instance of RegionFactory using the given Cache instance used to configure and construct the Region created by this FactoryBean.

Parameters:
cache - the GemFire Cache instance.
Returns:
a RegionFactory used to configure and construct the Region created by this FactoryBean.
See Also:
Cache.createRegionFactory(), Cache.createRegionFactory(com.gemstone.gemfire.cache.RegionAttributes), Cache.createRegionFactory(com.gemstone.gemfire.cache.RegionShortcut), RegionFactory

mergeRegionAttributes

protected <K,V> com.gemstone.gemfire.cache.RegionFactory<K,V> mergeRegionAttributes(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory,
                                                                                    com.gemstone.gemfire.cache.RegionAttributes<K,V> regionAttributes)
Intelligently merges the given RegionAttributes with the configuration setting of the RegionFactory. This method is used to merge the RegionAttributes and PartitionAttributes with the RegionFactory that is created when the user specified a RegionShortcut. This method gets called by the createRegionFactory method depending upon the value passed to the Cache.createRegionFactory() method (i.e. whether there was a RegionShortcut specified or not).

Type Parameters:
K - the Class type fo the Region key.
V - the Class type of the Region value.
Parameters:
regionFactory - the GemFire RegionFactory used to configure and create the Region that is the product of this RegionFactoryBean.
regionAttributes - the RegionAttributes containing the Region configuration settings to merge to the RegionFactory.
Returns:
the RegionFactory with the configuration settings of the RegionAttributes merged.
See Also:
hasUserSpecifiedEvictionAttributes(com.gemstone.gemfire.cache.RegionAttributes), validateRegionAttributes(com.gemstone.gemfire.cache.RegionAttributes), RegionAttributes, RegionFactory

mergePartitionAttributes

protected <K,V> void mergePartitionAttributes(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory,
                                              com.gemstone.gemfire.cache.RegionAttributes<K,V> regionAttributes)

postProcess

protected void postProcess(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory)
Post-process the RegionFactory used to create the GemFire Region for this factory bean during the initialization process. The RegionFactory is already configured and initialized by the factory bean before this method is invoked.

Parameters:
regionFactory - the GemFire RegionFactory used to create the Region for post-processing.
See Also:
RegionFactory

postProcess

protected void postProcess(com.gemstone.gemfire.cache.Region<K,V> region)
Post-process the Region for this factory bean during the initialization process. The Region is already configured and initialized by the factory bean before this method is invoked.

Parameters:
region - the GemFire Region to post-process.
See Also:
Region

resolveDataPolicy

protected void resolveDataPolicy(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory,
                                 Boolean persistent,
                                 com.gemstone.gemfire.cache.DataPolicy dataPolicy)
Validates and sets the Data Policy on the RegionFactory used to create and configure the Region from this FactoryBean.

Parameters:
regionFactory - the RegionFactory used by this FactoryBean to create and configure the Region.
persistent - a boolean value indicating whether the Region should be persistent and persist it's data to disk.
dataPolicy - the configured Data Policy for the Region.
See Also:
resolveDataPolicy(com.gemstone.gemfire.cache.RegionFactory, Boolean, String), DataPolicy, RegionFactory

resolveDataPolicy

protected void resolveDataPolicy(com.gemstone.gemfire.cache.RegionFactory<K,V> regionFactory,
                                 Boolean persistent,
                                 String dataPolicy)
Validates the configured Data Policy and may override it, taking into account the 'persistent' attribute and constraints for the Region type.

Parameters:
regionFactory - the GemFire RegionFactory used to create the desired Region.
persistent - a boolean value indicating whether the Region should persist it's data to disk.
dataPolicy - requested Data Policy as set by the user in the Spring GemFire configuration meta-data.
See Also:
DataPolicy, RegionFactory

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface DisposableBean
Throws:
Exception

setAsyncEventQueues

public void setAsyncEventQueues(Object[] asyncEventQueues)
The list of AsyncEventQueues to use with this Region.

Parameters:
asyncEventQueues - defined as Object for backwards compatibility with Gemfire 6.

setAttributes

public void setAttributes(com.gemstone.gemfire.cache.RegionAttributes<K,V> attributes)
Sets the region attributes used for the region used by this factory. Allows maximum control in specifying the region settings. Used only when a new region is created.

Parameters:
attributes - the attributes to set on a newly created region

getAttributes

public com.gemstone.gemfire.cache.RegionAttributes getAttributes()
Returns the attributes used to configure the Region created by this factory as set in the SDG XML namespace configuration meta-data, or as set with the setAttributes(:Attributes) method.

Returns:
the RegionAttributes used to configure the Region created by this factory.
See Also:
RegionAttributes

setCacheListeners

public void setCacheListeners(com.gemstone.gemfire.cache.CacheListener<K,V>[] cacheListeners)
Sets the cache listeners used for the region used by this factory. Used only when a new region is created.Overrides the settings specified through setAttributes(RegionAttributes).

Parameters:
cacheListeners - the cacheListeners to set on a newly created region

setCacheLoader

public void setCacheLoader(com.gemstone.gemfire.cache.CacheLoader<K,V> cacheLoader)
Sets the cache loader used for the region used by this factory. Used only when a new region is created.Overrides the settings specified through setAttributes(RegionAttributes).

Parameters:
cacheLoader - the cacheLoader to set on a newly created region

setCacheWriter

public void setCacheWriter(com.gemstone.gemfire.cache.CacheWriter<K,V> cacheWriter)
Sets the cache writer used for the region used by this factory. Used only when a new region is created. Overrides the settings specified through setAttributes(RegionAttributes).

Parameters:
cacheWriter - the cacheWriter to set on a newly created region

setClose

public void setClose(boolean close)
Indicates whether the region referred by this factory bean, will be closed on shutdown (default true).


setDestroy

public void setDestroy(boolean destroy)
Indicates whether the region referred by this factory bean, will be destroyed on shutdown (default false).


setDataPolicy

public void setDataPolicy(com.gemstone.gemfire.cache.DataPolicy dataPolicy)
Sets the DataPolicy of the Region.

Parameters:
dataPolicy - the GemFire DataPolicy to use when configuring the Region.
Since:
1.4.0

setDataPolicy

public void setDataPolicy(String dataPolicyName)
Deprecated. as of 1.4.0, use setDataPolicy(:DataPolicy) instead.

Sets the DataPolicy of the Region as a String.

Parameters:
dataPolicyName - the name of the DataPolicy (e.g. REPLICATE, PARTITION)
See Also:
setDataPolicy(com.gemstone.gemfire.cache.DataPolicy)

getDataPolicy

public com.gemstone.gemfire.cache.DataPolicy getDataPolicy()
Gets the "resolved" Data Policy as determined by this RegionFactory when configuring the attributes of the Region to be created.

Returns:
the "resolved" Data Policy to be used to create the Region.
See Also:
DataPolicy

setDiskStoreName

public void setDiskStoreName(String diskStoreName)
Sets the name of Disk Store used for either overflow or persistence, or both.

Parameters:
diskStoreName - the name of the Disk Store bean in context used for overflow/persistence.

setEnableGateway

public void setEnableGateway(boolean enableGateway)

setGatewaySenders

public void setGatewaySenders(Object[] gatewaySenders)
Parameters:
gatewaySenders - defined as Object for backward compatibility with Gemfire 6

setHubId

public void setHubId(String hubId)

setPersistent

public void setPersistent(Boolean persistent)

setScope

public void setScope(com.gemstone.gemfire.cache.Scope scope)
Sets the region scope. Used only when a new region is created. Overrides the settings specified through setAttributes(RegionAttributes).

Parameters:
scope - the region scope
See Also:
Scope

getShortcut

protected final com.gemstone.gemfire.cache.RegionShortcut getShortcut()

setShortcut

public void setShortcut(com.gemstone.gemfire.cache.RegionShortcut shortcut)
Configures the Region with a RegionShortcut.

Parameters:
shortcut - the RegionShortcut used to configure pre-defined default for the Region created by this FactoryBean.
See Also:
RegionShortcut

setSnapshot

public void setSnapshot(Resource snapshot)
Sets the snapshots used for loading a newly created region. That is, the snapshot will be used only when a new region is created - if the region already exists, no loading will be performed.

Parameters:
snapshot - the snapshot to set
See Also:
RegionLookupFactoryBean.setName(String)

start

public void start()
Specified by:
start in interface Lifecycle

stop

public void stop()
Specified by:
stop in interface Lifecycle

isRunning

public boolean isRunning()
Specified by:
isRunning in interface Lifecycle

getPhase

public int getPhase()
Specified by:
getPhase in interface Phased

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface SmartLifecycle

stop

public void stop(Runnable callback)
Specified by:
stop in interface SmartLifecycle