Pivotal GemFire® v8.2

Implementing Cache Listeners for Durable Clients

Implementing Cache Listeners for Durable Clients

A cache listener for durable clients requires all callback methods to behave properly when stored events are replayed. A cache listener has a callback method, afterRegionLive, specifically for durable clients aspects.

For general instructions on implementing a cache listener, see CacheListener.

Writing Callbacks for Use With Durable Messaging

Durable clients require special attention to cache callbacks generated by the cache listener. During the initialization window when a reconnecting client has a functioning cache but is still receiving the stored messages from the queue, the client can replay events that are long past. These events are not applied to the cache, but they are sent to the cache listener. If the listener’s callbacks invoked by these events make changes to the cache, that could conflict with current operations and create data inconsistencies.

Consequently, you need to keep your callback implementations lightweight and not do anything in the cache that could produce incorrect results during this window. For details on implementing callbacks for GemFire event handlers, seeImplementing Cache Event Handlers in the GemFire User’s Guide.

Implementing the afterRegionLive Method

If you are using cache listeners, you can implement the afterRegionLive callback method provided for durable clients. This callback is invoked when the client has received all the old messages that were stored in its queue while it was disconnected. Implementing this method enables you to do application-specific operations when the client has replayed all of these old events.

If you do not wish to use this callback, and your listener is an instance of CacheListener (not a CacheListenerAdapter), you must implement afterRegionLive as a non-operational method.