public interface Cluster
DistributedTree
that's
implemented either on top of JGroups or Apache ZooKeeper.Modifier and Type | Method and Description |
---|---|
void |
addLifecycleListener(LifecycleListener listener)
Adds a listener for lifecycle events.
|
void |
addMasterNodePropertyListener(String property,
NodePropertyListener listener)
Adds a listener that will be notified when a node property has changed on one of the master nodes.
|
void |
addNodeChangeListener(NodeChangeListener listener)
Adds a listener for events relating nodes joining and leaving the cluster.
|
void |
addNodeProperty(String property,
boolean requiredForPeer,
boolean requiredForServer,
ReaderWriter<?> readerWriter)
Adds a new node property that will be visible on the cluster.
|
void |
addSlaveConfigurationListener(SlaveConfigurationListener listener)
Adds a listener for events relating to this master-slaves node group configuration.
|
void |
addSlaveNodePropertyListener(String property,
NodePropertyListener listener)
Adds a listener that will be notified when a node property has changed on one of this node's slaves.
|
DistributedTree |
getDistributedTree()
Returns the
DistributedTree used by the cluster. |
NodeInfo |
getMaster(short node)
Returns a given node-group master if this node is a slave.
|
Collection<NodeInfo> |
getMasters()
Returns all the current, online master nodes.
|
NodeInfo |
getMyMaster()
Returns this node's master node if this is a slave.
|
short |
getMyNodeId()
Returns this cluster node's ID.
|
NodeInfo |
getMyNodeInfo()
Returns this cluster node's info.
|
List<NodeInfo> |
getMySlaves()
Returns this node's master node if this is a slave.
|
NodeInfo |
getNodeInfoByName(String nodeName)
Returns a
NodeInfo for any cluster node, identified by its (unique) name. |
Set<Short> |
getNodes()
Returns the IDs of all online nodes (each master and slaves group of nodes is listed once - remember: masters and slaves share the same ID).
|
Set<NodeInfo> |
getNodesByProperty(String propertyName,
Object value)
Returns a set of
NodeInfo for any cluster node, with a property equal to the given value. |
Object |
getUnderlyingResource()
Returns the main resource used by the cluster for coordination, namely a
org.jgroups.JChannel for a JGroups-based cluster or
a com.netflix.curator.framework.CuratorFramework for a ZooKeeper-based cluster. |
void |
goOffline()
Leave the cluster and shutdown the JVM.
|
boolean |
hasServer()
Returns true if the grid is configured to use a server.
|
boolean |
isMaster()
Returns
true if this node is a master; false if it's a slave. |
boolean |
isMaster(NodeInfo node)
Returns
true if the given node is a master; false if it's a slave. |
boolean |
isOnline()
Returns
true if this node is online (operational and visible to other nodes). |
void |
removeLifecycleListener(LifecycleListener listener)
Removes a
LifecycleListener . |
void |
removeMasterNodePropertyListener(String property,
NodePropertyListener listener)
Removes a
NodePropertyListener listening on master nodes. |
void |
removeNodeChangeListener(NodeChangeListener listener)
Removes a
NodeChangeListener . |
void |
removeSlaveConfigurationListener(SlaveConfigurationListener listener)
Removes a
SlaveConfigurationListener . |
void |
removeSlaveNodePropertyListener(String property,
NodePropertyListener listener)
Removes a
NodePropertyListener listening on this node's slaves. |
void |
setNodeProperty(String property,
Object value)
Sets a
property for this node. |
short getMyNodeId()
NodeInfo getMyNodeInfo()
NodeInfo.getName()
) is unique in the cluster.NodeInfo getNodeInfoByName(String nodeName)
NodeInfo
for any cluster node, identified by its (unique) name.nodeName
- The node's (unique) name.Set<NodeInfo> getNodesByProperty(String propertyName, Object value)
NodeInfo
for any cluster node, with a property equal to the given value.propertyName
- The property we want to compare to the given value.value
- The requested value of the property.boolean hasServer()
true
if the grid is configured to use a server; false
otherwise.boolean isOnline()
true
if this node is online (operational and visible to other nodes).true
if this node is online and false
otherwise.boolean isMaster()
true
if this node is a master; false
if it's a slave.true
if this node is a master; false
if it's a slave.Set<Short> getNodes()
Collection<NodeInfo> getMasters()
NodeInfo getMyMaster()
null
otherwise.List<NodeInfo> getMySlaves()
null
otherwise.NodeInfo getMaster(short node)
node
- The node ID of the mater-slaves group (remember: masters and slaves share the same ID) the master of which we want.boolean isMaster(NodeInfo node)
true
if the given node is a master; false
if it's a slave.node
- true
if the given node is a master; false
if it's a slave.DistributedTree getDistributedTree()
DistributedTree
used by the cluster. You may use the tree for your own purposes. The cluster protects any internal Galaxy data in the tree from accidental deletion or
modification.DistributedTree
used by the cluster.void addLifecycleListener(LifecycleListener listener)
listener
- The listenervoid removeLifecycleListener(LifecycleListener listener)
LifecycleListener
.listener
- The listener.void addSlaveConfigurationListener(SlaveConfigurationListener listener)
listener
- The listener.void removeSlaveConfigurationListener(SlaveConfigurationListener listener)
SlaveConfigurationListener
.listener
- The listener.void addNodeChangeListener(NodeChangeListener listener)
listener
- The listener.void removeNodeChangeListener(NodeChangeListener listener)
NodeChangeListener
.listener
- The listener.void addMasterNodePropertyListener(String property, NodePropertyListener listener)
property
- The property on whose changes we want to listen.listener
- The listener.void removeMasterNodePropertyListener(String property, NodePropertyListener listener)
NodePropertyListener
listening on master nodes.property
- The property on the listener is listening on.listener
- void addSlaveNodePropertyListener(String property, NodePropertyListener listener)
property
- The property on whose changes we want to listen.listener
- The listener.void removeSlaveNodePropertyListener(String property, NodePropertyListener listener)
NodePropertyListener
listening on this node's slaves.property
- The property on the listener is listening on.listener
- void addNodeProperty(String property, boolean requiredForPeer, boolean requiredForServer, ReaderWriter<?> readerWriter)
If required
is true, tells the cluster that each node must have the given property set to a non-null value in order to
be online. This would not normally be done by a user process, as it would require that his method be called during the Spring container initialization, i.e. in a Component
's init()
or postInit()
.
property
- The property's name.requiredForPeer
- Whether a non-null value for this property is required for the a peer to be online. For properties added by user processes, this should be false
.requiredForServer
- Whether a non-null value for this property is required for a server node to be online. For properties added by user processes, this should be false
.readerWriter
- A ReaderWriter
instance to read and write this property to and from the distributed tree.void setNodeProperty(String property, Object value)
property
for this node.property
- The property name being set.value
- The new property value.Object getUnderlyingResource()
org.jgroups.JChannel
for a JGroups-based cluster or
a com.netflix.curator.framework.CuratorFramework
for a ZooKeeper-based cluster.org.jgroups.JChannel
or org.apache.zookeeper.ZooKeeper
.void goOffline()
LifecycleListener.offline()
. This action cannot be reversed - the JVM must be restarted for the node to
come back online.