osl.service.yp
Class YP

java.lang.Object
  |
  +--osl.service.Service
        |
        +--osl.service.yp.YP

public class YP
extends Service
implements TransportClient, RequestClient

This is a simple YP service which allows local actors to look up the addresses of remote actor managers by specifying an IP or hostname. The manager name returned is always that returned by the YP service running on the remote node. If there is no YP service then the service call will hang.

Version:
$Revision: 1.10 $ ($Date: 1999/12/29 03:16:31 $)
See Also:
Service

Field Summary
static ServiceName name
          The name of this service.
 int port
          The port number used by this service.
static int YP_QUERY
          This constant indicates a query YP message.
static int YP_RESPONSE
          This constant indicates a response YP message.
 
Fields inherited from class osl.service.Service
serviceMethods
 
Constructor Summary
YP()
          The default constructor.
 
Method Summary
static YPMsg deserializeMsg(byte[] src)
          A convenient function for deserializing a message.
 void handlerException(RequestSession session, java.lang.Exception except, RequestID id)
          This method is required by RequestClient, but should never actually be called since we only issue RPC requests through our request session.
static byte[] serializeMsg(YPMsg src)
          A convenient function for serializing a message.
 void serviceInitialize(Scheduler S, RemoteActorManager M)
          Initialize this service instance.
 void serviceInitialize(Scheduler S, RemoteActorManager M, TransportLayer T, RequestHandler R, java.lang.String P)
          The REAL initializer for this service.
 ServiceName serviceName()
          Return the name of this service.
 void transportException(TransportInstance target, TransportMessage msg, TransportException error)
          Called if the transport layer encounters an exception while attempting to send a previously queued message.
 void transportReceive(TransportInstance target, TransportMessage msg)
          Called when the transport layer has received a new message on a connection associated with this client.
 ActorManagerName ypLookupRemoteManager(java.lang.String toLookup)
          Lookup the ActorManagerName of the foundry node running on a particular machine.
 ActorManagerName ypMapActorToManager(ActorName key)
          Map an ActorName to the ActorManagerName of the actor currently managing the actor (according to the nameservice).
 
Methods inherited from class osl.service.Service
serviceInvoke, serviceRegisterMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public static final ServiceName name
The name of this service. This field is static and final so that it may be referenced by all user-written actors which need access to this service. The name is represented as an anonymous class (cool dirty trick, yes?)

port

public int port
The port number used by this service. This is specified by the initialization method for this service.

YP_QUERY

public static final int YP_QUERY
This constant indicates a query YP message.

YP_RESPONSE

public static final int YP_RESPONSE
This constant indicates a response YP message.
Constructor Detail

YP

public YP()
The default constructor.
Method Detail

serviceInitialize

public void serviceInitialize(Scheduler S,
                              RemoteActorManager M)
                       throws ServiceException
Initialize this service instance.
Parameters:
S - A reference to the scheduler which should be used to schedule nameservice threads.
T - A reference to the transport layer which should be used for interactions between nameservice instances.
Throws:
ServiceException - Thrown if there is an error initializing this service.
Overrides:
serviceInitialize in class Service

serviceInitialize

public void serviceInitialize(Scheduler S,
                              RemoteActorManager M,
                              TransportLayer T,
                              RequestHandler R,
                              java.lang.String P)
                       throws ServiceException
The REAL initializer for this service. This method is the required initializer in order for the YP service to work correctly.
Throws:
ServiceException - Thrown if there is an error initializing this service.

serviceName

public ServiceName serviceName()
Return the name of this service.
Returns:
A ServiceName structure representing the name of this service.
Overrides:
serviceName in class Service

ypLookupRemoteManager

public ActorManagerName ypLookupRemoteManager(java.lang.String toLookup)
                                       throws ServiceException
Lookup the ActorManagerName of the foundry node running on a particular machine. At the moment, this method does the dumb thing and sends a request to the remote host everytime (rather than being a little smarter and caching previous lookups). I'll implement the cache later.
Parameters:
toLookup - A String giving the host name or IP of the node to lookup.
Returns:
The ActorManagerName of the manager running on node toLookup. Note that because the UDP transport layer does not currently detect node/link failure, a call to this function may hang if no manager is running on the given node, or if there is a communication failure while sending the message.
Throws:
ServiceException - Thrown if there is an error invoking this service.

ypMapActorToManager

public ActorManagerName ypMapActorToManager(ActorName key)
                                     throws ServiceException
Map an ActorName to the ActorManagerName of the actor currently managing the actor (according to the nameservice). Note that this information returned by this method may quickly become stale if the target actor migrates often.
Parameters:
key - The ActorName of the actor to look up.
Returns:
The ActorManagerName of the manager currently managing the actor with name key.
Throws:
ServiceException - Thrown if there is an error invoking this method.

serializeMsg

public static byte[] serializeMsg(YPMsg src)
                           throws java.io.IOException
A convenient function for serializing a message.

deserializeMsg

public static YPMsg deserializeMsg(byte[] src)
                            throws java.io.IOException,
                                   java.io.StreamCorruptedException,
                                   java.lang.ClassNotFoundException,
                                   java.io.OptionalDataException
A convenient function for deserializing a message.
Throws:
java.io.IOException - Thrown if an I/O error is encountered while reading the input stream created for the deserialized message.
java.io.StreamCorruptedException - Thrown if the stream constructed for the deserialized message is corrupted.
java.lang.ClassNotFoundException - Thrown if a class extracted from the message could not be found.
java.io.OptionalDataException - Thrown if unexpected data appeared on the input stream created for the deserialized message.

transportReceive

public void transportReceive(TransportInstance target,
                             TransportMessage msg)
Called when the transport layer has received a new message on a connection associated with this client. If a client holds several connections it is their responsibility to demultiplex incoming messages as appropriate. The target field may be used to determine which connection this message is associated with.
Specified by:
transportReceive in interface TransportClient
Parameters:
target - The TransportInstance reference that this message is targeted for. By assumption, the client is the owner of this instance.
msg - The TransportMessage that was received for this connection.

transportException

public void transportException(TransportInstance target,
                               TransportMessage msg,
                               TransportException error)
Called if the transport layer encounters an exception while attempting to send a previously queued message. If a client holds several connections it is their responsibility to demultiplex incoming messages as appropriate. The target field may be used to determine which connection this message is associated with.
Specified by:
transportException in interface TransportClient
Parameters:
target - The TransportInstance reference that the original message was sent from. By assumption, the client is the owner of this instance.
msg - The original TransportMessage that was queued to be sent to the remote host.
error - The TransportException which encapsulates the error encountered during transmission.

handlerException

public void handlerException(RequestSession session,
                             java.lang.Exception except,
                             RequestID id)
This method is required by RequestClient, but should never actually be called since we only issue RPC requests through our request session. We log an error message if this method IS called.
Specified by:
handlerException in interface RequestClient