Package io.vertx.spi.cluster.hazelcast
Class HazelcastClusterManager
- java.lang.Object
-
- io.vertx.spi.cluster.hazelcast.HazelcastClusterManager
-
- All Implemented Interfaces:
MembershipListener
,LifecycleListener
,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 void
addRegistration(String address, RegistrationInfo registrationInfo, Promise<Void> promise)
Share a new messaging handler registration with other nodes in the cluster.String
clusterHost()
If the cluster manager has its own server for data/membership, this returns the host it is listening to.String
clusterPublicHost()
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, Promise<AsyncMap<K,V>> promise)
Return anAsyncMap
for the givenname
.Config
getConfig()
Get the Hazelcast config.void
getCounter(String name, Promise<Counter> promise)
Return aCounter
for the givenname
.HazelcastInstance
getHazelcastInstance()
void
getLockWithTimeout(String name, long timeout, Promise<Lock> promise)
String
getNodeId()
Return the unique node identifier for this node.NodeInfo
getNodeInfo()
Get details about this clustered node.void
getNodeInfo(String nodeId, Promise<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.void
getRegistrations(String address, Promise<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
.void
init(Vertx vertx)
Invoked before this cluster node tries to join the cluster.boolean
isActive()
Is the cluster manager active?void
join(Promise<Void> promise)
Join the cluster.void
leave(Promise<Void> promise)
Leave the cluster.Config
loadConfig()
Load Hazelcast config XML and transform it into aConfig
object.void
memberAdded(MembershipEvent membershipEvent)
void
memberRemoved(MembershipEvent membershipEvent)
void
nodeListener(NodeListener listener)
Set a listener that will be called when a node joins or leaves the cluster.void
registrationListener(RegistrationListener listener)
Implementations must signal the providedregistrationListener
when messaging handler registrations are added or removed by sending aRegistrationUpdateEvent
withRegistrationListener.registrationsUpdated(RegistrationUpdateEvent)
.void
removeRegistration(String address, RegistrationInfo registrationInfo, Promise<Void> promise)
Signal removal of a messaging handler registration to other nodes in the cluster.void
setConfig(Config config)
Set the Hazelcast config.void
setNodeInfo(NodeInfo nodeInfo, Promise<Void> promise)
Store the details about this clustered node.void
stateChanged(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:ClusterManager
Invoked before this cluster node tries to join the cluster.- Specified by:
init
in interfaceClusterManager
- Parameters:
vertx
- the Vert.x instance
-
join
public void join(Promise<Void> promise)
Description copied from interface:ClusterManager
Join the cluster.- Specified by:
join
in interfaceClusterManager
-
getNodeId
public String getNodeId()
Description copied from interface:ClusterManager
Return the unique node identifier for this node.- Specified by:
getNodeId
in interfaceClusterManager
-
getNodes
public List<String> getNodes()
Description copied from interface:ClusterManager
Return a list of node identifiers corresponding to the nodes in the cluster.- Specified by:
getNodes
in interfaceClusterManager
-
registrationListener
public void registrationListener(RegistrationListener listener)
Description copied from interface:ClusterManager
Implementations must signal the providedregistrationListener
when messaging handler registrations are added or removed by sending aRegistrationUpdateEvent
withRegistrationListener.registrationsUpdated(RegistrationUpdateEvent)
.- Specified by:
registrationListener
in interfaceClusterManager
- Parameters:
listener
- the registration listener
-
nodeListener
public void nodeListener(NodeListener listener)
Description copied from interface:ClusterManager
Set a listener that will be called when a node joins or leaves the cluster.- Specified by:
nodeListener
in interfaceClusterManager
-
setNodeInfo
public void setNodeInfo(NodeInfo nodeInfo, Promise<Void> promise)
Description copied from interface:ClusterManager
Store the details about this clustered node.- Specified by:
setNodeInfo
in interfaceClusterManager
-
getNodeInfo
public NodeInfo getNodeInfo()
Description copied from interface:ClusterManager
Get details about this clustered node.- Specified by:
getNodeInfo
in interfaceClusterManager
-
getNodeInfo
public void getNodeInfo(String nodeId, Promise<NodeInfo> promise)
Description copied from interface:ClusterManager
Get details about a specific node in the cluster.- Specified by:
getNodeInfo
in interfaceClusterManager
- Parameters:
nodeId
- the clustered node id
-
getAsyncMap
public <K,V> void getAsyncMap(String name, Promise<AsyncMap<K,V>> promise)
Description copied from interface:ClusterManager
Return anAsyncMap
for the givenname
.- Specified by:
getAsyncMap
in interfaceClusterManager
-
getSyncMap
public <K,V> Map<K,V> getSyncMap(String name)
Description copied from interface:ClusterManager
Return a synchronous map for the givenname
.- Specified by:
getSyncMap
in interfaceClusterManager
-
getLockWithTimeout
public void getLockWithTimeout(String name, long timeout, Promise<Lock> promise)
Description copied from interface:ClusterManager
- Specified by:
getLockWithTimeout
in interfaceClusterManager
-
getCounter
public void getCounter(String name, Promise<Counter> promise)
Description copied from interface:ClusterManager
Return aCounter
for the givenname
.- Specified by:
getCounter
in interfaceClusterManager
-
leave
public void leave(Promise<Void> promise)
Description copied from interface:ClusterManager
Leave the cluster.- Specified by:
leave
in interfaceClusterManager
-
memberAdded
public void memberAdded(MembershipEvent membershipEvent)
- Specified by:
memberAdded
in interfaceMembershipListener
-
memberRemoved
public void memberRemoved(MembershipEvent membershipEvent)
- Specified by:
memberRemoved
in interfaceMembershipListener
-
stateChanged
public void stateChanged(LifecycleEvent lifecycleEvent)
- Specified by:
stateChanged
in interfaceLifecycleListener
-
isActive
public boolean isActive()
Description copied from interface:ClusterManager
Is the cluster manager active?- Specified by:
isActive
in interfaceClusterManager
- Returns:
- true if active, false otherwise
-
addRegistration
public void addRegistration(String address, RegistrationInfo registrationInfo, Promise<Void> promise)
Description copied from interface:ClusterManager
Share a new messaging handler registration with other nodes in the cluster.- Specified by:
addRegistration
in interfaceClusterManager
-
removeRegistration
public void removeRegistration(String address, RegistrationInfo registrationInfo, Promise<Void> promise)
Description copied from interface:ClusterManager
Signal removal of a messaging handler registration to other nodes in the cluster.- Specified by:
removeRegistration
in interfaceClusterManager
-
getRegistrations
public void getRegistrations(String address, Promise<List<RegistrationInfo>> promise)
Description copied from interface:ClusterManager
Get the messaging handler currently registered in the cluster.- Specified by:
getRegistrations
in interfaceClusterManager
-
clusterHost
public String clusterHost()
Description copied from interface:ClusterManager
If 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:
clusterHost
in 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:ClusterManager
If 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:
clusterPublicHost
in 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 aConfig
object. The content is read from:- the location denoted by the
vertx.hazelcast.config
sysprop, if present, or - the
cluster.xml
file 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()
-
-