uwcse.location
Class LocationService

java.lang.Object
  |
  +--com.intel.research.rain.Service
        |
        +--uwcse.location.LocationService
All Implemented Interfaces:
MessageHandler
Direct Known Subclasses:
FuseSimDisplay, FusionClientService, FusionService, MeasurementLogger

public abstract class LocationService
extends Service

The abstract class to be extended by runnable Location Services.

Version:
$Revision: 1.19 $
Author:
Jeffrey Hightower

Nested Class Summary
 class LocationService.RediscoverServices
          A task to rediscover a set of services.
 
Field Summary
protected static String CONFIG_FILENAME
           
protected static String MESSAGE_ELEMENT
           
protected static String MESSAGE_EXTENSION
           
protected static String RPC_ELEMENT
           
protected static String RPC_EXCEPTION_ELEMENT
           
protected static String RPC_EXTENSION
           
protected static String RPC_RESULT_ELEMENT
           
 
Constructor Summary
LocationService()
          Construct a new LocationService.
 
Method Summary
static void addObject(Message m, String tagName, Object o)
          This static utility method pickles the Object o into a Rain message under the given XML tagName.
 LocationRpcResult callLocationRpc(ServiceID id, LocationRpc rpc, long timeout)
          A helper routine to execute a remote procedure call on the service with the given ServiceID and block until we receive result or an exception.
static long correctedTimeMillis()
          Get the current value of the system clock with a correction applied by the Ntp server.
static Object getObject(Message m, String tagName)
          This static helper method unpickles and extracts an Object from a Rain message under the given XML tagName.
static long getSysclockError()
          Get the number of milliseconds of error in our system clock versus the Ntp server.
protected  void handleTerminalCommand(String cmd)
          This routine is called to process command strings captured by runTerminalCommandLoop.
 void multicastLocationMsg(Collection serviceIDs, LocationMsg msg)
          A helper routine to send a LocationMsg asynchronously to all the services in given Collection of ServiceIDs.
 void multicastLocationMsgs(Collection serviceIDs, Collection msgs)
          A helper routine to send a Collection of LocationMsgs asynchronously to all the services in given Collection of ServiceIDs.
protected  void processLocationMsg(ServiceID from, LocationMsg locationMsg)
          Catch LocationMsgs which are not handled by any extending classes or multimethods.
protected  LocationRpcResult processLocationRpc(ServiceID from, LocationRpc rpc)
          Catch LocationRpc requests which are not handled by any extending classes or multimethods and throw an exception back to the sender.
 void runTerminalCommandLoop()
          Run the terminal command reader to process location service terminal commands.
 void sendLocationMsg(ServiceID to, LocationMsg msg)
          A helper routine to send a LocationMsg asynchronously to the given ServiceID.
 void sendLocationMsgs(ServiceID to, Collection msgs)
          A helper routine to send a Collection of independent LocationMsgs to the given ServiceID.
 void setDescription(Element description)
          Overridden to insert subclasses' descriptions inside the structured registration hierarchy before registering with discovery.
protected  void withdraw()
          Supplement the inherited behavior to shutdown the Ntp query timer when withdrawing from Rain.
 
Methods inherited from class com.intel.research.rain.Service
getDaemon, getDispatcher, getServiceID, process, receive, setDaemon
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_EXTENSION

protected static final String MESSAGE_EXTENSION

MESSAGE_ELEMENT

protected static final String MESSAGE_ELEMENT

RPC_EXTENSION

protected static final String RPC_EXTENSION

RPC_ELEMENT

protected static final String RPC_ELEMENT

RPC_RESULT_ELEMENT

protected static final String RPC_RESULT_ELEMENT

RPC_EXCEPTION_ELEMENT

protected static final String RPC_EXCEPTION_ELEMENT

CONFIG_FILENAME

protected static final String CONFIG_FILENAME
Constructor Detail

LocationService

public LocationService()
                throws RainException,
                       LocationException
Construct a new LocationService. Ntp synchronization information is obtained if specified in the runtime definitions.

Throws:
RainException
LocationException
Method Detail

setDescription

public void setDescription(Element description)
Overridden to insert subclasses' descriptions inside the structured registration hierarchy before registering with discovery.

Overrides:
setDescription in class Service

processLocationMsg

protected void processLocationMsg(ServiceID from,
                                  LocationMsg locationMsg)
Catch LocationMsgs which are not handled by any extending classes or multimethods.


processLocationRpc

protected LocationRpcResult processLocationRpc(ServiceID from,
                                               LocationRpc rpc)
                                        throws Exception
