gemfire::CacheFactory Class Reference

Inherits gemfire::SharedBase.


Detailed Description

Top level class for configuring and using GemFire on a client.This should be called once to create Cache.

For the default values for the pool attributes see PoolFactory. To create additional Pools see PoolManager

Public Member Functions

CacheFactoryPtr addLocator (const char *host, int port)
 Adds a locator, given its host and port, to this factory.
CacheFactoryPtr addServer (const char *host, int port)
 Adds a server, given its host and port, to this factory.
CachePtr create ()
 To create the instance of Cache.
void preserveSB () const
 Atomically increment reference count.
int32_t refCount ()
 
Returns:
the reference count

void releaseSB () const
 Atomically decrement reference count, the SharedBase object is automatically deleted when its reference count goes to zero.
CacheFactoryPtr set (const char *name, const char *value)
 Sets a gemfire property that will be used when creating the {link }.
CacheFactoryPtr setFreeConnectionTimeout (int connectionTimeout)
 Sets the free connection timeout for this pool.
CacheFactoryPtr setIdleTimeout (long idleTimeout)
 Sets the amount of time a connection can be idle before expiring the connection.
CacheFactoryPtr setLoadConditioningInterval (int loadConditioningInterval)
 Sets the load conditioning interval for this pool.
CacheFactoryPtr setMaxConnections (int maxConnections)
 Sets the max number of client to server connections that the pool will create.
CacheFactoryPtr setMinConnections (int minConnections)
 Sets the minimum number of connections to keep available at all times.
CacheFactoryPtr setMultiuserAuthentication (bool multiuserAuthentication)
 Sets whether Pool is in multi user secure mode.
CacheFactoryPtr setPdxIgnoreUnreadFields (bool ignore)
 Control whether pdx ignores fields that were unread during deserialization.
CacheFactoryPtr setPdxReadSerialized (bool pdxReadSerialized)
 Sets the object preference to PdxInstance type.
CacheFactoryPtr setPingInterval (long pingInterval)
 The frequency with which servers must be pinged to verify that they are still alive.
CacheFactoryPtr setPRSingleHopEnabled (bool enabled)
 By default setPRSingleHopEnabled is true
The client is aware of location of partitions on servers hosting Regions.
CacheFactoryPtr setReadTimeout (int timeout)
 Sets the number of milliseconds to wait for a response from a server before timing out the operation and trying another server (if any are available).
CacheFactoryPtr setRetryAttempts (int retryAttempts)
 Set the number of times to retry a request after timeout/exception.
CacheFactoryPtr setServerGroup (const char *group)
 Configures the group which contains all the servers that this pool connects to.
CacheFactoryPtr setSocketBufferSize (int bufferSize)
 Sets the socket buffer size for each connection made in this pool.
CacheFactoryPtr setStatisticInterval (int statisticInterval)
 The frequency with which the client statistics must be sent to the server.
CacheFactoryPtr setSubscriptionAckInterval (int ackInterval)
 Sets the is the interval in milliseconds to wait before sending acknowledgements to the bridge server for events received from the server subscriptions.
CacheFactoryPtr setSubscriptionEnabled (bool enabled)
 If set to true then the created pool will have server-to-client subscriptions enabled.
CacheFactoryPtr setSubscriptionMessageTrackingTimeout (int messageTrackingTimeout)
 Sets the messageTrackingTimeout attribute which is the time-to-live period, in milliseconds, for subscription events the client has received from the server.
CacheFactoryPtr setSubscriptionRedundancy (int redundancy)
 Sets the redundancy level for this pools server-to-client subscriptions.
CacheFactoryPtr setThreadLocalConnections (bool threadLocalConnections)
 Sets the thread local connections policy for this pool.

Static Public Member Functions

static CachePtr create (const char *name, DistributedSystemPtr &system, const CacheAttributesPtr &attrs)
 Creates a new cache that uses the specified system.
