com.atlassian.beehive
Class AbstractClusterNodeHeartbeatService

java.lang.Object
  extended by com.atlassian.beehive.AbstractClusterNodeHeartbeatService
All Implemented Interfaces:
ClusterNodeHeartbeatService

public abstract class AbstractClusterNodeHeartbeatService
extends Object
implements ClusterNodeHeartbeatService

Implementation of ClusterNodeHeartbeatService.

It is up to the concrete class to ensure that startHeartbeat() is called upon product startup.

The current heartbeat is one minute which is the finest that atlassian-scheduler currently allows.


Constructor Summary
AbstractClusterNodeHeartbeatService(ClusterNodeHeartBeatDao clusterNodeHeartBeatDao, com.atlassian.scheduler.SchedulerService schedulerService)
           
 
Method Summary
 Collection<String> findLiveNodes()
          Returns all nodes that have sent a heartbeat within the default threshold time.
 Collection<String> findLiveNodes(long threshold)
          Returns all nodes that have sent a heartbeat within the given threshold.
 Long getLastHeartbeatTime(String nodeId)
          Returns the last time a heartbeat was sent by the given node.
 String getNodeId()
          Returns the node ID for this node.
 boolean isNodeLive(String nodeId)
          Checks whether the given cluster node is considered "live".
protected  void startHeartbeat()
          The concrete class must ensure that this is called upon product startup, but after the DB is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractClusterNodeHeartbeatService

public AbstractClusterNodeHeartbeatService(ClusterNodeHeartBeatDao clusterNodeHeartBeatDao,
                                           com.atlassian.scheduler.SchedulerService schedulerService)
Method Detail

startHeartbeat

protected void startHeartbeat()
                       throws com.atlassian.scheduler.SchedulerServiceException
The concrete class must ensure that this is called upon product startup, but after the DB is available.

Throws:
com.atlassian.scheduler.SchedulerServiceException - if the heartbeat job could not be scheduled. This should be considered a fatal exception.

getNodeId

@Nonnull
public String getNodeId()
Description copied from interface: ClusterNodeHeartbeatService
Returns the node ID for this node.

Specified by:
getNodeId in interface ClusterNodeHeartbeatService
Returns:
the node ID for this node.

isNodeLive

public boolean isNodeLive(@Nonnull
                          String nodeId)
Description copied from interface: ClusterNodeHeartbeatService
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.

Specified by:
isNodeLive in interface ClusterNodeHeartbeatService
Parameters:
nodeId - the cluster node to check
Returns:
true iff the given cluster node is still "live".

getLastHeartbeatTime

public Long getLastHeartbeatTime(@Nonnull
                                 String nodeId)
Description copied from interface: ClusterNodeHeartbeatService
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.

Specified by:
getLastHeartbeatTime in interface ClusterNodeHeartbeatService
Parameters:
nodeId - the node
Returns:
the last time a heartbeat was sent by the given node.

findLiveNodes

@Nonnull
public Collection<String> findLiveNodes()
Description copied from interface: ClusterNodeHeartbeatService
Returns all nodes that have sent a heartbeat within the default threshold time.

Specified by:
findLiveNodes in interface ClusterNodeHeartbeatService
Returns:
all nodes that have sent a heartbeat within the default threshold time.
See Also:
ClusterNodeHeartbeatService.findLiveNodes(long)

findLiveNodes

@Nonnull
public Collection<String> findLiveNodes(long threshold)
Description copied from interface: ClusterNodeHeartbeatService
Returns all nodes that have sent a heartbeat within the given threshold.

Specified by:
findLiveNodes in interface ClusterNodeHeartbeatService
Parameters:
threshold - the threshold in milliseconds
Returns:
all nodes that have sent a heartbeat within the given threshold.
See Also:
ClusterNodeHeartbeatService.findLiveNodes()


Copyright © 2014 Atlassian. All Rights Reserved.