Book Image

Getting Started with Hazelcast, Second Edition

By : Matthew Johns
Book Image

Getting Started with Hazelcast, Second Edition

By: Matthew Johns

Overview of this book

Table of Contents (19 chapters)
Getting Started with Hazelcast Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Extending quorum


We previously saw how we can configure a simple cluster health check to ensure that a given number of nodes were present to support the application. However, should we need more detailed control over the quorum definition beyond a simple node count check, we can create our own quorum function that will allow us to programmatically define what it means to be healthy. This can be as simple or as complex as what the application requires. In the following example, we sourced an expected cluster size (probably from a suitable location than a hard-coded) and dynamically checked whether a majority of the nodes are present:

public class QuorumExample {
  public static void main(String[] args) throws Exception {
    QuorumConfig quorumConf = new QuorumConfig();
    quorumConf.setName("atLeastTwoNodesWithMajority");
    quorumConf.setEnabled(true);
    quorumConf.setType(QuorumType.WRITE);

    final int expectedClusterSize = 5;
    quorumConf.setQuorumFunctionImplementation(
    ...