static CachePtr create (const char *name, DistributedSystemPtr &system, const char *cacheXml=0, const CacheAttributesPtr &attrs=gemfire::NullSharedBase::s_instancePtr, bool ignorePdxUnreadFields=false, bool readPdxSerialized=false)
 Creates a new cache that uses the specified system.
static CacheFactoryPtr createCacheFactory (const PropertiesPtr &dsProps=gemfire::NullSharedBase::s_instancePtr)
 To create the instance of CacheFactory.
static CachePtr getAnyInstance ()
 Gets an arbitrary open instance of Cache produced by an earlier call to CacheFactory::create.
static CachePtr getInstance (const DistributedSystemPtr &system)
 Gets the instance of Cache produced by an earlier call to CacheFactory::create.
static CachePtr getInstanceCloseOk (const DistributedSystemPtr &system)
 Gets the instance of Cache produced by an earlier call to CacheFactory::create, even if it has been closed.
static const char * getProductDescription ()
 Returns the product description string including product name and version.
static const char * getVersion ()
 Returns the version of the cache implementation.


Member Function Documentation

CacheFactoryPtr gemfire::CacheFactory::addLocator ( const char *  host,
int  port 
)

Adds a locator, given its host and port, to this factory.

The locator must be a server locator and will be used to discover other running bridge servers and locators.

Parameters:
host is the host name or ip address that the locator is listening on.
port is the port that the locator is listening on.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if the host is an unknown host according to java.net.InetAddress#getByName or if the port is outside the valid range of [1..65535] inclusive.
IllegalStateException if the locator has already been added to this factory.

CacheFactoryPtr gemfire::CacheFactory::addServer ( const char *  host,
int  port 
)

Adds a server, given its host and port, to this factory.

The server must be a bridge server and this client will directly connect to the server without consulting a server locator.

Parameters:
host is the host name or ip address that the server is listening on.
port is the port that the server is listening on.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if the host is an unknown host according to java.net.InetAddress#getByName or if the port is outside the valid range of [1..65535] inclusive.
IllegalStateException if the server has already been added to this factory.

static CachePtr gemfire::CacheFactory::create ( const char *  name,
DistributedSystemPtr system,
const CacheAttributesPtr attrs 
) [static]

Creates a new cache that uses the specified system.

Parameters:
name name to associate with the new cache; cannot be NULL; if empty then "NativeCache" is used as the name
system a DistributedSystem obtained by calling DistributedSystem::connect.
attrs optional CacheAttributes for this cache
Returns:
a Cache that uses the specified system for distribution.
Exceptions:
IllegalArgumentException If system is not connected. or name is NULL
CacheExistsException If an open cache already exists.
Deprecated:
as of NativeClient 3.5, use CacheFactory#createCacheFactory instead.

static CachePtr gemfire::CacheFactory::create ( const char *  name,
DistributedSystemPtr system,
const char *  cacheXml = 0,
const CacheAttributesPtr attrs = gemfire::NullSharedBase::s_instancePtr,
bool  ignorePdxUnreadFields = false,
bool  readPdxSerialized = false 
) [static]

Creates a new cache that uses the specified system.

Parameters:
name name to associate with the new cache; cannot be NULL; if empty then "NativeCache" is used as the name
system a DistributedSystem obtained by calling DistributedSystem::connect.
cacheXml name of the xml file from which cache will be configured.
attrs optional CacheAttributes for this cache; these override the ones provided in cacheXml.
Returns:
a Cache that uses the specified system for distribution.
Exceptions:
IllegalArgumentException If system is not connected. or name is NULL
CacheExistsException If an open cache already exists.
CacheXmlException Something went wrong while parsing the XML
IllegalStateException If xml file is well-flrmed but not valid
Deprecated:
as of NativeClient 3.5, use CacheFactory#createCacheFactory instead.

CachePtr gemfire::CacheFactory::create (  ) 

To create the instance of Cache.

static CacheFactoryPtr gemfire::CacheFactory::createCacheFactory ( const PropertiesPtr dsProps = gemfire::NullSharedBase::s_instancePtr  )  [static]

