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

java.lang.Object
  extended by com.sun.sgs.impl.util.AbstractService
      extended by com.sun.sgs.impl.service.watchdog.WatchdogServiceImpl
All Implemented Interfaces:
Service, WatchdogService

public final class WatchdogServiceImpl
extends AbstractService
implements WatchdogService

The WatchdogService implementation.

The constructor supports the following properties:

Property: com.sun.sgs.impl.service.watchdog.server.host
Default: the value of the com.sun.sgs.server.host property, if present, or localhost if this node is starting the server

Specifies the host name for the watchdog server that this service contacts. If the com.sun.sgs.node.type property is not appNode, then this property's default is used (since the watchdog server to contact will be the one started on the local host).
Property: com.sun.sgs.impl.service.watchdog.server.port
Default: 44533
Specifies the network port for the watchdog server that this service contacts (and, optionally, starts). If the com.sun.sgs.node.type property is not singleNode, then the value must be greater than or equal to 0 and no greater than 65535, otherwise the value must be greater than 0, and no greater than 65535.

Property: com.sun.sgs.impl.service.watchdog.client.host
Default: the local host name
Specifies the host name for the watchdog client used when registering the node with the watchdog service.
Property: com.sun.sgs.impl.service.watchdog.client.port
Default: 0 (anonymous port)
Specifies the network port for this watchdog service for receiving node status change notifications from the watchdog server. The value must be greater than or equal to 0 and no greater than 65535.

Property: com.sun.sgs.impl.service.watchdog.timesync.interval
Default: 300000 (five minutes)
Specifies the amount of time in milliseconds that this service will wait between synchronizing its local time with the global time of the WatchdogServer. The value must be greater than or equal to 1000 and no greater than Long.MAX_VALUE.
Property: com.sun.management.jmxremote.port
Default: None
Enables remote JMX monitoring through the specified port. By default, remote monitoring is not enabled. Not that this is a system property, and must be set on the command line when starting the node.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.sgs.impl.util.AbstractService
AbstractService.State, AbstractService.Version
 
Field Summary
(package private)  WatchdogClient clientProxy
          The watchdog client proxy.
(package private)  String localHost
          The name of the local host.
(package private)  Thread renewThread
          The thread that renews the node with the watchdog server.
(package private)  WatchdogServer serverProxy
          The watchdog server proxy, or null.
 
Fields inherited from class com.sun.sgs.impl.util.AbstractService
appName, dataService, IO_TASK_PROPERTY_PREFIX, IO_TASK_RETRIES_PROPERTY, IO_TASK_WAIT_TIME_PROPERTY, maxIoAttempts, retryWaitTime, taskOwner, taskScheduler, transactionScheduler, txnProxy
 
Constructor Summary
WatchdogServiceImpl(Properties properties, ComponentRegistry systemRegistry, TransactionProxy txnProxy, KernelShutdownController ctrl)
          Constructs an instance of this class with the specified properties.
 
Method Summary
 void addNodeListener(NodeListener listener)
          Registers a listener to be notified when any node that this service monitors starts or fails.
 void addRecoveryListener(RecoveryListener listener)
          Adds the specified recovery listener for the local node.
 long currentAppTimeMillis()
          Returns the current global application time in milliseconds.
protected  void doReady()
          Performs ready operations.
protected  void doShutdown()
          Performs shutdown operations.
 long getAppTimeMillis(long systemTimeMillis)
          Converts a system time value representing the total elapsed time in milliseconds since midnight, January 1, 1970 UTC to an "application time" value.
 Node getBackup(long nodeId)
          Returns the node that is designated as the backup for the node with the specified nodeId, or null if no backup is currently designated.
 Node.Health getLocalNodeHealth()
          Returns the health of the local node.
 Node.Health getLocalNodeHealthNonTransactional()
          Returns the health of the local node.
 Node getNode(long nodeId)
          Returns node status information for the node with the specified nodeId, or null if the node is unknown.
 Iterator<Node> getNodes()
          Returns an iterator for the set of nodes that this service monitors.
(package private)  NodeInfo getNodeStatusInfo()
          Retrieves information about the current node.
 WatchdogServerImpl getServer()
          Returns the server.
 long getSystemTimeMillis(long appTimeMillis)
          Converts an "application time" value representing the total amount of time in milliseconds that the current application has been running since the initialize method was called on its AppListener object to a system time value.
protected  void handleServiceVersionMismatch(AbstractService.Version oldVersion, AbstractService.Version currentVersion)
          Handles conversion from the oldVersion to the currentVersion.
 boolean isLocalNodeAlive()
          Returns true if the local node is considered alive, otherwise returns false.
 boolean isLocalNodeAliveNonTransactional()
          Returns true if the local node is considered alive, otherwise returns false.
 void reportFailure(long nodeId, String component)
          Informs the watchdog that a problem has occurred in a service or component.
 void reportHealth(long nodeId, Node.Health nodeHealth, String component)
          Informs the watchdog of a node's health.
 void reportHealth(Node.Health nodeHealth, String component)
          Informs the watchdog of this node's health.
 
Methods inherited from class com.sun.sgs.impl.util.AbstractService
callFinished, callStarted, checkNonTransactionalContext, checkServiceVersion, createTaskQueue, getDataService, getName, getState, isAlive, isInInitializedState, isRetryableException, ready, runIoTask, shutdown, shuttingDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.sgs.service.Service
getName, ready, shutdown
 

Field Detail

serverProxy

final WatchdogServer serverProxy
The watchdog server proxy, or null.


clientProxy

final WatchdogClient clientProxy
The watchdog client proxy.


localHost

final String localHost
The name of the local host.


renewThread

final Thread renewThread
The thread that renews the node with the watchdog server.

Constructor Detail

WatchdogServiceImpl

public WatchdogServiceImpl(Properties properties,
                           ComponentRegistry systemRegistry,
                           TransactionProxy txnProxy,
                           KernelShutdownController ctrl)
                    throws Exception
Constructs an instance of this class with the specified properties. See the class documentation for a list of supported properties. The Watchdog service is given the ability to shutdown a node with the KernelShutdownController.

Parameters:
properties - service (and server) properties
systemRegistry - system registry
txnProxy - transaction proxy
ctrl - shutdown controller
Throws:
Exception - if a problem occurs constructing the service/server
Method Detail

handleServiceVersionMismatch

protected void handleServiceVersionMismatch(AbstractService.Version oldVersion,
                                            AbstractService.Version currentVersion)
Handles conversion from the oldVersion to the currentVersion. This method is invoked by checkServiceVersion if a version mismatch is detected and is invoked from within a transaction.

Specified by:
handleServiceVersionMismatch in class AbstractService
Parameters:
oldVersion - the old version
currentVersion - the current version

doReady

protected void doReady()
                throws Exception
Performs ready operations. This method is invoked by the ready method only once so that the subclass can perform any operations necessary during the "ready" phase. A health update will be sent to listeners.

Specified by:
doReady in class AbstractService
Throws:
Exception - if a problem occurs

doShutdown

protected void doShutdown()
Performs shutdown operations. This method is invoked by the shutdown method only once so that the subclass can perform any operations necessary to shutdown the service.

Specified by:
doShutdown in class AbstractService

getLocalNodeHealth

public Node.Health getLocalNodeHealth()
Returns the health of the local node. This method should only be called from within a transaction.

Specified by:
getLocalNodeHealth in interface WatchdogService
Returns:
the health of the local node

isLocalNodeAlive

public boolean isLocalNodeAlive()
Returns true if the local node is considered alive, otherwise returns false. This method should only be called from within a transaction.

Specified by:
isLocalNodeAlive in interface WatchdogService
Returns:
true if the local node is considered alive, and false otherwise

getLocalNodeHealthNonTransactional

public Node.Health getLocalNodeHealthNonTransactional()
Returns the health of the local node. This method returns the most recent information known to this service and may not be definitive. For definitive information, use the getLocalNodeHealth method.

This method may be invoked any time after this service is initialized, whether or not the calling context is inside or outside of a transaction.

Specified by:
getLocalNodeHealthNonTransactional in interface WatchdogService
Returns:
the health of the local node

isLocalNodeAliveNonTransactional

public boolean isLocalNodeAliveNonTransactional()
Returns true if the local node is considered alive, otherwise returns false. This method returns the most recent information known to this service and may not be definitive. For definitive information, use the isLocalNodeAlive method.

This method may be invoked any time after this service is initialized, whether or not the calling context is inside or outside of a transaction.

Specified by:
isLocalNodeAliveNonTransactional in interface WatchdogService
Returns:
true if the local node is considered alive, and false otherwise

getNodes

public Iterator<Node> getNodes()
Returns an iterator for the set of nodes that this service monitors. The remove operation of the returned iterator is not supported and will throw UnsupportedOperationException if invoked. This method must be called within a transaction, and the returned iterator must only be used within that transaction.

Specified by:
getNodes in interface WatchdogService
Returns:
an iterator for the set of nodes that this service monitors

getNode

public Node getNode(long nodeId)
Returns node status information for the node with the specified nodeId, or null if the node is unknown. This method should only be called within a transaction.

Specified by:
getNode in interface WatchdogService
Parameters:
nodeId - a node ID
Returns:
node status information for the specified nodeId, or null

addNodeListener

public void addNodeListener(NodeListener listener)
Registers a listener to be notified when any node that this service monitors starts or fails. Registered listeners are notified outside of a transaction.

This method must be invoked outside of a transaction.

Specified by:
addNodeListener in interface WatchdogService
Parameters:
listener - a node listener

getBackup

public Node getBackup(long nodeId)
Returns the node that is designated as the backup for the node with the specified nodeId, or null if no backup is currently designated. This method must be called within a transaction.

Note: this method should probably be moved to the Node interface, or it should throw an exception in the case where there is no existing node corresponding to nodeId.

Specified by:
getBackup in interface WatchdogService
Parameters:
nodeId - a node ID
Returns:
a backup node, or null

addRecoveryListener

public void addRecoveryListener(RecoveryListener listener)
Adds the specified recovery listener for the local node. If the local node is designated as a backup for a node that fails, the specified listener will be notified (outside of a transaction) by having its recover method invoked, passing the failed node and a SimpleCompletionHandler whose completed method must be invoked when the recovery operations initiated by the listener are complete.

This method must be invoked outside of a transaction.

Specified by:
addRecoveryListener in interface WatchdogService
Parameters:
listener - a recovery listener

reportFailure

public void reportFailure(long nodeId,
                          String component)
Informs the watchdog that a problem has occurred in a service or component. The watchdog will notify the server of the failure and then proceed to shutting down the node. The node specified as the nodeId can be the local node or a remote node. The component parameter may be any identifying string, but is typically the class name of the component.

Once reportFailure has been called, the health of the specified node can not be changed.

This method must be invoked outside of a transaction.

Specified by:
reportFailure in interface WatchdogService
Parameters:
nodeId - the id of the node to shutdown
component - the name of the component that failed

reportHealth

public void reportHealth(Node.Health nodeHealth,
                         String component)
Informs the watchdog of this node's health. Multiple components may report on a node's health. The watchdog will use these reports to determine the overall node's health. The component parameter may be any identifying string, but is typically the class name of the component.

Once reportLocalHealth has been called with a health that returns false from its Health.isAlive method, the health of the local node can not be changed.

This method must be invoked outside of a transaction.

Specified by:
reportHealth in interface WatchdogService
Parameters:
nodeHealth - the health
component - the name of the component reporting health

reportHealth

public void reportHealth(long nodeId,
                         Node.Health nodeHealth,
                         String component)
Informs the watchdog of a node's health. Multiple components may report on a node's health. The watchdog will use these reports to determine the overall node's health. The node specified as the nodeId can be the local node or a remote node. The component parameter may be any identifying string, but is typically the class name of the component.

Once reportHealth has been called with a health that returns false from its Health.isAlive method, the health of the specified node can not be changed.

This method must be invoked outside of a transaction.

Specified by:
reportHealth in interface WatchdogService
Parameters:
nodeId - the id of the node
nodeHealth - the health
component - the name of the component reporting health

currentAppTimeMillis

public long currentAppTimeMillis()
Returns the current global application time in milliseconds. This method returns the amount of time in milliseconds that the current application has been running since the initialize method was called on the application's AppListener object. Any time that passes while the application is not running does not affect this value. This means that this method can effectively be used to measure the global wall clock time of the current application's running state.

Note: This method cannot be reliably used to make fine-grained time comparisons across task boundaries. Unpredictable conditions such as network latency mean that the resulting value may be subject to some skew. Additionally, the global accuracy of the clock time may drift as much as a few seconds in either direction due to inherent inaccuracies recovering application time after a system crash.

Specified by:
currentAppTimeMillis in interface WatchdogService
Returns:
the current global application time in milliseconds

getAppTimeMillis

public long getAppTimeMillis(long systemTimeMillis)
Converts a system time value representing the total elapsed time in milliseconds since midnight, January 1, 1970 UTC to an "application time" value. An application time value is the total amount of time in milliseconds that the current application has been running since the initialize method was called on its AppListener object.

Specified by:
getAppTimeMillis in interface WatchdogService
Parameters:
systemTimeMillis - a system time value
Returns:
the given system time converted into application time

getSystemTimeMillis

public long getSystemTimeMillis(long appTimeMillis)
Converts an "application time" value representing the total amount of time in milliseconds that the current application has been running since the initialize method was called on its AppListener object to a system time value. A system time value is the total elapsed time in milliseconds since midnight, January 1, 1970 UTC.

Specified by:
getSystemTimeMillis in interface WatchdogService
Parameters:
appTimeMillis - an application time value
Returns:
the given application time converted into system time

getServer

public WatchdogServerImpl getServer()
Returns the server. This method is used for testing.

Returns:
the server

getNodeStatusInfo

NodeInfo getNodeStatusInfo()
Retrieves information about the current node.

Returns:
information about the current node

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