com.sun.sgs.impl.service.watchdog
Class NodeImpl

java.lang.Object
  extended by com.sun.sgs.impl.service.watchdog.NodeImpl
All Implemented Interfaces:
ManagedObject, Node, Serializable, Comparable<NodeImpl>

 class NodeImpl
extends Object
implements Node, ManagedObject, Serializable, Comparable<NodeImpl>

Implements the Node interface. The state for a given nodeId is bound in the datastore with the following service bound name:

com.sun.sgs.impl.service.watchdog.NodeImpl.nodeId


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sun.sgs.service.Node
Node.Health
 
Field Summary
static long INVALID_ID
          The ID for an unknown node.
 
Constructor Summary
NodeImpl(long nodeId, String hostName, int jmxPort, WatchdogClient client)
          Constructs an instance of this class with the given nodeId, hostName, and client.
NodeImpl(long nodeId, String hostName, Node.Health health)
          Constructs an instance of this class with the given nodeId, hostName, and health.
NodeImpl(long nodeId, String hostName, Node.Health health, long backupId)
          Constructs an instance of this class with the given nodeId, hostName, isAlive status, and backupId.
 
Method Summary
(package private)  void addPrimary(DataService dataService, long primaryId)
          Adds the specified primaryId to the list of primaries for which this node is a backup, and updates the node's state in the specified dataService.
 int compareTo(NodeImpl o)
          
 boolean equals(Object obj)
          
(package private)  long getBackupId()
          Returns the backup for this node, or -1L if there is no backup.
(package private)  long getExpiration()
          Returns the expiration time.
 Node.Health getHealth()
          Returns the health of the node.
 String getHostName()
          Returns this node's host name.
 long getId()
          Returns the node ID, which is always non-negative.
(package private) static NodeImpl getNode(DataService dataService, long nodeId)
          Returns the Node instance for the given nodeId, retrieved from the specified dataService, or null if the node isn't bound in the data service .
(package private) static NodeImpl getNodeForUpdate(DataService dataService, long nodeId)
          Returns the Node instance for the given nodeId, retrieved from the specified dataService for update.
(package private)  NodeInfo getNodeInfo()
          Returns the management information for this node.
(package private) static Iterator<Node> getNodes(DataService dataService)
          Returns an iterator for Node instances to be retrieved from the specified dataService.
(package private)  Set<Long> getPrimaries()
          Returns the set of primary nodes for which this node is a backup.
(package private)  WatchdogClient getWatchdogClient()
          Returns the watchdog client, or null.
(package private)  boolean hasBackup()
          Returns true if this node has a backup.
 int hashCode()
          
 boolean isAlive()
          Returns true if the node is known to be alive, and false if the node is thought to have failed or is unknown.
(package private)  boolean isExpired()
          Returns true if the node is expired, and false otherwise.
(package private) static Collection<NodeImpl> markAllNodesFailed(DataService dataService)
          Marks all nodes currently bound in the specified dataService as failed, and returns a collection of those nodes.
(package private)  void putNode(DataService dataService)
          Stores this instance in the specified dataService.
(package private) static void removeNode(DataService dataService, long nodeId)
          Removes the node with the specified nodeId and its binding from the specified dataService.
(package private)  void setExpiration(long newExpiration)
          Sets the expiration time for this node instance.
(package private)  void setFailed(DataService dataService, NodeImpl backup)
          Sets the health of this node instance to RED, sets this node's backup to the specified backup, empties the set of primaries for which this node is recovering, and updates the node's state in the specified dataService.
(package private)  void setHealth(DataService dataService, Node.Health newHealth)
          Sets the health of this node instance to a non-RED value.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INVALID_ID

public static final long INVALID_ID
The ID for an unknown node.

See Also:
Constant Field Values
Constructor Detail

NodeImpl

NodeImpl(long nodeId,
         String hostName,
         int jmxPort,
         WatchdogClient client)
Constructs an instance of this class with the given nodeId, hostName, and client. This instance's alive status is set to true. The expiration time for this instance should be set as soon as it is known.

Parameters:
nodeId - a node ID
hostName - a host name
jmxPort - the port JMX is listening on for the node, or -1
client - a watchdog client

NodeImpl

NodeImpl(long nodeId,
         String hostName,
         Node.Health health)
Constructs an instance of this class with the given nodeId, hostName, and health. This instance's watchdog client is set to null and its backup is unassigned (backup ID is -1).

Parameters:
nodeId - a node ID
hostName - a host name, or null
health - the node's health

NodeImpl

NodeImpl(long nodeId,
         String hostName,
         Node.Health health,
         long backupId)
Constructs an instance of this class with the given nodeId, hostName, isAlive status, and backupId. This instance's watchdog client is set to null.

Parameters:
nodeId - a node ID
hostName - a host name, or null
health - the node's health
backupId - the ID of the node's backup (-1 if no backup is assigned)
Method Detail

getId

