BigMemory Max 4.3.4 | Product Documentation | BigMemory Max Developer Guide | Cluster Events | Listening for Cluster Events
 
Listening for Cluster Events
The interface net.sf.ehcache.cluster.ClusterTopologyListener provides methods for detecting the following cluster events:
public interface ClusterTopologyListener {
/**
* A node has joined the cluster
*
* @param node The joining node
*/
void nodeJoined(ClusterNode node);
/**
* A node has left the cluster
*
* @param node The departing node
*/
void nodeLeft(ClusterNode node);
/**
* This node has established contact with the cluster and can execute clustered
* operations.
*
* @param node The current node
*/
void clusterOnline(ClusterNode node);
/**
* This node has lost contact (possibly temporarily) with the cluster and
* cannot execute clustered operations
*
* @param node The current node
*/
void clusterOffline(ClusterNode node);
}
/**
* This node lost contact and rejoined the cluster again.
*
* This event is only fired in the node which rejoined and not to all the
* connected nodes
* @param oldNode The old node which got disconnected
* @param newNode The new node after rejoin
*/
void clusterRejoined(ClusterNode oldNode, ClusterNode newNode);
Example Code
This example prints out the cluster nodes and then registers a ClusterTopologyListener, which prints out events as they happen.
CacheManager mgr = ...
CacheCluster cluster = mgr.getCluster("TERRACOTTA");
// Get current nodes
Collection<ClusterNode> nodes = cluster.getNodes();
for(ClusterNode node : nodes) {
System.out.println(node.getId() + " " + node.getHostname() + " " + node.getIp());
}
// Register listener
cluster.addTopologyListener(new ClusterTopologyListener() {
public void nodeJoined(ClusterNode node) { System.out.println(node +
      " joined"); }
public void nodeLeft(ClusterNode node) { System.out.println(node + " left"); }
public void clusterOnline(ClusterNode node) { System.out.println(node +
      " enabled"); }
public void clusterOffline(ClusterNode node) { System.out.println(node +
      " disabled"); }
public void clusterRejoined(ClusterNode node, ClusterNode newNode) {
System.out.println(node + " rejoined the cluster as " + newNode);
}
});

Copyright © 2010 - 2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.