To create the instance of CacheFactory.

Parameters:
dsProps Properties which are applicable at client level.

static CachePtr gemfire::CacheFactory::getAnyInstance (  )  [static]

Gets an arbitrary open instance of Cache produced by an earlier call to CacheFactory::create.

Exceptions:
CacheClosedException if a cache has not been created or the only created one is closed

static CachePtr gemfire::CacheFactory::getInstance ( const DistributedSystemPtr system  )  [static]

Gets the instance of Cache produced by an earlier call to CacheFactory::create.

Parameters:
system the DistributedSystem the cache was created with.
Returns:
the Cache associated with the specified system.
Exceptions:
CacheClosedException if a cache has not been created or the created one is closed
EntryNotFoundException if a cache with specified system not found

static CachePtr gemfire::CacheFactory::getInstanceCloseOk ( const DistributedSystemPtr system  )  [static]

Gets the instance of Cache produced by an earlier call to CacheFactory::create, even if it has been closed.

Parameters:
system the DistributedSystem the cache was created with.
Returns:
the Cache associated with the specified system.
Exceptions:
CacheClosedException if a cache has not been created
EntryNotFoundException if a cache with specified system is not found

static const char* gemfire::CacheFactory::getProductDescription (  )  [static]

Returns the product description string including product name and version.

static const char* gemfire::CacheFactory::getVersion (  )  [static]

Returns the version of the cache implementation.

For the 1.0 release of GemFire, the string returned is 1.0.

Returns:
the version of the cache implementation as a String

void gemfire::SharedBase::preserveSB (  )  const [inherited]

Atomically increment reference count.

int32_t gemfire::SharedBase::refCount (  )  [inline, inherited]

Returns:
the reference count

void gemfire::SharedBase::releaseSB (  )  const [inherited]

Atomically decrement reference count, the SharedBase object is automatically deleted when its reference count goes to zero.

CacheFactoryPtr gemfire::CacheFactory::set ( const char *  name,
const char *  value 
)

Sets a gemfire property that will be used when creating the {link }.

Parameters:
name the name of the gemfire property
value the value of the gemfire property
Returns:
a reference to this
Since:
3.5

CacheFactoryPtr gemfire::CacheFactory::setFreeConnectionTimeout ( int  connectionTimeout  ) 

Sets the free connection timeout for this pool.

If the pool has a max connections setting, operations will block if all of the connections are in use. The free connection timeout specifies how long those operations will block waiting for a free connection before receiving an AllConnectionsInUseException. If max connections is not set this setting has no effect.

See also:
setMaxConnections(int)
Parameters:
connectionTimeout is the connection timeout in milliseconds
Returns:
a reference to this
Exceptions:
IllegalArgumentException if connectionTimeout is less than or equal to 0.

CacheFactoryPtr gemfire::CacheFactory::setIdleTimeout ( long  idleTimeout  ) 

Sets the amount of time a connection can be idle before expiring the connection.

If the pool size is greater than the minimum specified by PoolFactory#setMinConnections(int), connections which have been idle for longer than the idleTimeout will be closed.

Parameters:
idleTimeout is the amount of time in milliseconds that an idle connection should live before expiring. -1 indicates that connections should never expire.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if idleTimout is less than 0.

CacheFactoryPtr gemfire::CacheFactory::setLoadConditioningInterval ( int  loadConditioningInterval  ) 

Sets the load conditioning interval for this pool.

This interval controls how frequently the pool will check to see if a connection to a given server should be moved to a different server to improve the load balance.

A value of -1 disables load conditioning

Parameters:
loadConditioningInterval is the connection lifetime in milliseconds
Returns:
a reference to this
Exceptions:
IllegalArgumentException if connectionLifetime is less than -1.

CacheFactoryPtr gemfire::CacheFactory::setMaxConnections ( int  maxConnections  ) 

Sets the max number of client to server connections that the pool will create.

If all of the connections are in use, an operation requiring a client to server connection will block until a connection is available.

