VMware GemFire Native C++ Reference  9.1
apache::geode::client::CacheFactory Class Reference

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

Inherits apache::geode::client::SharedBase.

Public Member Functions

CacheFactoryPtr addLocator (const char *host, int port)
 Adds a locator, given its host and port, to this factory. More...
 
CacheFactoryPtr addServer (const char *host, int port)
 Adds a server, given its host and port, to this factory. More...
 
CachePtr create ()
 To create the instance of Cache. More...
 
void preserveSB () const
 Atomically increment reference count. More...
 
int32_t refCount ()
 
void releaseSB () const
 Atomically decrement reference count, the SharedBase object is automatically deleted when its reference count goes to zero. More...
 
CacheFactoryPtr set (const char *name, const char *value)
 Sets a geode property that will be used when creating the {link }. More...
 
CacheFactoryPtr setFreeConnectionTimeout (int connectionTimeout)
 Sets the free connection timeout for this pool. More...
 
CacheFactoryPtr setIdleTimeout (long idleTimeout)
 Sets the amount of time a connection can be idle before expiring the connection. More...
 
CacheFactoryPtr setLoadConditioningInterval (int loadConditioningInterval)
 Sets the load conditioning interval for this pool. More...
 
CacheFactoryPtr setMaxConnections (int maxConnections)
 Sets the max number of client to server connections that the pool will create. More...
 
CacheFactoryPtr setMinConnections (int minConnections)
 Sets the minimum number of connections to keep available at all times. More...
 
CacheFactoryPtr setMultiuserAuthentication (bool multiuserAuthentication)
 Sets whether Pool is in multi user secure mode. More...
 
CacheFactoryPtr setPdxIgnoreUnreadFields (bool ignore)
 Control whether pdx ignores fields that were unread during deserialization. More...
 
CacheFactoryPtr setPdxReadSerialized (bool pdxReadSerialized)
 Sets the object preference to PdxInstance type. More...
 
CacheFactoryPtr setPingInterval (long pingInterval)
 The frequency with which servers must be pinged to verify that they are still alive. More...
 
CacheFactoryPtr setPRSingleHopEnabled (bool enabled)
 By default setPRSingleHopEnabled is true
The client is aware of location of partitions on servers hosting Regions. More...
 
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). More...
 
CacheFactoryPtr setRetryAttempts (int retryAttempts)
 Set the number of times to retry a request after timeout/exception. More...
 
CacheFactoryPtr setServerGroup (const char *group)
 Configures the group which contains all the servers that this pool connects to. More...
 
CacheFactoryPtr setSocketBufferSize (int bufferSize)
 Sets the socket buffer size for each connection made in this pool. More...
 
CacheFactoryPtr setStatisticInterval (int statisticInterval)
 The frequency with which the client statistics must be sent to the server. More...
 
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. More...
 
CacheFactoryPtr setSubscriptionEnabled (bool enabled)
 If set to true then the created pool will have server-to-client subscriptions enabled. More...
 
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. More...
 
CacheFactoryPtr setSubscriptionRedundancy (int redundancy)
 Sets the redundancy level for this pools server-to-client subscriptions. More...
 
CacheFactoryPtr setThreadLocalConnections (bool threadLocalConnections)
 Sets the thread local connections policy for this pool. More...
 
CacheFactoryPtr setUpdateLocatorListInterval (long updateLocatorListInterval)
 The frequency with which client updates the locator list. More...
 

Static Public Member Functions

static CacheFactoryPtr createCacheFactory (const PropertiesPtr &dsProps=::apache::geode::client::NullSharedBase::s_instancePtr)
 To create the instance of CacheFactory. More...
 
static CachePtr getAnyInstance ()
 Gets an arbitrary open instance of Cache produced by an earlier call to CacheFactory::create. More...
 
static CachePtr getInstance (const DistributedSystemPtr &system)
 Gets the instance of Cache produced by an earlier call to CacheFactory::create. More...
 
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. More...
 
static const char * getProductDescription ()
 Returns the product description string including product name and version. More...
 
static const char * getVersion ()
 Returns the version of the cache implementation. More...
 

Detailed Description

Top level class for configuring and using Geode 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

Member Function Documentation

CacheFactoryPtr apache::geode::client::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
hostis the host name or ip address that the locator is listening on.
portis the port that the locator is listening on.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif 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.
IllegalStateExceptionif the locator has already been added to this factory.
CacheFactoryPtr apache::geode::client::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
hostis the host name or ip address that the server is listening on.
portis the port that the server is listening on.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif 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.
IllegalStateExceptionif the server has already been added to this factory.
CachePtr apache::geode::client::CacheFactory::create ( )

To create the instance of Cache.

static CacheFactoryPtr apache::geode::client::CacheFactory::createCacheFactory ( const PropertiesPtr dsProps = ::apache::geode::client::NullSharedBase::s_instancePtr)
static

To create the instance of CacheFactory.