Catch LocationRpc requests which are not handled by any extending classes or multimethods and throw an exception back to the sender.

Throws:
Exception

callLocationRpc

public final LocationRpcResult callLocationRpc(ServiceID id,
                                               LocationRpc rpc,
                                               long timeout)
                                        throws LocationRpcException
A helper routine to execute a remote procedure call on the service with the given ServiceID and block until we receive result or an exception. The ServiceID and reqMsg must not be null.

Parameters:
rpc - the remote procedure call to run
timeout - the timeout out in milliseconds to wait for a reply after which an exception will be thorwn
Returns:
the RPC result unless an exception is thrown on the remote service
Throws:
LocationRpcException - when an exception is thrown by the remote service. The cause is the exception thrown on the remote service.
See Also:
Throwable.getCause()

sendLocationMsg

public final void sendLocationMsg(ServiceID to,
                                  LocationMsg msg)
                           throws RainException
A helper routine to send a LocationMsg asynchronously to the given ServiceID. The service ID and msg must not be null.

Throws:
RainException
See Also:
multicastLocationMsg(Collection,LocationMsg), sendLocationMsgs(ServiceID,Collection), multicastLocationMsgs(Collection,Collection)

multicastLocationMsg

public final void multicastLocationMsg(Collection serviceIDs,
                                       LocationMsg msg)
                                throws RainException
A helper routine to send a LocationMsg asynchronously to all the services in given Collection of ServiceIDs. This method behaves similarly to calling sendLocationMsg() in a loop iterating over serviceIDs.

Throws:
RainException
See Also:
sendLocationMsg(ServiceID,LocationMsg), sendLocationMsgs(ServiceID,Collection), multicastLocationMsgs(Collection,Collection)

sendLocationMsgs

public final void sendLocationMsgs(ServiceID to,
                                   Collection msgs)
                            throws RainException
A helper routine to send a Collection of independent LocationMsgs to the given ServiceID. This method behaves similarly to calling sendLocationMsg() in a loop iterating over msgs. Msgs may be delivered to the remote service in arbitrary order.

Throws:
RainException
See Also:
sendLocationMsg(ServiceID,LocationMsg), multicastLocationMsg(Collection,LocationMsg), multicastLocationMsgs(Collection,Collection)

multicastLocationMsgs

public final void multicastLocationMsgs(Collection serviceIDs,
                                        Collection msgs)
                                 throws RainException
A helper routine to send a Collection of LocationMsgs asynchronously to all the services in given Collection of ServiceIDs. This method behaves similarly to calling sendLocationMsg() in a set of nested loops iterating over serviceIDs and msgs. Msgs may be delivered to each service in arbitrary and possibly different order.

Throws:
RainException
See Also:
sendLocationMsg(ServiceID,LocationMsg), multicastLocationMsg(Collection,LocationMsg), sendLocationMsgs(ServiceID,Collection)

addObject

public static void addObject(Message m,
                             String tagName,
                             Object o)
This static utility method pickles the Object o into a Rain message under the given XML tagName.


getObject

public static Object getObject(Message m,
                               String tagName)
This static helper method unpickles and extracts an Object from a Rain message under the given XML tagName.

Returns:
An Object extracted from the given tagName in the message or null if no such tagName or object is found or an error occurs.

runTerminalCommandLoop

public final void runTerminalCommandLoop()
                                  throws IOException
Run the terminal command reader to process location service terminal commands. This routine does not return until 'quit' (case insensitive) is read. This routine calls handleTerminalCommand(String) for all input except 'quit'

Throws:
IOException
See Also:
handleTerminalCommand(String)

correctedTimeMillis

public static final long correctedTimeMillis()
Get the current value of the system clock with a correction applied by the Ntp server.

See Also:
System.currentTimeMillis()

getSysclockError

public static final long getSysclockError()
Get the number of milliseconds of error in our system clock versus the Ntp server.

Returns:
the long offset in milliseconds of the system time versus the Ntp server's time

handleTerminalCommand

protected void handleTerminalCommand(String cmd)
This routine is called to process command strings captured by runTerminalCommandLoop. Classes extending LocationService may handle any command strings they wish except 'quit' (case insensitive) is a reserved command that causes the shell to exit.

See Also:
runTerminalCommandLoop()

withdraw

protected void withdraw()
Supplement the inherited behavior to shutdown the Ntp query timer when withdrawing from Rain.

Overrides:
withdraw in class Service


This documentation is for the Location Stack v0.7. The latest distribution, the documentation, and the list of contributors to the Location Stack can always be found at http://portolano.cs.washington.edu/projects/location/

© Copyright 2003 University of Washington CSE