Search in sources :

Example 1 with ConsoleApp

use of com.hazelcast.console.ConsoleApp in project microservices by pwillhan.

the class QuorumExample method main.

public static void main(String[] args) throws Exception {
    QuorumConfig quorumConf = new QuorumConfig();
    quorumConf.setName("atLeastTwoNodesWithMajority");
    quorumConf.setEnabled(true);
    quorumConf.setType(QuorumType.WRITE);
    quorumConf.addListenerConfig(new QuorumListenerConfig(new ClusterQuorumListener()));
    final int expectedClusterSize = 5;
    quorumConf.setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return members.size() >= 2 && members.size() > expectedClusterSize / 2;
        }
    });
    MapConfig mapConf = new MapConfig();
    mapConf.setName("default");
    mapConf.setQuorumName("atLeastTwoNodesWithMajority");
    Config conf = new Config();
    conf.addQuorumConfig(quorumConf);
    conf.addMapConfig(mapConf);
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
    new ConsoleApp(hz).start(args);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClusterQuorumListener(listeners.ClusterQuorumListener) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) ConsoleApp(com.hazelcast.console.ConsoleApp) MapConfig(com.hazelcast.config.MapConfig) QuorumFunction(com.hazelcast.quorum.QuorumFunction) Member(com.hazelcast.core.Member)

Aggregations

Config (com.hazelcast.config.Config)1 MapConfig (com.hazelcast.config.MapConfig)1 QuorumConfig (com.hazelcast.config.QuorumConfig)1 QuorumListenerConfig (com.hazelcast.config.QuorumListenerConfig)1 ConsoleApp (com.hazelcast.console.ConsoleApp)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Member (com.hazelcast.core.Member)1 QuorumFunction (com.hazelcast.quorum.QuorumFunction)1 ClusterQuorumListener (listeners.ClusterQuorumListener)1