GemStone::GemFire::Cache::ICacheWriter Interface Reference

Inherited by GemStone::GemFire::Cache::CacheWriterAdapter.


Detailed Description

An application plug-in that can be installed on a region. Defines methods that are called before entry modification, such as writing the value to a database.

A distributed region will typically have a single cache writer. If the application is designed such that all or most updates to a region occur on a node, the cache writer for the region should be installed at that node.

A cache writer is defined in the RegionAttributes.

Cache writer invocations are initiated by the node where the entry or region modification occurs.

Before a region is updated via a put, create, or destroy operation, GemFire will call an ICacheWriter that is installed anywhere in any participating cache for that region, preferring a local ICacheWriter if there is one. Usually there will be only one ICacheWriter in the distributed system. If there are multiple ICacheWriters available in the distributed system, the GemFire implementation always prefers one that is stored locally, or else picks one arbitrarily. In any case, only one ICacheWriter will be invoked.

The typical use for a ICacheWriter is to update a database. Application writers should implement these methods to execute application-specific behavior before the cache is modified.

Note that cache writer callbacks are synchronous callbacks and have the ability to veto the cache update. Since cache writer invocations require communications over the network, (especially if they are not co-located on the nodes where the change occurs) the use of cache writers presents a performance penalty.

The ICacheWriter is capable of aborting the update to the cache by throwing a CacheWriterException. This exception or any runtime exception thrown by the ICacheWriter will abort the operation, and the exception will be propagated to the initiator of the operation, regardless of whether the initiator is in the same process as the ICacheWriter.

See also:
AttributesFactory.SetCacheWriter, RegionAttributes.CacheWriter, ICacheLoader, ICacheListener


Public Member Functions

bool BeforeCreate (EntryEvent^ ev)
bool BeforeDestroy (EntryEvent^ ev)
bool BeforeRegionClear (RegionEvent^ ev)
bool BeforeRegionDestroy (RegionEvent^ ev)
bool BeforeUpdate (EntryEvent^ ev)
void Close (Region^ region)

Member Function Documentation

bool GemStone::GemFire::Cache::ICacheWriter::BeforeCreate ( EntryEvent^   ev  ) 

Called before an entry is created. Entry creation is initiated by a Create, a Put, or a Get.

The CacheWriter can determine whether this value comes from a Get or not from Load. 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.

Parameters:
ev event object associated with creating the entry
See also:
Region.Create, Region.Put, Region.Get

Implemented in GemStone::GemFire::Cache::CacheWriterAdapter.

bool GemStone::GemFire::Cache::ICacheWriter::BeforeDestroy ( EntryEvent^   ev  ) 

Called before an entry is destroyed.

The entry being destroyed may or may not exist in the local cache where the CacheWriter is installed. This method is not called as a result of expiration or Region.LocalDestroyRegion.

Parameters:
ev event object associated with destroying the entry
See also:
Region.Destroy

Implemented in GemStone::GemFire::Cache::CacheWriterAdapter.

bool GemStone::GemFire::Cache::ICacheWriter::BeforeRegionClear ( RegionEvent^   ev  ) 

Called before this region is cleared.

Implemented in GemStone::GemFire::Cache::CacheWriterAdapter.

bool GemStone::GemFire::Cache::ICacheWriter::BeforeRegionDestroy ( RegionEvent^   ev  ) 

Called before this region is destroyed.

Parameters:
ev event object associated with destroying the region
See also:
Region.DestroyRegion

Implemented in GemStone::GemFire::Cache::CacheWriterAdapter.

bool GemStone::GemFire::Cache::ICacheWriter::BeforeUpdate ( EntryEvent^   ev  ) 

Called before an entry is updated. The entry update is initiated by a Put or a Get that causes the loader 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.

Parameters:
ev event object associated with updating the entry
See also:
Region.Put, Region.Get

Implemented in GemStone::GemFire::Cache::CacheWriterAdapter.

void GemStone::GemFire::Cache::ICacheWriter::Close ( Region^   region  ) 

Called when the region containing this callback is destroyed, when the cache is closed.

Implementations should clean up any external resources, such as database connections. Any runtime exceptions this method throws will be logged.

It is possible for this method to be called multiple times on a single callback instance, so implementations must be tolerant of this.

Parameters:
region region to close
See also:
Cache.Close, Region.DestroyRegion

Implemented in GemStone::GemFire::Cache::CacheWriterAdapter.


GemFire C++ Cache .NET API Documentation