NCache provides events that are fired when a node joins or leaves the cluster or when cache stops. Applications can register interest for these events and are therefore notified when such events occur. Both .NET and Java clients can receive such notifications.
Below example explains how to write event handlers which respond to notifications about the cluster status.
import com.alachisoft.ncache.web.caching.*;
import com.alachisoft.ncache.event.*;
public class CacheEventListner implements ClusterListener
{
public void cacheStopped(ClusterEvent ce)
{
System.out.println("Cache Stopped");
}
public void memberJoined(ClusterEvent ce)
{
System.out.println(ce.getIp() + " Joined Cluster " + ce.getCacheId());
}
public void memberLeft(ClusterEvent ce)
{
System.out.println(ce.getIp() + " left Cluster " + ce.getCacheId());
}
}
CacheEventListner eventListner = new CacheEventListner();
Cache _cache = NCache.initializeCache("ClusteredCache");
_cache.addClusterEventListener(eventListner);
_cache.registerMemberJoinedNotification();
_cache.registerMemberJoinedNotification();
_cache.registerMemberLeftNotification();
See Also