Package io.vertx.spi.cluster.hazelcast
Class HazelcastClusterManager
- java.lang.Object
-
- io.vertx.spi.cluster.hazelcast.HazelcastClusterManager
-
- All Implemented Interfaces:
MembershipListener,LifecycleListener,ClusteredNode,ClusterManager,VertxServiceProvider,EventListener
public class HazelcastClusterManager extends Object implements ClusterManager, MembershipListener, LifecycleListener
A cluster manager that uses Hazelcast- Author:
- Tim Fox
-
-
Constructor Summary
Constructors Constructor Description HazelcastClusterManager()Constructor - gets config from classpathHazelcastClusterManager(Config conf)Constructor - config suppliedHazelcastClusterManager(HazelcastInstance instance)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRegistration(String address, RegistrationInfo registrationInfo, Completable<Void> promise)Share a new messaging handler registration with other nodes in the cluster.StringclusterHost()If the cluster manager has its own server for data/membership, this returns the host it is listening to.StringclusterPublicHost()If the cluster manager has its own server for data/membership, this returns the host it advertises to other nodes.<K,V>
voidgetAsyncMap(String name, Completable<AsyncMap<K,V>> promise)Return anAsyncMapfor the givenname.ConfiggetConfig()Get the Hazelcast config.voidgetCounter(String name, Completable<Counter> promise)Return aCounterfor the givenname.HazelcastInstancegetHazelcastInstance()voidgetLockWithTimeout(String name, long timeout, Completable<Lock> promise)StringgetNodeId()Return the unique node identifier for this node.NodeInfogetNodeInfo()Get details about this clustered node.voidgetNodeInfo(String nodeId, Completable<NodeInfo> promise)Get details about a specific node in the cluster.List<String>getNodes()Return a list of node identifiers corresponding to the nodes in the cluster.voidgetRegistrations(String address, Completable<List<RegistrationInfo>> promise)Get the messaging handler currently registered in the cluster.<K,V>
Map<K,V>getSyncMap(String name)Return a synchronous map for the givenname.voidinit(Vertx vertx)Invoked before this cluster node tries to join the cluster.booleanisActive()Is the cluster manager active?voidjoin(Completable<Void> promise)Join the cluster.voidleave(Completable<Void> promise)Leave the cluster.ConfigloadConfig()Load Hazelcast config XML and transform it into aConfigobject.voidmemberAdded(MembershipEvent membershipEvent)voidmemberRemoved(MembershipEvent membershipEvent)voidnodeListener(NodeListener listener)Set a listener that will be called when a node joins or leaves the cluster.voidregistrationListener(RegistrationListener listener)Implementations must signal the providedregistrationListenerwhen messaging handler registrations are added or removed by sending aRegistrationUpdateEventwithRegistrationListener.registrationsUpdated(RegistrationUpdateEvent).voidremoveRegistration(String address, RegistrationInfo registrationInfo, Completable<Void> promise)Signal removal of a messaging handler registration to other nodes in the cluster.voidsetConfig(Config config)Set the Hazelcast config.voidsetNodeInfo(NodeInfo nodeInfo, Completable<Void> promise)Store the details about this clustered node.voidstateChanged(LifecycleEvent lifecycleEvent)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.vertx.core.spi.cluster.ClusterManager
init
-
-
-
-
Constructor Detail
-
HazelcastClusterManager
public HazelcastClusterManager()
Constructor - gets config from classpath
-
HazelcastClusterManager
public HazelcastClusterManager(Config conf)
Constructor - config supplied- Parameters:
conf- Hazelcast config, not null
-
HazelcastClusterManager
public HazelcastClusterManager(HazelcastInstance instance)
-
-
Method Detail
-
init
public void init(Vertx vertx)
Description copied from interface:ClusterManagerInvoked before this cluster node tries to join the cluster.- Specified by:
initin interfaceClusterManager- Parameters:
vertx- the Vert.x instance
-
join
public void join(Completable<Void> promise)
Description copied from interface:ClusterManagerJoin the cluster.- Specified by:
joinin interfaceClusterManager
-
getNodeId
public String getNodeId()
Description copied from interface:ClusteredNodeReturn the unique node identifier for this node.- Specified by:
getNodeIdin interfaceClusteredNode
-
getNodes
public List<String> getNodes()
Description copied from interface:ClusteredNodeReturn a list of node identifiers corresponding to the nodes in the cluster.- Specified by:
getNodesin interfaceClusteredNode
-
registrationListener
public void registrationListener(RegistrationListener listener)
Description copied from interface:ClusterManagerImplementations must signal the providedregistrationListenerwhen messaging handler registrations are added or removed by sending aRegistrationUpdateEventwithRegistrationListener.registrationsUpdated(RegistrationUpdateEvent).- Specified by:
registrationListenerin interfaceClusterManager- Parameters:
listener- the registration listener
-
nodeListener
public void nodeListener(NodeListener listener)
Description copied from interface:ClusterManagerSet a listener that will be called when a node joins or leaves the cluster.- Specified by:
nodeListenerin interfaceClusterManager
-
setNodeInfo
public void setNodeInfo(NodeInfo nodeInfo, Completable<Void> promise)
Description copied from interface:ClusterManagerStore the details about this clustered node.- Specified by:
setNodeInfoin interfaceClusterManager
-
getNodeInfo
public NodeInfo getNodeInfo()
Description copied from interface:ClusteredNodeGet details about this clustered node.- Specified by:
getNodeInfoin interfaceClusteredNode
-
getNodeInfo
public void getNodeInfo(String nodeId, Completable<NodeInfo> promise)
Description copied from interface:ClusteredNodeGet details about a specific node in the cluster.- Specified by:
getNodeInfoin interfaceClusteredNode- Parameters:
nodeId- the clustered node id
-
getAsyncMap
public <K,V> void getAsyncMap(String name, Completable<AsyncMap<K,V>> promise)
Description copied from interface:ClusterManagerReturn anAsyncMapfor the givenname.- Specified by:
getAsyncMapin interfaceClusterManager
-
getSyncMap
public <K,V> Map<K,V> getSyncMap(String name)
Description copied from interface:ClusterManagerReturn a synchronous map for the givenname.- Specified by:
getSyncMapin interfaceClusterManager
-
getLockWithTimeout
public void getLockWithTimeout(String name, long timeout, Completable<Lock> promise)
Description copied from interface:ClusterManager- Specified by:
getLockWithTimeoutin interfaceClusterManager
-
getCounter
public void getCounter(String name, Completable<Counter> promise)
Description copied from interface:ClusterManagerReturn aCounterfor the givenname.- Specified by:
getCounterin interfaceClusterManager
-
leave
public void leave(Completable<Void> promise)
Description copied from interface:ClusterManagerLeave the cluster.- Specified by:
leavein interfaceClusterManager
-
memberAdded
public void memberAdded(MembershipEvent membershipEvent)
- Specified by:
memberAddedin interfaceMembershipListener
-
memberRemoved
public void memberRemoved(MembershipEvent membershipEvent)
- Specified by:
memberRemovedin interfaceMembershipListener
-
stateChanged
public void stateChanged(LifecycleEvent lifecycleEvent)
- Specified by:
stateChangedin interfaceLifecycleListener
-
isActive
public boolean isActive()
Description copied from interface:ClusterManagerIs the cluster manager active?- Specified by:
isActivein interfaceClusterManager- Returns:
- true if active, false otherwise
-
addRegistration
public void addRegistration(String address, RegistrationInfo registrationInfo, Completable<Void> promise)
Description copied from interface:ClusterManagerShare a new messaging handler registration with other nodes in the cluster.- Specified by:
addRegistrationin interfaceClusterManager
-
removeRegistration
public void removeRegistration(String address, RegistrationInfo registrationInfo, Completable<Void> promise)
Description copied from interface:ClusterManagerSignal removal of a messaging handler registration to other nodes in the cluster.- Specified by:
removeRegistrationin interfaceClusterManager
-
getRegistrations
public void getRegistrations(String address, Completable<List<RegistrationInfo>> promise)
Description copied from interface:ClusteredNodeGet the messaging handler currently registered in the cluster.- Specified by:
getRegistrationsin interfaceClusteredNode
-
clusterHost
public String clusterHost()
Description copied from interface:ClusterManagerIf the cluster manager has its own server for data/membership, this returns the host it is listening to. When users don't configure the eventbus cluster host, the value will serve as a default.- Specified by:
clusterHostin interfaceClusterManager- Returns:
- null if the cluster manager does not start a server or the host couldn't be determined
-
clusterPublicHost
public String clusterPublicHost()
Description copied from interface:ClusterManagerIf the cluster manager has its own server for data/membership, this returns the host it advertises to other nodes. When users don't configure the eventbus cluster public host, the value will serve as a default.- Specified by:
clusterPublicHostin interfaceClusterManager- Returns:
- null if the cluster manager does not advertise a host that is different from the cluster host or the public host couldn't be determined
-
getConfig
public Config getConfig()
Get the Hazelcast config.- Returns:
- a config object
-
setConfig
public void setConfig(Config config)
Set the Hazelcast config.- Parameters:
config- a config object
-
loadConfig
public Config loadConfig()
Load Hazelcast config XML and transform it into aConfigobject. The content is read from:- the location denoted by the
vertx.hazelcast.configsysprop, if present, or - the
cluster.xmlfile on the classpath, if present, or - the default config file
The cluster manager uses this method to load the config when the node joins the cluster, if no config was provided upon creation.
You may use this method to get a base config and customize it before the node joins the cluster. In this case, don't forget to invoke
setConfig(Config)after you applied your changes.- Returns:
- a config object
- the location denoted by the
-
getHazelcastInstance
public HazelcastInstance getHazelcastInstance()
-
-