All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.swisspush.vertx.cluster.ClusterInformation Maven / Gradle / Ivy

package org.swisspush.vertx.cluster;

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.cluster.Member;
import org.slf4j.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.isEmpty()) {
            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;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy