|
GemFire 6.5 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.gemstone.gemfire.cache.CacheFactory
public class CacheFactory
Factory class used to create the singleton cache and connect to GemFire the singleton distributed system. If the application wants to connect to GemFire as a client it should use ClientCacheFactory instead.
Once the factory has been configured using its set(String, String) method you produce a Cache by calling the create() method.
To get the existing unclosed singleton cache instance call getAnyInstance().
If an instance of DistributedSystem already exists when this factory
creates a cache, that instance will be used if it is compatible with this factory.
The following examples illustrate bootstrapping the cache using region shortcuts:
Example 1: Create a cache and a replicate region named customers.
Cache c = new CacheFactory().create();
Region r = c.createRegionFactory(REPLICATE).create("customers");
Example 2: Create a cache and a partition region with redundancy
Cache c = new CacheFactory().create();
Region r = c.createRegionFactory(PARTITION_REDUNDANT).create("customers");
Example 3: Construct the cache region declaratively in cache.xml
<!DOCTYPE cache PUBLIC
"-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
"http://www.gemstone.com/dtd/cache6_5.dtd">
<cache>
<region name="myRegion" refid="REPLICATE"/>
<!-- you can override or add to the REPLICATE attributes by adding
a region-attributes sub element here -->
</cache>
Now, create the cache telling it to read your cache.xml file:
Cache c = new CacheFactory()
.set("cache-xml-file", "myCache.xml")
.create();
Region r = c.getRegion("myRegion");
For a complete list of all region shortcuts see RegionShortcut.
Applications that need to explicitly control the individual region attributes can do this declaratively in XML or using APIs.
| Constructor Summary | |
|---|---|
CacheFactory()
Creates a default cache factory. |
|
CacheFactory(Properties props)
Create a CacheFactory initialized with the given gemfire properties. |
|
| Method Summary | |
|---|---|
Cache |
create()
Creates a new cache that uses the configured distributed system. |
static Cache |
create(DistributedSystem system)
Deprecated. as of 6.5 use CacheFactory(Properties) instead. |
static Cache |
getAnyInstance()
Gets an arbitrary open instance of Cache produced by an
earlier call to create(). |
static Cache |
getInstance(DistributedSystem system)
Gets the instance of Cache produced by an
earlier call to create(). |
static Cache |
getInstanceCloseOk(DistributedSystem system)
Gets the instance of Cache produced by an
earlier call to create() even if it has been closed. |
static String |
getVersion()
Returns the version of the cache implementation. |
CacheFactory |
set(String name,
String value)
Sets a gemfire property that will be used when creating the Cache. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CacheFactory()
public CacheFactory(Properties props)
DistributedSystem.
props - the gemfire properties to initialize the factory with.| Method Detail |
|---|
public CacheFactory set(String name,
String value)
DistributedSystem.
name - the name of the gemfire propertyvalue - the value of the gemfire property
@Deprecated
public static Cache create(DistributedSystem system)
throws CacheExistsException,
TimeoutException,
CacheWriterException,
GatewayException,
RegionExistsException
CacheFactory(Properties) instead.
system.
The system can specify a "cache-xml-file"
property which will cause this creation to also create the
regions, objects, and attributes declared in the file. The
contents of the file must comply with the
"doc-files/cache6_5.dtd"> file.
Note that when parsing the XML file Declarable classes
are loaded using the current thread's context class loader.
system - a DistributedSystem obtained by calling
DistributedSystem.connect(java.util.Properties).
Cache that uses the specified
system for distribution.
IllegalArgumentException - If system is not connected.
CacheExistsException - If an open cache already exists.
CacheXmlException - If a problem occurs while parsing the declarative caching
XML file.
TimeoutException - If a Region.put(Object, Object) times out while initializing the
cache.
CacheWriterException - If a CacheWriterException is thrown while
initializing the cache.
GatewayException - If a GatewayException is thrown while
initializing the cache.
RegionExistsException - If the declarative caching XML file describes a region
that already exists (including the root region).
public Cache create()
throws TimeoutException,
CacheWriterException,
GatewayException,
RegionExistsException
If the cache does need to be created it will also be initialized from cache.xml if it exists.
CacheXmlException - If a problem occurs while parsing the declarative caching
XML file.
TimeoutException - If a Region.put(Object, Object) times out while initializing the
cache.
CacheWriterException - If a CacheWriterException is thrown while
initializing the cache.
GatewayException - If a GatewayException is thrown while
initializing the cache.
RegionExistsException - If the declarative caching XML file describes a region
that already exists (including the root region).public static Cache getInstance(DistributedSystem system)
Cache produced by an
earlier call to create().
system - the DistributedSystem the cache was created with.
Cache associated with the specified system.
CacheClosedException - if a cache has not been created
or the created one is closedpublic static Cache getInstanceCloseOk(DistributedSystem system)
Cache produced by an
earlier call to create() even if it has been closed.
system - the DistributedSystem the cache was created with.
Cache associated with the specified system.
CacheClosedException - if a cache has not been createdpublic static Cache getAnyInstance()
Cache produced by an
earlier call to create().
CacheClosedException - if a cache has not been created
or the only created one is closedpublic static String getVersion()
String
|
GemFire 6.5 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||