Search in sources :

Example 1 with NodeListener

use of io.vertx.core.spi.cluster.NodeListener in project vert.x by eclipse.

the class HAManager method init.

/**
 * Initialize the ha manager, i.e register the node listener to propagates the node events and
 * start the quorum timer. The quorum will be checked as well.
 */
void init() {
    synchronized (haInfo) {
        clusterMap.put(nodeID, haInfo.encode());
    }
    clusterManager.nodeListener(new NodeListener() {

        @Override
        public void nodeAdded(String nodeID) {
            HAManager.this.nodeAdded(nodeID);
        }

        @Override
        public void nodeLeft(String leftNodeID) {
            HAManager.this.nodeLeft(leftNodeID);
        }
    });
    quorumTimerID = vertx.setPeriodic(QUORUM_CHECK_PERIOD, tid -> checkHADeployments());
    // Call check quorum to compute whether we have an initial quorum
    synchronized (this) {
        checkQuorum();
    }
}
Also used : Logger(io.vertx.core.impl.logging.Logger) java.util(java.util) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) io.vertx.core(io.vertx.core) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) NodeListener(io.vertx.core.spi.cluster.NodeListener) MINUTES(java.util.concurrent.TimeUnit.MINUTES) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) JsonObject(io.vertx.core.json.JsonObject) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) NodeListener(io.vertx.core.spi.cluster.NodeListener)

Example 2 with NodeListener

use of io.vertx.core.spi.cluster.NodeListener in project vert.x by eclipse.

the class VertxStartFailureTest method testHAManagerInitFailure.

@Test
public void testHAManagerInitFailure() throws Exception {
    RuntimeException expected = new RuntimeException();
    FakeClusterManager clusterManager = new FakeClusterManager() {

        @Override
        public void nodeListener(NodeListener listener) {
            // Triggers HAManager init failure
            throw expected;
        }
    };
    VertxOptions options = new VertxOptions().setClusterManager(clusterManager).setHAEnabled(true);
    Throwable failure = failStart(options);
    assertSame(expected, failure);
}
Also used : NodeListener(io.vertx.core.spi.cluster.NodeListener) FakeClusterManager(io.vertx.test.fakecluster.FakeClusterManager) Test(org.junit.Test)

Aggregations

NodeListener (io.vertx.core.spi.cluster.NodeListener)2 io.vertx.core (io.vertx.core)1 Logger (io.vertx.core.impl.logging.Logger)1 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 ClusterManager (io.vertx.core.spi.cluster.ClusterManager)1 FakeClusterManager (io.vertx.test.fakecluster.FakeClusterManager)1 java.util (java.util)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 MINUTES (java.util.concurrent.TimeUnit.MINUTES)1 NANOSECONDS (java.util.concurrent.TimeUnit.NANOSECONDS)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Test (org.junit.Test)1