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 AbortServiceException
aseBlocker
AnAbortServiceException
that occurred and blocks the cluster node from continuing.protected String
clusterName
The cluster name of the node.protected Lock
controlLock
The lock required to control the cluster node.protected Condition
controlSignal
The condition for the node control to wait for external signals, e. g.protected Set<Thread>
currentStatusChangeWaiters
The threads that awaitstatusChange
which has been signalled.protected Error
errBlocker
AnError
that occurred and blocks the cluster node from continuing.protected boolean
isServer
Whether the cluster node is a server node.protected long
lastStatusUpdate
The time the status has been updated the last time.protected String
name
The name of the cluster node.protected Set<Thread>
nextStatusChangeWaiters
The threads that awaitstatusChange
and have arrived after its last signalling.protected Thread
nodeControl
The thread controlling the cluster node, that is it handles the complete node lifecycle including restarting and thus changing roles.protected boolean
restarting
Whether the control thread has accepted a restarting request and is currently restarting.protected boolean
restartRequested
Whether a restart has been requested from the outside or becomes necessary due to internal problems.protected long
runningSince
The time since the cluster node is running (value stems from the database).protected boolean
shutdown
Whether a shutdown has been requested from the outside or becomes necessary due to internal problems.protected Status
status
The current status of the cluster node.protected Condition
statusChange
The condition of the control lock for threads that wait for a specific status,awaitStatus(long, Status...)
.protected Condition
statusChangeWaitersLeft
The 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.String
getClusterName()
Gets the name of the cluster of this node if available.String
getClusterNodeName()
Gets the complete name of this cluster node, that is the name of the cluster (if available) and the node name.protected String
getLogName()
Gets the name of the cluster together with whether it is a server or client cluster node.String
getName()
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
AnAbortServiceException
that occurred and blocks the cluster node from continuing.
-
errBlocker
protected Error errBlocker
AnError
that 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 awaitstatusChange
and have arrived after its last signalling.
-
currentStatusChangeWaiters
protected volatile Set<Thread> currentStatusChangeWaiters
The threads that awaitstatusChange
which has been signalled. This threads have to leave (if their condition is right). This prevents threads waiting forstatusChange
to 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 ascurrentStatusChangeWaiters
is 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.null
if there is currently no platform.- Returns:
- The name of the cluster of this node or
null
if 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, anAbortServiceException
will 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 ornull
in case the timeout elapsed before one of these statuses has been reached.
If the node control is not running any more,Status.TERMINATED
will 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, anInterruptedException
will be thrown.AbortServiceException
- If there are non-recoverable problems with the cluster especially when bootstrapping, anAbortServiceException
will be thrown.
-
-