org.swisspush.vertx.cluster.ClusterInformation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cluster-watchdog Show documentation
Show all versions of cluster-watchdog Show documentation
Checks if all your hazelcast cluster members are receiveing published messages over the bus.
package org.swisspush.vertx.cluster;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.Member;
import io.vertx.core.logging.Logger;
import java.util.HashSet;
import java.util.Set;
/**
* @author https://github.com/floriankammermann [Florian Kammermann] on 02.06.2015
*/
public class ClusterInformation {
public static Set getMembers(Logger log) throws MoreThanOneHazelcastInstanceException {
// get the hazelcast instances
Set allHazelcastInstances = Hazelcast.getAllHazelcastInstances();
if(allHazelcastInstances == null || allHazelcastInstances.size() == 0) {
log.error("ClusterWatchdog no hazelcast instances found");
return new HashSet<>();
}
if(allHazelcastInstances.size() > 1) {
log.error("ClusterWatchdog more than one hazelcast instances found: " + allHazelcastInstances.size());
throw new MoreThanOneHazelcastInstanceException();
}
log.debug("ClusterWatchdog found exactly one hazelcast instance, we can go on");
Set members = allHazelcastInstances.iterator().next().getCluster().getMembers();
log.debug("ClusterWatchdog found the following members in the hazelcast instance: " + members);
return members;
}
}