See also:
setFreeConnectionTimeout(int)
Parameters:
maxConnections is the maximum number of connections in the pool. -1 indicates that there is no maximum number of connections
Returns:
a reference to this
Exceptions:
IllegalArgumentException if maxConnections is less than minConnections.

CacheFactoryPtr gemfire::CacheFactory::setMinConnections ( int  minConnections  ) 

Sets the minimum number of connections to keep available at all times.

When the pool is created, it will create this many connections. If 0 then connections will not be made until an actual operation is done that requires client-to-server communication.

Parameters:
minConnections is the initial number of connections this pool will create.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if minConnections is less than 0.

CacheFactoryPtr gemfire::CacheFactory::setMultiuserAuthentication ( bool  multiuserAuthentication  ) 

Sets whether Pool is in multi user secure mode.

If its in multiuser mode then app needs to get RegionService instance of Cache, to do the operations on cache. Deafult value is false.

Parameters:
multiuserAuthentication to set the pool in multiuser mode.
Returns:
a reference to this

CacheFactoryPtr gemfire::CacheFactory::setPdxIgnoreUnreadFields ( bool  ignore  ) 

Control whether pdx ignores fields that were unread during deserialization.

The default is to preserve unread fields be including their data during serialization. But if you configure the cache to ignore unread fields then their data will be lost during serialization.

You should only set this attribute to true if you know this member will only be reading cache data. In this use case you do not need to pay the cost of preserving the unread fields since you will never be reserializing pdx data.

Parameters:
ignore true if fields not read during pdx deserialization should be ignored; false, the default, if they should be preserved.
Returns:
this CacheFactory
Since:
3.6

CacheFactoryPtr gemfire::CacheFactory::setPdxReadSerialized ( bool  pdxReadSerialized  ) 

Sets the object preference to PdxInstance type.

When a cached object that was serialized as a PDX is read from the cache a PdxInstance will be returned instead of the actual domain class. The PdxInstance is an interface that provides run time access to the fields of a PDX without deserializing the entire PDX. The PdxInstance implementation is a light weight wrapper that simply refers to the raw bytes of the PDX that are kept in the cache. Using this method applications can choose to access PdxInstance instead of C++ object.

Note that a PdxInstance is only returned if a serialized PDX is found in the cache. If the cache contains a deserialized PDX, then a domain class instance is returned instead of a PdxInstance.

Parameters:
pdxReadSerialized true to prefer PdxInstance
Returns:
this ClientCacheFactory

CacheFactoryPtr gemfire::CacheFactory::setPingInterval ( long  pingInterval  ) 

The frequency with which servers must be pinged to verify that they are still alive.

Each server will be sent a ping every pingInterval if there has not been any other communication with the server.

These pings are used by the server to monitor the health of the client. Make sure that the pingInterval is less than the maximum time between pings allowed by the bridge server.

Parameters:
pingInterval is the amount of time in milliseconds between pings.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if pingInterval is less than 0.

CacheFactoryPtr gemfire::CacheFactory::setPRSingleHopEnabled ( bool  enabled  ) 

By default setPRSingleHopEnabled is true
The client is aware of location of partitions on servers hosting Regions.

Using this information, the client routes the client cache operations directly to the server which is hosting the required partition for the cache operation. If setPRSingleHopEnabled is false the client can do an extra hop on servers to go to the required partition for that cache operation. The setPRSingleHopEnabled avoids extra hops only for following cache operations:
1. Region#put(Object, Object)
2. Region#get(Object)
3. Region#destroy(Object)
4. Region#getAll(Object, object)
If true, works best when PoolFactory#setMaxConnections(int) is set to -1.

Parameters:
name is boolean whether PR Single Hop optimization is enabled or not.
Returns:
a reference to this

CacheFactoryPtr gemfire::CacheFactory::setReadTimeout ( int  timeout  ) 

Sets the number of milliseconds to wait for a response from a server before timing out the operation and trying another server (if any are available).

