Class ClusterNodeState
- java.lang.Object
-
- de.aristaflow.adept2.core.registry.cluster.ClusterNodeState
-
public class ClusterNodeState extends Object
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 correspondingClusterNode. Both classes interact closely with respect to field access and locking.
-
-
Field Summary
Fields Modifier and Type Field Description protected AbortServiceExceptionaseBlockerAnAbortServiceExceptionthat occurred and blocks the cluster node from continuing.protected StringclusterNameThe cluster name of the node.protected LockcontrolLockThe lock required to control the cluster node.protected ConditioncontrolSignalThe condition for the node control to wait for external signals, e.protected Set<Thread>currentStatusChangeWaitersThe threads that awaitstatusChangewhich has been signalled.protected ErrorerrBlockerAnErrorthat occurred and blocks the cluster node from continuing.protected booleanisServerWhether the cluster node is a server node.protected longlastStatusUpdateThe time the status has been updated the last time.protected StringnameThe name of the cluster node.protected Set<Thread>nextStatusChangeWaitersThe threads that awaitstatusChangeand have arrived after its last signalling.protected ThreadnodeControlThe thread controlling the cluster node, that is it handles the complete node lifecycle including restarting and thus changing roles.protected booleanrestartingWhether the control thread has accepted a restarting request and is currently restarting.protected booleanrestartRequestedWhether a restart has been requested from the outside or becomes necessary due to internal problems.protected longrunningSinceThe time since the cluster node is running (value stems from the database).protected booleanshutdownWhether a shutdown has been requested from the outside or becomes necessary due to internal problems.protected StatusstatusThe current status of the cluster node.protected ConditionstatusChangeThe condition of the control lock for threads that wait for a specific status,awaitStatus(long, Status...).protected ConditionstatusChangeWaitersLeftThe condition of the control lock to let node control wait for all threads currently waiting forstatusChange.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Triple<Status,Long,Long>awaitStatus(long timeout, Status... statuses)Waits until the cluster node reaches one of the designated statuses or until the designated timeout elapsed.StringgetClusterName()Gets the name of the cluster of this node if available.StringgetClusterNodeName()Gets the complete name of this cluster node, that is the name of the cluster (if available) and the node name.protected StringgetLogName()Gets the name of the cluster together with whether it is a server or client cluster node.StringgetName()Gets the name of the cluster node.Triple<Status,Long,Long>getStatus()Gets the current status of the cluster node without waiting.
-
-
-
Field Detail
-
name
protected final String name
The name of the cluster node. If none is provided via the configuration, a random default value is chosen automatically.
-
clusterName
protected String clusterName
The cluster name of the node. This is only be available while a cluster platform exists.
-
isServer
protected volatile boolean isServer
Whether the cluster node is a server node.
-
shutdown
protected volatile boolean shutdown
Whether a shutdown has been requested from the outside or becomes necessary due to internal problems.
-
restartRequested
protected volatile boolean restartRequested
Whether a restart has been requested from the outside or becomes necessary due to internal problems.
-
restarting
protected volatile boolean restarting
Whether the control thread has accepted a restarting request and is currently restarting. While restarting further restart requests have to be ignored.
-
status
protected volatile Status 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 lastStatusUpdate
The 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 runningSince
The time since the cluster node is running (value stems from the database).
-
aseBlocker
protected AbortServiceException aseBlocker
AnAbortServiceExceptionthat occurred and blocks the cluster node from continuing.
-
errBlocker
protected Error errBlocker
AnErrorthat occurred and blocks the cluster node from continuing.
-
nodeControl
protected final Thread 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
protected final Lock controlLock
The lock required to control the cluster node. This includes control operations like starting, terminating and restarting but also status changes.
-
controlSignal
protected final Condition controlSignal
The condition for the node control to wait for external signals, e. g.restart(long).
-
statusChange
protected final Condition statusChange
The condition of the control lock for threads that wait for a specific status,awaitStatus(long, Status...).
-
nextStatusChangeWaiters
protected volatile Set<Thread> nextStatusChangeWaiters
The threads that awaitstatusChangeand have arrived after its last signalling.
-
currentStatusChangeWaiters
protected volatile Set<Thread> 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
protected final Condition 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 Detail
-
getName
public String 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
public String 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
public String 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
protected String 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
public Triple<Status,Long,Long> getStatus() throws AbortServiceException
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,Long> awaitStatus(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.
-
-