Pivotal GemFire Native Client Cache Reference  9.0.6
gemfire::CacheListener Class Reference

An application plug-in that can be installed on a region. More...

Inherits gemfire::SharedBase.

Public Member Functions

virtual void afterCreate (const EntryEvent &event)
 Handles the event of a new key being added to a region. More...
 
virtual void afterDestroy (const EntryEvent &event)
 Handles the event of an entry being destroyed. More...
 
virtual void afterInvalidate (const EntryEvent &event)
 Handles the event of an entry's value being invalidated. More...
 
virtual void afterRegionClear (const RegionEvent &event)
 Handles the event of a region being cleared. More...
 
virtual void afterRegionDestroy (const RegionEvent &event)
 Handles the event of a region being destroyed. More...
 
virtual void afterRegionDisconnected (const RegionPtr &region)
 Called when all the endpoints assosiated with region are down. More...
 
virtual void afterRegionInvalidate (const RegionEvent &event)
 Handles the event of a region being invalidated. More...
 
virtual void afterRegionLive (const RegionEvent &event)
 Handles the event of a region being live. More...
 
virtual void afterUpdate (const EntryEvent &event)
 Handles the event of an entry's value being modified in a region. More...
 
virtual void close (const RegionPtr &region)
 Called when the region containing this callback is destroyed, when the cache is closed. 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...
 
virtual ~CacheListener ()
 public methods More...
 

Protected Member Functions

 CacheListener ()
 constructors More...
 

Detailed Description

An application plug-in that can be installed on a region.

Listeners are change notifications that are invoked AFTER the change has occured for region update operations on a client. Listeners also receive notifications when entries in a region are modified. Multiple events can cause concurrent invocation of CacheListener methods. If event A occurs before event B, there is no guarantee that their corresponding CacheListener method invocations will occur in the same order. Any exceptions thrown by the listener are caught by GemFire and logged. If the exception is due to listener invocation on the same thread where a region operation has been performed, then a CacheListenerException is thrown back to the application. If the exception is for a notification received from server then that is logged and the notification thread moves on to receiving other notifications.

There are two cases in which listeners are invoked. The first is when a region modification operation (e.g. put, create, destroy, invalidate) is performed. For this case it is important to ensure that minimal work is done in the listener before returning control back to Gemfire since the operation will block till the listener has not completed. For example, a listener implementation may choose to hand off the event to a thread pool that then processes the event on its thread rather than the listener thread. The second is when notifications are received from java server as a result of region register interest calls (Region::registerKeys etc), or invalidate notifications when notify-by-subscription is false on the server. In this case the methods of CacheListener are invoked asynchronously (i.e. does not block the thread that receives notification messages). Additionally for the latter case of notifications from server, listener is always invoked whether or not local operation is successful e.g. if a destroy notification is received and key does not exist in the region, the listener will still be invoked. This is different from the first case where listeners are invoked only when the region update operation succeeds.

See also
AttributesFactory::setCacheListener
RegionAttributes::getCacheListener
CacheListenerException

Constructor & Destructor Documentation

virtual gemfire::CacheListener::~CacheListener ( )
virtual

public methods

destructor

gemfire::CacheListener::CacheListener ( )
protected

constructors

Member Function Documentation

virtual void gemfire::CacheListener::afterCreate ( const EntryEvent event)
virtual

Handles the event of a new key being added to a region.

The entry did not previously exist in this region in the local cache (even with a NULLPTR value).

Parameters
eventdenotes the event object associated with the entry creation This function does not throw any exception.
See also
Region::create
Region::put
Region::get
virtual void gemfire::CacheListener::afterDestroy ( const EntryEvent event)
virtual

Handles the event of an entry being destroyed.

Parameters
eventEntryEvent denotes the event object associated with the entry destruction
See also
Region::destroy
virtual void gemfire::CacheListener::afterInvalidate ( const EntryEvent event)
virtual

Handles the event of an entry's value being invalidated.

Parameters
eventEntryEvent denotes the event object associated with the entry invalidation
virtual void gemfire::CacheListener::afterRegionClear ( const RegionEvent event)
virtual

Handles the event of a region being cleared.

Events are not invoked for each individual entry that is removed as a result of the region being cleared. Each subregion, however, gets its own afterRegionClear event invoked on its listener.

Parameters
eventRegionEvent denotes the event object associated with the region removal
See also
Region::clear
virtual void gemfire::CacheListener::afterRegionDestroy ( const RegionEvent event)
virtual

Handles the event of a region being destroyed.

Events are not invoked for each individual entry that is destroyed as a result of the region being destroyed. Each subregion, however, gets its own afterRegionDestroyed event invoked on its listener.

Parameters
eventRegionEvent denotes the event object associated with the region destruction
See also
Region::destroyRegion
virtual void gemfire::CacheListener::afterRegionDisconnected ( const RegionPtr region)
virtual

Called when all the endpoints assosiated with region are down.

This will be called when all the endpoints are down for the first time. If endpoints come up and again go down it will be called again. This will also be called when all endpoints are down and region is attached to the pool.

Parameters
regionRegionPtr denotes the assosiated region.
virtual void gemfire::CacheListener::afterRegionInvalidate ( const RegionEvent event)
virtual

Handles the event of a region being invalidated.

Events are not invoked for each individual value that is invalidated as a result of the region being invalidated. Each subregion, however, gets its own regionInvalidated event invoked on its listener.

Parameters
eventRegionEvent denotes the event object associated with the region invalidation
See also
Region::invalidateRegion
virtual void gemfire::CacheListener::afterRegionLive ( const RegionEvent event)
virtual

Handles the event of a region being live.

This event will be invoked after processing all the past messages. Each subregion, however, gets its own afterRegionLive event invoked on its listener.

Parameters
eventRegionEvent denotes the associated event object
virtual void gemfire::CacheListener::afterUpdate ( const EntryEvent event)
virtual

Handles the event of an entry's value being modified in a region.

This entry previously existed in this region in the local cache, but its previous value may have been NULLPTR.

Parameters
eventEntryEvent denotes the event object associated with updating the entry
See also
Region::put
virtual void gemfire::CacheListener::close ( const RegionPtr region)
virtual

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.

See also
Cache::close
Region::destroyRegion
void gemfire::SharedBase::preserveSB ( ) const
inherited

Atomically increment reference count.

int32_t gemfire::SharedBase::refCount ( )
inlineinherited
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.


GemFire C++ Cache API Documentation