Parameters
dsPropsProperties which are applicable at client level.
static CachePtr apache::geode::client::CacheFactory::getAnyInstance ( )
static

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

Exceptions
CacheClosedExceptionif a cache has not been created or the only created one is closed
static CachePtr apache::geode::client::CacheFactory::getInstance ( const DistributedSystemPtr system)
static

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

Parameters
systemthe DistributedSystem the cache was created with.
Returns
the Cache associated with the specified system.
Exceptions
CacheClosedExceptionif a cache has not been created or the created one is closed
EntryNotFoundExceptionif a cache with specified system not found
static CachePtr apache::geode::client::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
systemthe DistributedSystem the cache was created with.
Returns
the Cache associated with the specified system.
Exceptions
CacheClosedExceptionif a cache has not been created
EntryNotFoundExceptionif a cache with specified system is not found
static const char* apache::geode::client::CacheFactory::getProductDescription ( )
static

Returns the product description string including product name and version.

static const char* apache::geode::client::CacheFactory::getVersion ( )
static

Returns the version of the cache implementation.

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

Returns
the version of the cache implementation as a String
void apache::geode::client::SharedBase::preserveSB ( ) const
inherited

Atomically increment reference count.

int32_t apache::geode::client::SharedBase::refCount ( )
inlineinherited
Returns
the reference count
void apache::geode::client::SharedBase::releaseSB ( ) const
inherited

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

CacheFactoryPtr apache::geode::client::CacheFactory::set ( const char *  name,
const char *  value 
)

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

Parameters
namethe name of the geode property
valuethe value of the geode property
Returns
a reference to this
Since
3.5
CacheFactoryPtr apache::geode::client::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
connectionTimeoutis the connection timeout in milliseconds
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif connectionTimeout is less than or equal to 0.
CacheFactoryPtr apache::geode::client::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
idleTimeoutis 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
IllegalArgumentExceptionif idleTimout is less than 0.
CacheFactoryPtr apache::geode::client::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
loadConditioningIntervalis the connection lifetime in milliseconds
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif connectionLifetime is less than -1.
CacheFactoryPtr apache::geode::client::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
maxConnectionsis the maximum number of connections in the pool. -1 indicates that there is no maximum number of connections
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif maxConnections is less than minConnections.
CacheFactoryPtr apache::geode::client::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
minConnectionsis the initial number of connections this pool will create.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif minConnections is less than 0.
CacheFactoryPtr apache::geode::client::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
multiuserAuthenticationto set the pool in multiuser mode.
Returns
a reference to this
CacheFactoryPtr apache::geode::client::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
ignoretrue 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 apache::geode::client::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
pdxReadSerializedtrue to prefer PdxInstance
Returns
this ClientCacheFactory
CacheFactoryPtr apache::geode::client::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
pingIntervalis the amount of time in milliseconds between pings.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif pingInterval is less than 0.
CacheFactoryPtr apache::geode::client::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
    nameis boolean whether PR Single Hop optimization is enabled or not.
    Returns
    a reference to this
CacheFactoryPtr apache::geode::client::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
timeoutis the number of milliseconds to wait for a response from a server
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif timeout is less than or equal to 0.
CacheFactoryPtr apache::geode::client::CacheFactory::setRetryAttempts ( int  retryAttempts)

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

Parameters
retryAttemptsis 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
IllegalArgumentExceptionif idleTimout is less than 0.
CacheFactoryPtr apache::geode::client::CacheFactory::setServerGroup ( const char *  group)

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

Parameters
groupis 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 apache::geode::client::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
bufferSizeis the size of the socket buffers used for reading and writing on each connection in this pool.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif bufferSize is less than or equal to 0.
CacheFactoryPtr apache::geode::client::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
statisticIntervalis the amount of time in milliseconds between sends of client statistics to the server.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif statisticInterval is less than -1.
CacheFactoryPtr apache::geode::client::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
ackIntervalis the number of milliseconds to wait before sending event acknowledgements.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif ackInterval is less than or equal to 0.
CacheFactoryPtr apache::geode::client::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 apache::geode::client::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
messageTrackingTimeoutis the number of milliseconds to set the timeout to.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif messageTrackingTimeout is less than or equal to 0.
CacheFactoryPtr apache::geode::client::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
redundancyis the number of redundant servers for this client's subscriptions.
Returns
a reference to this
Exceptions
IllegalArgumentExceptionif redundancyLevel is less than -1.
CacheFactoryPtr apache::geode::client::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
threadLocalConnectionsif true then enable thread local connections.
Returns
a reference to this
CacheFactoryPtr apache::geode::client::CacheFactory::setUpdateLocatorListInterval ( long  updateLocatorListInterval)

The frequency with which client updates the locator list.

To disable this set its value to 0.

Parameters
updateLocatorListIntervalis the amount of time in milliseconds between checking locator list at locator.

Pivotal GemFire C++ Cache API Documentation