Class 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 corresponding ClusterNode. Both classes interact closely with respect to field access and locking.
    • 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
        An AbortServiceException that occurred and blocks the cluster node from continuing.
      • errBlocker

        protected Error errBlocker
        An Error 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).
      • nextStatusChangeWaiters

        protected volatile Set<Thread> nextStatusChangeWaiters
        The threads that await statusChange and have arrived after its last signalling.
      • currentStatusChangeWaiters

        protected volatile Set<Thread> currentStatusChangeWaiters
        The threads that await statusChange which has been signalled. This threads have to leave (if their condition is right). This prevents threads waiting for statusChange to miss signals.
      • statusChangeWaitersLeft

        protected final Condition statusChangeWaitersLeft
        The condition of the control lock to let node control wait for all threads currently waiting for statusChange. This is signalled as soon as currentStatusChangeWaiters 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 a ClusterNode.
        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, an AbortServiceException will be thrown. This exception indicates that the status is Status.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 or null 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, an InterruptedException will be thrown.
        AbortServiceException - If there are non-recoverable problems with the cluster especially when bootstrapping, an AbortServiceException will be thrown.