Interface BambooClusterNodeHeartbeatService

  • All Known Implementing Classes:
    BambooClusterNodeHeartbeatServiceImpl

    @Internal
    public interface BambooClusterNodeHeartbeatService
    Provides a heartbeat for nodes of a cluster and utility methods for finding out about the "liveness" of other nodes.
    • Method Detail

      • getNodeId

        @NotNull
        @NotNull String getNodeId()
        Returns the node ID for this node.
        Returns:
        the node ID for this node.
      • isNodeLive

        boolean isNodeLive​(@NotNull
                           @NotNull String nodeId)
        Checks whether the given cluster node is considered "live".

        Each live node will be writing a heartbeat on a set schedule (eg once a minute). A node is considered live if it has written a heartbeat within a reasonable tolerance level (eg 5 minutes).

        The tolerance level needs to be large enough to avoid certain expected slow-downs in the system including GC pauses, or just general slowness in the JVM / scheduler / network / database of the remote node.

        This method is database sensitive and will return false if the database operations could not be performed.

        Parameters:
        nodeId - the cluster node to check
        Returns:
        true iff the given cluster node is still "live".
      • isNodeLive

        boolean isNodeLive()
        Checks whether the current cluster node is considered "live".

        Each live node will be writing a heartbeat on a set schedule (eg once a minute). A node is considered live if it has written a heartbeat within a reasonable tolerance level (eg 5 minutes).

        The tolerance level needs to be large enough to avoid certain expected slow-downs in the system including GC pauses, or just general slowness in the JVM / scheduler / network / database of the remote node.

        This method is NOT database sensitive and the returned value will be evaluated properly, even without a database connection.

        Returns:
        true iff the given cluster node is still "live".
        Since:
        9.4.0
      • getLastHeartbeatTime

        @Nullable
        @Nullable Long getLastHeartbeatTime​(@NotNull
                                            @NotNull String nodeId)
        Returns the last time a heartbeat was sent by the given node.

        A null value indicates no heartbeats have ever been sent by the given node.

        Parameters:
        nodeId - the node
        Returns:
        the last time a heartbeat was sent by the given node.
      • findLiveNodes

        @NotNull
        @NotNull Collection<String> findLiveNodes()
        Returns all nodes IDs that have sent a heartbeat within the default threshold time.
        Returns:
        all nodes IDs that have sent a heartbeat within the default threshold time.
      • findLiveNodes

        @Deprecated
        @NotNull
        @NotNull Collection<String> findLiveNodes​(long thresholdInMillis)
        Deprecated.
        since 9.4.0 use findLiveNodes() instead
        Returns all nodes that have sent a heartbeat within the given threshold.
        Parameters:
        thresholdInMillis - the threshold in milliseconds
        Returns:
        all nodes IDs that have sent a heartbeat within the given threshold.
      • findLiveNodesStatuses

        @NotNull
        @NotNull Collection<BambooNodeStatus> findLiveNodesStatuses()
        Returns all nodes objects that have sent a heartbeat within the default threshold time. The returned nodes are buffered and may not be up to date. Use refreshLiveNodes() to perform an update.
        Returns:
        collection of nodes
        Since:
        9.4.0
      • startNodeHeartbeat

        void startNodeHeartbeat()
                         throws Exception
        Starts registering heartbeats for the current node. The first heartbeat is synchronous and will be performed before this method returns. In case of initial heartbeat failure, the method will kill the current node.
        Throws:
        Exception
      • isNodeHeartbeatStarted

        boolean isNodeHeartbeatStarted()
        Returns:
        true if node heartbeat has been started for the current node
      • isCurrentNodePrimaryBuffered

        boolean isCurrentNodePrimaryBuffered()
        Returns:
        true if current node has been recently (i.e. within timeout) successfully marked as alive.
      • setCurrentNodePrimary

        void setCurrentNodePrimary​(boolean primary)
        Set current node's primary flag. Executed when the current node loses primary lock.
      • renouncePrimaryRole

        void renouncePrimaryRole​(boolean panicMode)
        Renounce primary role.
        Parameters:
        panicMode - indicates that this node is (supposedly) the primary but encountered irrecoverable error.
        Since:
        9.5
      • getNodeStatuses

        @NotNull
        @NotNull List<BambooNodeStatus> getNodeStatuses()
        Get status of all nodes if DC license applied otherwise empty list.
        Since:
        8.0.2
      • getAllNodesInfo

        @NotNull
        @NotNull io.atlassian.fugue.Either<Exception,​List<BambooNodeInfo>> getAllNodesInfo()
        Get info of all nodes (dead and alive).
        Returns:
        either list of nodes info or exception if something went wrong
        Since:
        9.5
      • refreshLiveNodes

        void refreshLiveNodes()
        Refreshes the list of live nodes. Takes the information from the heartbeat table and give accurate information of which nodes are alive.
        Since:
        9.4
      • performHeartbeatAction

        boolean performHeartbeatAction()
        Performs the heartbeat action for the current node and refreshes live nodes.
        Returns:
        true if the action was successful, false otherwise
        Since:
        9.5
      • shutdown

        void shutdown()
        Stop the heartbeat scheduler service.
        Since:
        9.1
      • removeNode

        void removeNode​(@NotNull
                        @NotNull String nodeId)
        Remove node by the given id.
        Since:
        9.5.0
      • getLiveNodeCount

        int getLiveNodeCount()
        Gets a number of live nodes in the cluster.
        Returns:
        number of live nodes
        Since:
        9.5.0