Skip to content

Instantly share code, notes, and snippets.

@jsanda
Created June 3, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsanda/95409e8f4956730d58a8 to your computer and use it in GitHub Desktop.
Save jsanda/95409e8f4956730d58a8 to your computer and use it in GitHub Desktop.
public class StateListenerTest {
private static final Log logger = LogFactory.getLog(StateListenerTest.class);
@Test
public void listenForStateChanges() throws Exception {
Cluster cluster = new ClusterBuilder()
.addContactPoints("127.0.0.1")
.withCredentials("rhqadmin", "rhqadmin")
.build();
cluster.register(new Host.StateListener() {
@Override
public void onAdd(Host host) {
logger.info("host " + host + " ADDED");
}
@Override
public void onUp(Host host) {
logger.info("host " + host + " UP");
}
@Override
public void onDown(Host host) {
logger.info("host " + host + " DOWN");
}
@Override
public void onRemove(Host host) {
logger.info("host " + host + " REMOVED");
}
});
logger.info("Initializing session");
Session session = cluster.connect("rhq");
try {
while (true) {
Thread.sleep(10000);
}
} catch (InterruptedException e) {
session.shutdown();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment