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

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

Go to download

Checks if all your hazelcast cluster members are receiveing published messages over the bus.

There is a newer version: 3.1.1
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy