|
GemFire 5.5.1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.gemstone.gemfire.cache.util.BridgeWriter
public class BridgeWriter
A CacheWriter that writes data to one or more remote
CacheServer processes. This allows for a hierarchical caching
scheme in which one cache ('client' cache) delegates a request to another
cache ('server' cache).
When using the BridgeWriter, at least two GemFire Caches must
exist in a client/server mode (they should not be part of the same
distributed system).
The 'server' cache must be running a gemfire CacheServer
process, while the 'client' cache must have a BridgeWriter
installed in one or more of its Regions. If a
BridgeWriter is defined in a client Region,
there must also be a Region defined in the 'server' cache with
the same exact name.
The BridgeWriter performs put() operations on
the remote server cache, and does not provide the distribution behavior that
can be enabled by using a DISTRIBUTED or
DISTRIBUTED_NO_ACK Region. This mechanism is
designed as a more targeted alternative to netSearch, in which the 'client'
cache completely delegates the loading of the data to the 'server' cache if
it is not yet cached in the client. This directed behavior enables a remote
network put() operation to be performed much more efficiently
in a scenario where there is a hierarchical cache topology. Updates and
invalidation remain local, in fact the Regions that are used
for this loosely coupled cache may even be LOCAL in scope.
The BridgeWriter may be used to configure caches with
multi-layer hierarchies.
Load Balancing:
The BridgeWriter supports these load balancing mechanisms
(specified by the LBPolicy config attribute):
BridgeWriter picks another server and then sends further
requests to that server. This achieves a level of load balancing by
redirecting requests away from servers that produce timeouts.Failover:
If a remote server cache throws an exception or times out, the client will
retry based on the configured retryCount parameter. If the
retryCount is exceeded, the server in question will be added
to a failed server list, and the client will select another server to connect
to. The servers in the failed server list will be periodically pinged with an
intelligent ping that ensures cache health. If a server is determined to be
healthy again, it will be promoted back to the healthy server list. The time
period between failed server pings is configurable via the
retryInterval parameter.
Configuration:
The BridgeWriter is configurable declaratively or
programmatically. Declarative configuration is achieved through defining the
configuration parameters in a cache.xml file. Programmatic
configuration may be achieved by first instantiating a
BridgeWriter object and subsequently calling
init(Properties)with a Properties object containing
each desired parameter and value.
The supported parameters are:
<parameter name="endpoints">
<string>MyPrimaryServer=hostsrv:40404,MySecondary=hostsrv2:40404</string>
</parameter>
<parameter name="readTimeout">
<string>5000</string>
</parameter>
readTimeout configuration, within the
allowableServerTimeoutPeriod, before being placed in the dead
server list.
<parameter name="allowableServerTimeouts">
<string>13</string>
</parameter>
readTimeout configuration allowableServerTimeout
times before being placed in the dead server list.
<parameter name="allowableServerTimeoutPeriod">
<string>20000</string>
</parameter>
<parameter name="retryAttempts">
<string>5</string>
</parameter>
ServerMonitor to ping living servers to verify that
they are still alive and dead servers to verify that they are still dead.
<parameter name="retryInterval">
<string>10000</string>
</parameter>
<parameter name="LBPolicy">
<string>Sticky</string>
</parameter>
0 causes no initial connections to be
created (they are only created on demand).
<parameter name="connectionsPerServer">
<string>10</string>
</parameter>
<parameter name="establishCallbackConnection">
<string>true</string>
</parameter>
<parameter name="redundancyLevel">
<string>1</string>
</parameter>
<parameter name="socketBufferSize">
<string>32768</string>
</parameter>
<parameter name="messageTrackingTimeout">
<string>300000</string>
</parameter>
<parameter name="useLiveServerMonitorThread">
<string>true</string>
</parameter>
<parameter name="clientAckInterval">
<string>5000</string>
</parameter>
If you are using a cache.xml file to create a
Region declaratively, you can include the following to
associate a BridgeWriter with a Region (default
values shown for optional parameters):
<cache-writer>
<classname>com.gemstone.gemfire.cache.util.BridgeWriter</classname>
<parameter name="endpoints">
<string>MyHost=ninja.gemstone.com:40404</string>
</parameter>
<parameter name="readTimeout">
<string>10000</string>
</parameter>
<parameter name="retryAttempts">
<string>5</string>
</parameter>
<parameter name="retryInterval">
<string>10000</string>
</parameter>
<parameter name="LBPolicy">
<string>Sticky</string>
</parameter>
<parameter name="establishCallbackConnection">
<string>false</string>
</parameter>
<parameter name="socketBufferSize">
<string>32768</string>
</parameter>
</parameter>
<parameter name="messageTrackingTimeout">
<string>300000</string>
</parameter>
</parameter>
<parameter name="useLiveServerMonitorThread">
<string>true</string>
</parameter>
</parameter>
<parameter name="clientAckInterval">
<string>5000</string>
</parameter>
</cache-writer>
| Constructor Summary | |
|---|---|
BridgeWriter()
|
|
| Method Summary | |
|---|---|
void |
addEndpoint(String name,
String host,
int port)
Add an Endpoint to the known Endpoints. |
void |
attach(Region r)
Notify the BridgeWriter that the given Region will begin delivering events to this BridgeWriter. |
void |
beforeCreate(EntryEvent event)
Called before an entry is created. |
void |
beforeDestroy(EntryEvent event)
Called before an entry is destroyed. |
void |
beforeRegionClear(RegionEvent event)
Called before a region is cleared. |
void |
beforeRegionDestroy(RegionEvent event)
Called before a region is destroyed. |
void |
beforeUpdate(EntryEvent event)
Called before an entry is updated. |
void |
close()
Called when a region using this BridgeWriter is destroyed,
when the cache is closed, or when a callback is removed from a region using
an AttributesMutator. |
boolean |
containsKey(Region region,
Object key)
Performs a containsKey on a key of a region on the cache server at the remote end of this connection. |
void |
createRegionOnServer(String parentRegionName,
String regionName)
|
void |
detach(Region r)
Notify the BridgeWriter that the given region is no longer relevant. |
static void |
emergencyClose()
|
Set |
getActiveServers()
Returns the list of names of servers that are currently marked active and connected to. |
Object |
getConnectionProxy()
Returns the ConnectionProxy associated with this
BridgeLoader. |
Object |
getCurrentServer()
Returns the currently used Endpoint. |
Set |
getDeadServers()
Returns the list of names of servers that are currently marked dead. |
Object[] |
getEndpoints()
Returns the list of end points passed to the bridge writer In release 5.0, the signature of this method was changed from public Endpoint[] getEndpoints()to public Object[] getEndpoints() |
List |
getInterestList(Region r,
int interestType)
Returns the interest list for a particular region. |
String |
getLBPolicy()
Returns the load balancing policy being used by the bridge writer Internal use only |
Object |
getObjectFromPrimaryServer(Region r,
Object key)
For internal use only. |
Object |
getPrimaryEndpoint()
Returns the Endpoint used to obtain the interest list. |
Properties |
getProperties()
Returns the properties that defined this BridgeWriter. |
int |
getReadTimeout()
Returns the read timeout being used to time out requests to the server Internal use only. |
int |
getRetryAttempts()
Returns the number of times the bridge writer tries to write data on encountering certain types of exceptions. |
int |
getRetryInterval()
Returns the retry interval in use. |
void |
handleMarker()
Handle the marker message by invoking CacheListener.afterRegionLive on all connected Regions |
boolean |
hasEstablishCallbackConnection()
Return true if this writer has not been closed and it was configured to establish a callback connection. |
void |
init(BridgeWriter bridgeWriter)
Initializes this writer from an existing BridgeWriter. |
void |
init(Properties p)
Initializes the writer with supplied config parameters. |
boolean |
isClosed()
Returns true if this BridgeWriter has been closed. |
Set |
keySet(Region region)
Performs a keySet of a region on the cache server at the remote end of this connection. |
static void |
loadEmergencyClasses()
Ensure that the BridgeClient and ConnectionProxyImpl classes get loaded. |
List |
registerInterest(Region r,
Object key,
int interestType,
InterestResultPolicy policy,
boolean isDurable)
Register interest in a particular region and key. |
void |
release()
For speed optimizations, a connection to a server may be assigned to the calling thread when the BridgeWriter is used to do an operation. |
void |
removeEndpoint(String name,
String host,
int port)
Remove an Endpoint from the dead Endpoints. |
void |
terminate()
This method should be invoked when the BridgeWriter mechanism is to be shut down explicitly , outside of closing the cache. |
String |
toString()
Returns a brief description of this BridgeWriter |
void |
unregisterInterest(Region r,
Object key,
int interestType)
Unregister interest in a particular region and key. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public BridgeWriter()
| Method Detail |
|---|
public void init(Properties p)
Properties object that at a minimum contains the 'endpoints'
parameter before the writer can be used. If init fails with a
LicenseException, the resulting BridgeWriter will throw
IllegalStateException until it is properly initialized.
init in interface Declarablep - configuration data such as 'endpoint' definitions
LicenseException
IllegalStateException - if the writer is already initializedpublic void init(BridgeWriter bridgeWriter)
BridgeWriter. This
method reuses the existing BridgeWriter's proxy.
bridgeWriter - The existing BridgeWriter
IllegalStateException - if the writer is already initializedpublic static void loadEmergencyClasses()
SystemFailure.loadEmergencyClasses()public static void emergencyClose()
SystemFailure.emergencyClose()public void close()
BridgeWriter is destroyed,
when the cache is closed, or when a callback is removed from a region using
an AttributesMutator.
Closes connections to BridgeServerswhen all
Regionsare finished using this BridgeWriter,
close in interface CacheCallbackattach(Region),
detach(Region)public void handleMarker()
public boolean isClosed()
BridgeWriter has been closed.
public void detach(Region r)
destructionand
closure. This method effects the behavor of
close().
r - the Region which will no longer use this BridgeWriterattach(Region),
close()public void release()
public void terminate()
public void beforeUpdate(EntryEvent event)
throws CacheWriterException
put or a get that causes the writer to update
an existing entry. The entry previously existed in the cache where the
operation was initiated, although the old value may have been null. The
entry being updated may or may not exist in the local cache where the
CacheWriter is installed.
beforeUpdate in interface CacheWriterevent - an EntryEvent that provides information about the operation in
progress
CacheWriterException - if thrown will abort the operation in progress, and the exception
will be propagated back to caller that initiated the operationRegion.put(Object, Object),
Region.get(Object)
public void beforeCreate(EntryEvent event)
throws CacheWriterException
create, a put, or a get.
The CacheWriter can determine whether this value comes from
a get or not from EntryEvent.isLoad(). The entry
being created may already exist in the local cache where this
CacheWriter is installed, but it does not yet exist in the
cache where the operation was initiated.
beforeCreate in interface CacheWriterevent - an EntryEvent that provides information about the operation in
progress
CacheWriterException - if thrown will abort the operation in progress, and the exception
will be propagated back to caller that initiated the operationRegion.create(Object, Object),
Region.put(Object, Object),
Region.get(Object)
public void beforeDestroy(EntryEvent event)
throws CacheWriterException
Region.localDestroy(Object).
beforeDestroy in interface CacheWriterevent - an EntryEvent that provides information about the operation in
progress
CacheWriterException - if thrown will abort the operation in progress, and the exception
will be propagated back to caller that initiated the operationRegion.destroy(Object)
public void beforeRegionDestroy(RegionEvent event)
throws CacheWriterException
CacheWriter will
not additionally be called for each entry that is destroyed in the region
as a result of a region destroy. If the region's subregions have
CacheWriter s installed, then they will be called for the
cascading subregion destroys. This method is not called as a
result of expiration or Region.localDestroyRegion(). However, the
close()method is invoked regardless of whether a region is
destroyed locally. A non-local region destroy results in an invocation of
beforeRegionDestroy(com.gemstone.gemfire.cache.RegionEvent)followed by an invocation of close().
WARNING: This method should not destroy or create any regions itself or a deadlock will occur.
beforeRegionDestroy in interface CacheWriterevent - a RegionEvent that provides information about the
CacheWriterException - if thrown, will abort the operation in progress, and the
exception will be propagated back to the caller that initiated
the operationRegion.destroyRegion()
public void beforeRegionClear(RegionEvent event)
throws CacheWriterException
CacheWriter will
not additionally be called for each entry that is cleared in the region
as a result of a region clear. If the region's subregions have
CacheWriter s installed, then they will be called for the
cascading subregion clears. This method is not called as a
result of expiration or Region.localDestroyRegion(). However, the
close()method is invoked regardless of whether a region is
cleared locally. A non-local region clear results in an invocation of
beforeRegionClear(com.gemstone.gemfire.cache.RegionEvent)followed by an invocation of close().
WARNING: This method should not destroy or create or clear any regions itself or a deadlock will occur.
beforeRegionClear in interface CacheWriterevent - a RegionEvent that provides information about the
CacheWriterException - if thrown, will abort the operation in progress, and the
exception will be propagated back to the caller that initiated
the operationRegion.clear()
public void createRegionOnServer(String parentRegionName,
String regionName)
throws CacheWriterException
CacheWriterException
public List registerInterest(Region r,
Object key,
int interestType,
InterestResultPolicy policy,
boolean isDurable)
throws CacheWriterException
r - The region in which to register interestkey - The key in which to register interestinterestType - The type of interest (e.g. regular expression)policy - The interest result policy. This can be one of:
isDurable - true if the register interest is durable
CacheWriterExceptionpublic boolean hasEstablishCallbackConnection()
public void unregisterInterest(Region r,
Object key,
int interestType)
throws CacheWriterException
r - The region in which to unregister interestkey - The key in which to unregister interest
CacheWriterException
public List getInterestList(Region r,
int interestType)
throws CacheWriterException
r - the region whose interest list to provide
CacheWriterException
public Object getObjectFromPrimaryServer(Region r,
Object key)
throws CacheWriterException
registerInterest(Region, Object, int, InterestResultPolicy, boolean)to
restore coherence in the client cache.
CacheWriterException
public Set keySet(Region region)
throws CacheWriterException
region - The region on which to perform keySet.
CacheWriterException
public boolean containsKey(Region region,
Object key)
throws CacheWriterException
region - The region on which to perform containsKey.key - The key on which to perform containsKey.
CacheWriterExceptionpublic int getRetryInterval()
public int getReadTimeout()
public int getRetryAttempts()
public Object[] getEndpoints()
public Endpoint[] getEndpoints()public Object[] getEndpoints()
public String getLBPolicy()
public Set getDeadServers()
public Set getActiveServers()
public Object getCurrentServer()
Endpoint in certain load balancing policies (e.g. STICKY).
public Properties getProperties()
BridgeWriter.
BridgeWriterpublic Object getPrimaryEndpoint()
Endpoint used to obtain the interest list.
Endpoint used to obtain the interest list; null
if no interest has been registered or an interest list endpoint
currently does not exist.
public void addEndpoint(String name,
String host,
int port)
throws EndpointExistsException
Endpoint to the known Endpoints.
name - The name of the endpoint to addhost - The host name or ip address of the endpoint to addport - The port of the endpoint to add
EndpointExistsException - if the Endpoint to be
added already exists.
public void removeEndpoint(String name,
String host,
int port)
throws EndpointDoesNotExistException,
EndpointInUseException
Endpoint from the dead Endpoints.
The specified Endpoint must be dead.
name - The name of the endpoint to removehost - The host name or ip address of the endpoint to removeport - The port of the endpoint to remove
EndpointDoesNotExistException - if the Endpoint to be
removed doesn't exist.
EndpointInUseException - if the Endpoint to be removed
contains Connectionspublic String toString()
BridgeWriter
toString in class Objectpublic void attach(Region r)
close()
This is called internally when the BridgeWriter is added to a Region via
AttributesFactory.setCacheWriter(CacheWriter)}
r - the Region which will begin use this BridgeWriter.detach(Region),
close()public Object getConnectionProxy()
ConnectionProxy associated with this
BridgeLoader.
For internal use only.
ConnectionProxy associated with this
BridgeLoader
|
GemFire 5.5.1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||