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

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

public final class WatchdogServerImpl
extends AbstractService
implements WatchdogServer

The WatchdogServer implementation.

The constructor supports the following properties:

Property: com.sun.sgs.impl.service.watchdog.server.port
Default: 44533
Specifies the network port for the server. This value must be greater than or equal to 0 and no greater than 65535. If the value specified is 0, then an anonymous port will be chosen. The value chosen will be logged, and can also be accessed with the getPort method.

Property: com.sun.sgs.impl.service.watchdog.server.renew.interval
Default: 1000 (one second)
Specifies the renew interval which is returned by the renewNode method). The interval must be greater than or equal to 5 milliseconds and less than or equal to 10000 milliseconds (10 seconds).

Property: com.sun.sgs.impl.service.watchdog.server.timeflush.interval
Default: 5000 (five seconds)
Represents the amount of time in milliseconds that the server will wait between updates to the global application time stored in the data store. A larger value will take less system resources but will allow the possibility of the global application clock to drift by at least the given value if the system crashes. The interval must be greater than or equal to 100 milliseconds and less than or equal to 300000 milliseconds.

Note that this server caches NodeImpls outside the data service to maintain state.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.sgs.impl.util.AbstractService
AbstractService.State, AbstractService.Version
 
Field Summary
(package private) static int DEFAULT_PORT
          The default value of the server port.
(package private)  SortedSet<NodeImpl> expirationSet
          The set of alive nodes, sorted by renew expiration time.
(package private)  long localNodeId
          The node ID for this server.
(package private)  Object notifyClientsLock
          The lock for notifying the NotifyClientsThread.
(package private) static String PORT_PROPERTY
          The property name for the server port.
(package private)  long renewInterval
          The renew interval.
(package private)  Queue<NodeImpl> statusChangedNodes
          The queue of nodes whose status has changed.
(package private)  long timeflushInterval
          The timeflush interval.
(package private) static String WATCHDOG_SERVER_NAME
          The server name in the registry.
 
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
WatchdogServerImpl(Properties properties, ComponentRegistry systemRegistry, TransactionProxy txnProxy, String host, WatchdogClient client, boolean fullStack)
          Constructs an instance of this class with the specified properties.
 
Method Summary
 long currentAppTimeMillis()
          Returns the global application time in milliseconds as it is maintained by the central node.
protected  void doReady()
          Performs ready operations.
protected  void doShutdown()
          Performs shutdown operations.
 int getPort()
          Returns the port being used for this server.
(package private)  long getTimeOffset()
          Returns the offset being used by this server to report global application time with the currentAppTimeMillis() method.
protected  void handleServiceVersionMismatch(AbstractService.Version oldVersion, AbstractService.Version currentVersion)
          Handles conversion from the oldVersion to the currentVersion.
(package private)  Collection<NodeImpl> processNodeFailures(Collection<NodeImpl> nodesToFail)
          Processes the nodes which have failed by calling the failure methods for each node in the collection.
 void recoveredNode(long nodeId, long backupId)
          Notifies this watchdog that the node with the specified nodeId has been recovered by the node with the specified backupId.
 long registerNode(long nodeId, String host, WatchdogClient client, int jmxPort)
          Registers a node with the corresponding nodeId, host, and client, and returns the interval (in milliseconds) that this watchdog must be notified, via the renewNode method, in order for the specified node to be considered alive.
 boolean renewNode(long nodeId)
          Notifies this watchdog that the node with the specified nodeId is alive.
 void setNodeHealth(long nodeId, boolean isLocal, Node.Health health, String component, int maxNumberOfAttempts)
          Notifies the node with the given ID that its health has been set.
 
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
 

Field Detail

WATCHDOG_SERVER_NAME

static final String WATCHDOG_SERVER_NAME
The server name in the registry.

See Also:
Constant Field Values

PORT_PROPERTY

static final String PORT_PROPERTY
The property name for the server port.

See Also:
Constant Field Values

DEFAULT_PORT

static final int DEFAULT_PORT
The default value of the server port.

See Also:
Constant Field Values

renewInterval

final long renewInterval
The renew interval.


timeflushInterval

final long timeflushInterval
The timeflush interval.


localNodeId

final long localNodeId
The node ID for this server.


notifyClientsLock

final Object notifyClientsLock
The lock for notifying the NotifyClientsThread.


statusChangedNodes

final Queue<NodeImpl> statusChangedNodes
The queue of nodes whose status has changed.


expirationSet

final SortedSet<NodeImpl> expirationSet
The set of alive nodes, sorted by renew expiration time.

Constructor Detail

WatchdogServerImpl

public WatchdogServerImpl(Properties properties,
                          ComponentRegistry systemRegistry,
                          TransactionProxy txnProxy,
                          String host,
                          WatchdogClient client,
                          boolean fullStack)
                   throws Exception
Constructs an instance of this class with the specified properties. See the class documentation for a list of supported properties.

Parameters:
properties - server properties
systemRegistry - the system registry
txnProxy - the transaction proxy
host - the local host name
client - the local watchdog client
fullStack - true if this server is running on a full stack
Throws:
Exception - if there is a problem starting the 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.

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

registerNode

public long registerNode(long nodeId,
                         String host,
                         WatchdogClient client,
                         int jmxPort)
                  throws NodeRegistrationFailedException
Registers a node with the corresponding nodeId, host, and client, and returns the interval (in milliseconds) that this watchdog must be notified, via the renewNode method, in order for the specified node to be considered alive.

If this method throws NodeRegistrationFailedException, the caller should not retry as this indicates a fatal error.

When a node fails or a new node starts, the given client will be notified of these status changes via its nodeStatusChanges method.

Specified by:
registerNode in interface WatchdogServer
Parameters:
nodeId - the node ID of the node
host - a host name
client - a watchdog client
jmxPort - the port JMX is listening on, or -1 if JMX is not enabled for remote listening on the node
Returns:
the renew interval (in milliseconds)
Throws:
NodeRegistrationFailedException - if there is a problem registering the node

renewNode

public boolean renewNode(long nodeId)
Notifies this watchdog that the node with the specified nodeId is alive. This method returns true if this watchdog still considers the node alive, and returns false otherwise. This watchdog considers the node to have failed if a renew request is not received from the node before the assigned interval, returned from registerNode, expires. If this method returns false for a given nodeId, the caller should not retry this method because the node is considered to have failed.

Specified by:
renewNode in interface WatchdogServer
Parameters:
nodeId - a node ID
Returns:
true if the node is considered alive, false otherwise

recoveredNode

public void recoveredNode(long nodeId,
                          long backupId)
Notifies this watchdog that the node with the specified nodeId has been recovered by the node with the specified backupId.

Specified by:
recoveredNode in interface WatchdogServer
Parameters:
nodeId - the recovered node's ID
backupId - the backup node's ID

setNodeHealth

public void setNodeHealth(long nodeId,
                          boolean isLocal,
                          Node.Health health,
                          String component,
                          int maxNumberOfAttempts)
Notifies the node with the given ID that its health has been set. If the health is RED it indicates that the node has failed and should be shutdown. In this case, if the given node is a remote node, this notification is a result of a server running into difficulty communicating with a remote node, so the server's watchdog service is responsible for notifying the watchdog service in order to issue the shutdown. The component parameter may be any identifying string, but is typically the class name of the component that reported the specified health.

Specified by:
setNodeHealth in interface WatchdogServer
Parameters:
nodeId - the node's ID
isLocal - specifies if the node is reporting health on itself or a remote node
health - the node's health
component - the component reported the specified health
maxNumberOfAttempts - the maximum number of attempts to try and resolve an IOException

currentAppTimeMillis

public long currentAppTimeMillis()
Returns the global application time in milliseconds as it is maintained by the central node. 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.

Note: Since this method is typically called as part of a Remote interface, appropriate measures should be taken to account for possible network latency.

Specified by:
currentAppTimeMillis in interface WatchdogServer
Returns:
the global application time in milliseconds according to the central time server

getTimeOffset

long getTimeOffset()
Returns the offset being used by this server to report global application time with the currentAppTimeMillis() method.

Returns:
the time offset

processNodeFailures

Collection<NodeImpl> processNodeFailures(Collection<NodeImpl> nodesToFail)
Processes the nodes which have failed by calling the failure methods for each node in the collection. The processes are separated into two for-loops so that a failed node is not mistakenly chosen as a backup while this operation is occurring.

Parameters:
nodesToFail - the collection of failed nodes
Returns:
a subset of nodesToFail that were marked as failed from this method

getPort

public int getPort()
Returns the port being used for this server.

Returns:
the server port

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