
io.jsync.spi.cluster.ClusterManager Maven / Gradle / Ivy
Show all versions of jsync.io Show documentation
/*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.jsync.spi.cluster;
import java.util.List;
import java.util.Map;
/**
* A cluster provider for jsync.io must implement this interface.
*
* In order for HA to work correctly, all implementations of this interface MUST be implemented such that:
*
* 1. Whenever a node joins or leaves the cluster the registered NodeListener (if any) MUST be called with the
* appropriate join or leave event.
* 2. For all nodes that are part of the cluster, the registered NodeListener MUST be called with the exact same
* sequence of join and leave events on all nodes.
* 3. For any particular join or leave event that is handled in any NodeListener, anywhere in the cluster, the List
* of nodes returned by getNodes must be identical.
* 4. All of the methods in the implementation must return immediately, i.e. they must not block while the operation
* is being executed. If the underlying implementation does block, that can be wrapped in an
* {@link io.jsync.spi.Action} instance and executed using the method
* {@link io.jsync.spi.AsyncSPI#executeBlocking(io.jsync.spi.Action, io.jsync.Handler)}
*
* @author Tim Fox
*/
public interface ClusterManager {
/**
* Return an async multi-map for the given name
*/
AsyncMultiMap getAsyncMultiMap(String name);
/**
* Return an async map for the given name
*/
AsyncMap getAsyncMap(String name);
/**
* Return a synchronous map for the given name
*/
Map getSyncMap(String name);
/**
* Return the unique node ID for this node
*/
String getNodeID();
/**
* Return a list of node IDs corresponding to the nodes in the cluster
*/
List getNodes();
/**
* Set a listener that will be called when a node joins or leaves the cluster.
*
* @param listener
*/
void nodeListener(NodeListener listener);
/**
* Join the cluster
*/
void join();
/**
* Leave the cluster
*/
void leave();
}