public long getId()
Returns the node ID, which is always non-negative.

Specified by:
getId in interface Node
Returns:
the node ID

getHostName

public String getHostName()
Returns this node's host name.

Specified by:
getHostName in interface Node
Returns:
this node's host name

isAlive

public boolean isAlive()
Returns true if the node is known to be alive, and false if the node is thought to have failed or is unknown.

Specified by:
isAlive in interface Node
Returns:
true if the node is alive, and false otherwise

getHealth

public Node.Health getHealth()
Returns the health of the node.

Specified by:
getHealth in interface Node
Returns:
the node's health

compareTo

public int compareTo(NodeImpl o)

Specified by:
compareTo in interface Comparable<NodeImpl>

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

getWatchdogClient

WatchdogClient getWatchdogClient()
Returns the watchdog client, or null.


getExpiration

long getExpiration()
Returns the expiration time. A value of 0 means that either the value has not been initialized or the value is not meaningful because the node has failed. If isAlive() returns false the value returned from this method is not meaningful.


setExpiration

void setExpiration(long newExpiration)
Sets the expiration time for this node instance.

Parameters:
newExpiration - the new expiration value

isExpired

boolean isExpired()
Returns true if the node is expired, and false otherwise.

Returns:
true if the node is expired, and false otherwise

setFailed

void setFailed(DataService dataService,
               NodeImpl backup)
Sets the health of this node instance to RED, sets this node's backup to the specified backup, empties the set of primaries for which this node is recovering, and updates the node's state in the specified dataService. Subsequent calls to isAlive will return false.

Parameters:
dataService - a data service
backup - a chosen backup
Throws:
ObjectNotFoundException - if this node has been removed
TransactionException - if there is a problem with the current transaction

setHealth

void setHealth(DataService dataService,
               Node.Health newHealth)
Sets the health of this node instance to a non-RED value. If the node health is to be set to RED use setFailed.

Parameters:
dataService - a data service
newHealth - the new health of this node
Throws:
ObjectNotFoundException - if this node has been removed
TransactionException - if there is a problem with the current transaction

addPrimary

void addPrimary(DataService dataService,
                long primaryId)
Adds the specified primaryId to the list of primaries for which this node is a backup, and updates the node's state in the specified dataService.

Parameters:
dataService - a data service
primaryId - the ID of a primary for which this node is a backup
Throws:
ObjectNotFoundException - if this node has been removed
TransactionException - if there is a problem with the current transaction

getPrimaries

Set<Long> getPrimaries()
Returns the set of primary nodes for which this node is a backup.


hasBackup

boolean hasBackup()
Returns true if this node has a backup.


getBackupId

long getBackupId()
Returns the backup for this node, or -1L if there is no backup.


putNode

void putNode(DataService dataService)
Stores this instance in the specified dataService. This method should only be called within a transaction.

Parameters:
dataService - a data service
Throws:
TransactionException - if there is a problem with the current transaction

getNodeInfo

NodeInfo getNodeInfo()
Returns the management information for this node.

Returns:
the management information for this node

removeNode

static void removeNode(DataService dataService,
                       long nodeId)
Removes the node with the specified nodeId and its binding from the specified dataService. If the binding has already been removed from the dataService this method takes no action. This method should only be called within a transaction.

Parameters:
dataService - a data service
nodeId - a node ID
Throws:
TransactionException - if there is a problem with the current transaction

getNode

static NodeImpl getNode(DataService dataService,
                        long nodeId)
Returns the Node instance for the given nodeId, retrieved from the specified dataService, or null if the node isn't bound in the data service . This method should only be called within a transaction.

Parameters:
dataService - a data service
nodeId - a node ID
Returns:
the node for the given nodeId, or null
Throws:
TransactionException - if there is a problem with the current transaction

getNodeForUpdate

static NodeImpl getNodeForUpdate(DataService dataService,
                                 long nodeId)
Returns the Node instance for the given nodeId, retrieved from the specified dataService for update. This method returns null if the node isn't bound in the data service . This method must only be called within a transaction.

Parameters:
dataService - a data service
nodeId - a node ID
Returns:
the node for the given nodeId, or null
Throws:
TransactionException - if there is a problem with the current transaction

markAllNodesFailed

static Collection<NodeImpl> markAllNodesFailed(DataService dataService)
Marks all nodes currently bound in the specified dataService as failed, and returns a collection of those nodes. This method should only be called within a transaction.

Parameters:
dataService - a data service
Returns:
a collection of currently bound nodes, each marked as failed
Throws:
TransactionException - if there is a problem with the current transaction

getNodes

static Iterator<Node> getNodes(DataService dataService)
Returns an iterator for Node instances to be retrieved from the specified dataService. The returned iterator does not support the remove operation. This method should only be called within a transaction, and the returned iterator should only be used within that transaction.

Parameters:
dataService - a data service
Returns:
an iterator for nodes
Throws:
TransactionException - if there is a problem with the current transaction

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved