com.sun.sgs.impl.service.nodemap
Class NodeMappingServerImpl

java.lang.Object
  extended by com.sun.sgs.impl.util.AbstractService
      extended by com.sun.sgs.impl.service.nodemap.NodeMappingServerImpl
All Implemented Interfaces:
NodeMappingServer, Service, Remote

public final class NodeMappingServerImpl
extends AbstractService
implements NodeMappingServer

The remote server portion of the node mapping service. This portion of the service is used for any global operations, such as selecting a node for an identity. Additionally, all changes to the map are made by the server so it can notify listeners of changes, no matter which node is affected.

The constructor supports the following properties:

Property: com.sun.sgs.impl.service.nodemap.server.port
Default: 44535
The network port for the NodeMappingServer. This value must be no less than 0 and no greater than 65535. The value 0 can only be specified if the com.sun.sgs.impl.service.nodemap.start.server property is true, and means that an anonymous port will be chosen for running the server.

Property: com.sun.sgs.impl.service.nodemap.policy.class
Default: com.sun.sgs.impl.service.nodemap.RoundRobinPolicy
The name of the class that implements NodeAssignPolicy, used for the node assignment policy. The class should be public, not abstract, and should provide a public constructor with Properties and NodeMappingServerImpl parameters.

Property: com.sun.sgs.impl.service.nodemap.remove.expire.time
Default: 5000
The minimum time, in milliseconds, that this server will wait before removing a potentially inactive identity from the map. This value must be greater than 0. Shorter expiration times cause the map to be cleaned up more frequently, potentially causing more assignNode calls; longer expiration times will increase the chance that an identity will become active again before it can be removed.

Property: com.sun.sgs.impl.service.nodemap.relocation.expire.time
Default: 10000
The time allowed, in milliseconds, for IdentityRelocationListeners to call completed on the handler they receive. If this time has elapsed, this server disregards the proposed identity relocation. This value is used to guard against listeners which never respond they are finished. During this time period, the identity is prohibited from moving elsewhere unless the node has failed.

This class uses the Logger named com.sun.sgs.impl.service.nodemap.server to log information at the following logging levels:

This class is public for testing.


Nested Class Summary
(package private) static class NodeMappingServerImpl.GetIdTask
          Task which gets an IdentityMO from a data service.
 
Nested classes/interfaces inherited from class com.sun.sgs.impl.util.AbstractService
AbstractService.State, AbstractService.Version
 
Field Summary
(package private) static int DEFAULT_SERVER_PORT
          The default value of the server port.
(package private) static String SERVER_EXPORT_NAME
          The name we export ourselves under.
(package private) static String SERVER_PORT_PROPERTY
          The property name for the server port.
(package private)  WatchdogService watchdogService
          The watchdog service.
 
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
NodeMappingServerImpl(Properties properties, ComponentRegistry systemRegistry, TransactionProxy txnProxy)
          Creates a new instance of NodeMappingServerImpl, called from the local NodeMappingService.
 
Method Summary
 boolean assertValid(Identity identity)
          Check the validity of the data store for a particular identity.
 long assignNode(Class service, Identity identity, long requestingNode)
          Assigns the identity to a node and indicates that the service class believes this identity is active.
 void canMove(Identity id)
          All IdentityRelocationListeners have completed their work, so it's safe to move the identity.
 void canRemove(Identity id)
          The identity's reference count has gone to zero, so it can be removed.
protected  void doReady()
          Performs ready operations.
protected  void doShutdown()
          Performs shutdown operations.
(package private)  long getNodeForIdentity(Identity id)
          Get the node an identity is mapped to.
(package private)  int getPort()
          Returns the port being used for this server.
protected  void handleServiceVersionMismatch(AbstractService.Version oldVersion, AbstractService.Version currentVersion)
          Handles conversion from the oldVersion to the currentVersion.
 void registerNodeListener(NotifyClient client, long nodeId)
          Register a NotifyClient object to be called when changes occur on a particular node.
(package private)  Set<String> reportFoundKeys(Identity identity)
          Return the data store keys found for a particular identity.
(package private)  void runTransactionally(KernelRunnable task)
          Run the given task synchronously, and transactionally, retrying if the exception is of type <@code ExceptionRetryStatus>.
 String toString()
          Returns a string representation of this instance.
 void unregisterNodeListener(long nodeId)
          Unregister the NotifyClient object for a node if one is registered.
 
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, wait, wait, wait
 

Field Detail

SERVER_PORT_PROPERTY

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

See Also:
Constant Field Values

DEFAULT_SERVER_PORT

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

See Also:
Constant Field Values

SERVER_EXPORT_NAME

static final String SERVER_EXPORT_NAME
The name we export ourselves under.

See Also:
Constant Field Values

watchdogService

final WatchdogService watchdogService
The watchdog service.

Constructor Detail

NodeMappingServerImpl

public NodeMappingServerImpl(Properties properties,
                             ComponentRegistry systemRegistry,
                             TransactionProxy txnProxy)
                      throws Exception
Creates a new instance of NodeMappingServerImpl, called from the local NodeMappingService.

The application context is resolved at construction time (rather than when AbstractService.ready() is called), because this server will never need Managers and will not run application code. Managers are not available until Service.ready is called.

Parameters:
properties - service properties
systemRegistry - system registry
txnProxy - the transaction proxy
Throws:
Exception - if an error occurs during creation
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()
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

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. Called from the instantiating service.

Specified by:
doShutdown in class AbstractService

toString

public String toString()
Returns a string representation of this instance.

Overrides:
toString in class Object
Returns:
a string representation of this instance

assignNode

public long assignNode(Class service,
                       Identity identity,
                       long requestingNode)
                throws IOException
Assigns the identity to a node and indicates that the service class believes this identity is active. If the id has already been assigned to a node, simply return that assignment. If the id is assigned to a node that's not alive, reassign it.

Specified by:
assignNode in interface NodeMappingServer
Parameters:
service - the class of the calling service
identity - the identity to assign should this be a set?
requestingNode - the id of the node requesting assignment
Returns:
the ID of the node that the identity was assigned to, or -1 if the assignment failed
Throws:
IOException - if a communication problem occurs while invoking this method

canMove

public void canMove(Identity id)
             throws IOException
All IdentityRelocationListeners have completed their work, so it's safe to move the identity.

Specified by:
canMove in interface NodeMappingServer
Parameters:
id - the identity which can now be moved
Throws:
IOException - if a communication problem occurs while invoking this method

canRemove

public void canRemove(Identity id)
               throws IOException
The identity's reference count has gone to zero, so it can be removed.

Specified by:
canRemove in interface NodeMappingServer
Parameters:
id - the identity which can be removed from the map
Throws:
IOException - if a communication problem occurs while invoking this method

registerNodeListener

public void registerNodeListener(NotifyClient client,
                                 long nodeId)
                          throws IOException
Register a NotifyClient object to be called when changes occur on a particular node. Only one listener object can be registered per nodeId, and registering a listener will clear any previously registered listener for that nodeId.

Registration must only be made during service startup. Only nodes that have registered can be assigned identities. Nodes will not be added to the server's NodeAssignPolicy unless they have registered a listener with this method.

Specified by:
registerNodeListener in interface NodeMappingServer
Parameters:
client - the callback client
nodeId - the node which client is interested in changes to
Throws:
IOException - if a communication problem occurs while invoking this method

unregisterNodeListener

public void unregisterNodeListener(long nodeId)
                            throws IOException
Unregister the NotifyClient object for a node if one is registered. Also called internally when we hear a node has died.

Specified by:
unregisterNodeListener in interface NodeMappingServer
Parameters:
nodeId - the node
Throws:
IOException - if a communication problem occurs while invoking this method

assertValid

public boolean assertValid(Identity identity)
                    throws Exception
Check the validity of the data store for a particular identity. Used for testing.

Specified by:
assertValid in interface NodeMappingServer
Parameters:
identity - the identity
Returns:
true if all is well, false if there is a problem
Throws:
Exception - if any error occurs

getPort

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

Returns:
the port

runTransactionally

void runTransactionally(KernelRunnable task)
                  throws Exception
Run the given task synchronously, and transactionally, retrying if the exception is of type <@code ExceptionRetryStatus>.

Parameters:
task - the task
Throws:
Exception

getNodeForIdentity

long getNodeForIdentity(Identity id)
                  throws Exception
Get the node an identity is mapped to. Used for testing.

Parameters:
id - the identity
Returns:
the node the identity is mapped to
Throws:
Exception - if any error occurs

reportFoundKeys

Set<String> reportFoundKeys(Identity identity)
                      throws Exception
Return the data store keys found for a particular identity. Used for testing.

Parameters:
identity - the identity
Returns:
the set of service name bindings found for that identity
Throws:
Exception - if any error occurs

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