Class ClusterNodeState
java.lang.Object
de.aristaflow.adept2.core.registry.cluster.ClusterNodeState
This class encapsulates the state of a cluster node in memory. It also provides control data like
restarting or shutting down. Package-scoped methods are only called from the corresponding
ClusterNode. Both classes interact closely with respect to field access and locking.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbortServiceExceptionAnAbortServiceExceptionthat occurred and blocks the cluster node from continuing.protected StringThe cluster name of the node.protected final LockThe lock required to control the cluster node.protected final ConditionThe condition for the node control to wait for external signals, e.The threads that awaitstatusChangewhich has been signalled.protected ErrorAnErrorthat occurred and blocks the cluster node from continuing.protected booleanWhether the cluster node is a server node.protected longThe time the status has been updated the last time.protected final StringThe name of the cluster node.The threads that awaitstatusChangeand have arrived after its last signalling.protected final ThreadThe thread controlling the cluster node, that is it handles the complete node lifecycle including restarting and thus changing roles.protected booleanWhether the control thread has accepted a restarting request and is currently restarting.protected booleanWhether a restart has been requested from the outside or becomes necessary due to internal problems.protected longThe time since the cluster node is running (value stems from the database).protected booleanWhether a shutdown has been requested from the outside or becomes necessary due to internal problems.protected StatusThe current status of the cluster node.protected final ConditionThe condition of the control lock for threads that wait for a specific status,awaitStatus(long, Status...).protected final ConditionThe condition of the control lock to let node control wait for all threads currently waiting forstatusChange. -
Method Summary
Modifier and TypeMethodDescriptionawaitStatus(long timeout, Status... statuses) Waits until the cluster node reaches one of the designated statuses or until the designated timeout elapsed.Gets the name of the cluster of this node if available.Gets the complete name of this cluster node, that is the name of the cluster (if available) and the node name.protected StringGets the name of the cluster together with whether it is a server or client cluster node.getName()Gets the name of the cluster node.Gets the current status of the cluster node without waiting.
-
Field Details
-
name
The name of the cluster node. If none is provided via the configuration, a random default value is chosen automatically. -
clusterName
The cluster name of the node. This is only be available while a cluster platform exists. -
isServer
protected volatile boolean isServerWhether the cluster node is a server node. -
shutdown
protected volatile boolean shutdownWhether a shutdown has been requested from the outside or becomes necessary due to internal problems. -
restartRequested
protected volatile boolean restartRequestedWhether a restart has been requested from the outside or becomes necessary due to internal problems. -
restarting
protected volatile boolean restartingWhether the control thread has accepted a restarting request and is currently restarting. While restarting further restart requests have to be ignored. -
status
The current status of the cluster node. This corresponds to the value in the corresponding table – usually a bit delayed. -
lastStatusUpdate
protected volatile long lastStatusUpdateThe time the status has been updated the last time. Asynchronous requests needs this to detect whether the node control has responded to the request. -
runningSince
protected volatile long runningSinceThe time since the cluster node is running (value stems from the database). -
aseBlocker
AnAbortServiceExceptionthat occurred and blocks the cluster node from continuing. -
errBlocker
AnErrorthat occurred and blocks the cluster node from continuing. -
nodeControl
The thread controlling the cluster node, that is it handles the complete node lifecycle including restarting and thus changing roles. When changing the node state the name of this thread will be adapted appropriately to reflect the current status. -
controlLock
The lock required to control the cluster node. This includes control operations like starting, terminating and restarting but also status changes. -
controlSignal
The condition for the node control to wait for external signals, e. g.restart(long). -
statusChange
The condition of the control lock for threads that wait for a specific status,awaitStatus(long, Status...). -
nextStatusChangeWaiters
The threads that awaitstatusChangeand have arrived after its last signalling. -
currentStatusChangeWaiters
The threads that awaitstatusChangewhich has been signalled. This threads have to leave (if their condition is right). This prevents threads waiting forstatusChangeto miss signals. -
statusChangeWaitersLeft
The condition of the control lock to let node control wait for all threads currently waiting forstatusChange. This is signalled as soon ascurrentStatusChangeWaitersis empty.
-
-
Method Details
-
getName
Gets the name of the cluster node. This is independent from the status and created once for the complete lifetime of aClusterNode.- Returns:
- The name of the cluster node.
-
getClusterName
Gets the name of the cluster of this node if available.nullif there is currently no platform.- Returns:
- The name of the cluster of this node or
nullif there is no current platform.
-
getClusterNodeName
Gets the complete name of this cluster node, that is the name of the cluster (if available) and the node name.- Returns:
- The complete name of this cluster node, that is the name of the cluster (if available) and the node name.
-
getLogName
Gets the name of the cluster together with whether it is a server or client cluster node. Use this in log messages.- Returns:
- The name of the cluster together with whether it is a server or client cluster node for usage in log messages.
-
getStatus
Gets the current status of the cluster node without waiting.- Returns:
- The current status of this cluster node, the time of the last status update and the time since when this node is running.
- Throws:
AbortServiceException- If there are non-recoverable problems with the cluster especially when bootstrapping, anAbortServiceExceptionwill be thrown. This exception indicates that the status isStatus.TERMINATED.
-
awaitStatus
public Triple<Status,Long, awaitStatusLong> (long timeout, Status... statuses) throws InterruptedException, AbortServiceException Waits until the cluster node reaches one of the designated statuses or until the designated timeout elapsed. The reached status will be returned ornullin case the timeout elapsed before one of these statuses has been reached.
If the node control is not running any more,Status.TERMINATEDwill remain the status and no waiting will take place.- Parameters:
timeout- The time in milliseconds to wait for the cluster node to reach one of the designated statuses. Use 0 to not wait at all or a negative value to wait without time limit. The time required for the lock will count to this timeout.statuses- The statuses which should be reached by this cluster node.- Returns:
- The current status of the cluster node if it is one of the awaited statuses,
null(as first element of the triple) otherwise. Additionally, the triple will always contain the time of the last status update and the time since when this node is running. - Throws:
InterruptedException- If the current thread is interrupted while waiting for one of the designated statuses, anInterruptedExceptionwill be thrown.AbortServiceException- If there are non-recoverable problems with the cluster especially when bootstrapping, anAbortServiceExceptionwill be thrown.
-