Parameters:
timeout is the number of milliseconds to wait for a response from a server
Returns:
a reference to this
Exceptions:
IllegalArgumentException if timeout is less than or equal to 0.

CacheFactoryPtr gemfire::CacheFactory::setRetryAttempts ( int  retryAttempts  ) 

Set the number of times to retry a request after timeout/exception.

Parameters:
retryAttempts is the number of times to retry a request after timeout/exception. -1 indicates that a request should be tried against every available server before failing
Returns:
a reference to this
Exceptions:
IllegalArgumentException if idleTimout is less than 0.

CacheFactoryPtr gemfire::CacheFactory::setServerGroup ( const char *  group  ) 

Configures the group which contains all the servers that this pool connects to.

Parameters:
group is the server group that this pool will connect to. If the value is null or "" then the pool connects to all servers.
Returns:
a reference to this

CacheFactoryPtr gemfire::CacheFactory::setSocketBufferSize ( int  bufferSize  ) 

Sets the socket buffer size for each connection made in this pool.

Large messages can be received and sent faster when this buffer is larger. Larger buffers also optimize the rate at which servers can send events for client subscriptions.

Parameters:
bufferSize is the size of the socket buffers used for reading and writing on each connection in this pool.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if bufferSize is less than or equal to 0.

CacheFactoryPtr gemfire::CacheFactory::setStatisticInterval ( int  statisticInterval  ) 

The frequency with which the client statistics must be sent to the server.

Doing this allows GFMon to monitor clients.

A value of -1 disables the sending of client statistics to the server.

Parameters:
statisticInterval is the amount of time in milliseconds between sends of client statistics to the server.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if statisticInterval is less than -1.

CacheFactoryPtr gemfire::CacheFactory::setSubscriptionAckInterval ( int  ackInterval  ) 

Sets the is the interval in milliseconds to wait before sending acknowledgements to the bridge server for events received from the server subscriptions.

Parameters:
ackInterval is the number of milliseconds to wait before sending event acknowledgements.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if ackInterval is less than or equal to 0.

CacheFactoryPtr gemfire::CacheFactory::setSubscriptionEnabled ( bool  enabled  ) 

If set to true then the created pool will have server-to-client subscriptions enabled.

If set to false then all Subscription* attributes are ignored at the time of creation.

Returns:
a reference to this

CacheFactoryPtr gemfire::CacheFactory::setSubscriptionMessageTrackingTimeout ( int  messageTrackingTimeout  ) 

Sets the messageTrackingTimeout attribute which is the time-to-live period, in milliseconds, for subscription events the client has received from the server.

It is used to minimize duplicate events. Entries that have not been modified for this amount of time are expired from the list.

Parameters:
messageTrackingTimeout is the number of milliseconds to set the timeout to.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if messageTrackingTimeout is less than or equal to 0.

CacheFactoryPtr gemfire::CacheFactory::setSubscriptionRedundancy ( int  redundancy  ) 

Sets the redundancy level for this pools server-to-client subscriptions.

If 0 then no redundant copies are kept on the servers. Otherwise an effort is made to maintain the requested number of copies of the server-to-client subscriptions. At most, one copy per server is made up to the requested level.

Parameters:
redundancy is the number of redundant servers for this client's subscriptions.
Returns:
a reference to this
Exceptions:
IllegalArgumentException if redundancyLevel is less than -1.

CacheFactoryPtr gemfire::CacheFactory::setThreadLocalConnections ( bool  threadLocalConnections  ) 

Sets the thread local connections policy for this pool.

If true then any time a thread goes to use a connection from this pool it will check a thread local cache and see if it already has a connection in it. If so it will use it. If not it will get one from this pool and cache it in the thread local. This gets rid of thread contention for the connections but increases the number of connections the servers see.

If false then connections are returned to the pool as soon as the operation being done with the connection completes. This allows connections to be shared amonst multiple threads keeping the number of connections down.

Parameters:
threadLocalConnections if true then enable thread local connections.
Returns:
a reference to this


GemFire C++ Cache API Documentation