Created
June 3, 2015 19:03
-
-
Save jsanda/95409e8f4956730d58a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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