SunSPOT API V3.0


com.sun.spot.peripheral.radio.shrp
Class SingleHopManager

java.lang.Object
  extended by com.sun.spot.peripheral.radio.shrp.SingleHopManager
All Implemented Interfaces:
IRoutingManager, IService

public class SingleHopManager
extends Object
implements IRoutingManager

The single hop routing modules makes all nodes look like they are 1 hop away. If a route is invalidated 3 times, we throw a noRouteException, meaning a node is probably not actually 1 hop away. Since A RouteInfo object is never freed we must create one the first time it is requested. We then store that reference in a Hashtable. The next time it is requested, we returned the caches RouteInfo object. The intention is that this will minimize garbage collection, as well as serve as a sample for writing simple routing managers.

Author:
Pete St. Pierre

Field Summary
 
Fields inherited from interface com.sun.spot.service.IService
PAUSED, PAUSING, RESUMING, RUNNING, STARTING, STOPPED, STOPPING
 
Constructor Summary
SingleHopManager()
          Creates a new instance of SingleHopManager The SingleHopManager can be used by the LowPan layer to limit communications to nodes within a single radio hop away.
 
Method Summary
 void deregisterEventListener(IMHEventListener listener)
          deregisters a listener for routing messages.
 boolean findRoute(long address, RouteEventClient eventClient, Object uniqueKey)
          lookup a route to this address.
 boolean getEnabled()
          Return whether service is started automatically on reboot.
 RouteInfo getRouteInfo(long address)
          retrieve routing information for a destination address.
 String getServiceName()
          Return the name of this service.
 int getStatus()
          Return the current status of this service.
 void initialize(long ourAddress, ILowPan lowPanLayer)
          setup this routing manager for use.
 boolean invalidateRoute(long originator, long destination)
          Nodes are always 1 hop away.
 boolean isRunning()
          Return whether the service is currently running.
 boolean pause()
          Pause the service, and return whether successful.
 void registerEventListener(IMHEventListener listener)
          registers a listener for routing messages.
 boolean resume()
          Resume the service, and return whether successful.
 void setEnabled(boolean enable)
          Enable/disable whether service is started automatically.
 void setServiceName(String who)
          Assign a name to this service.
 boolean start()
          Start the service, and return whether successful.
 boolean stop()
          Stop the service, and return whether successful.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleHopManager

public SingleHopManager()
Creates a new instance of SingleHopManager The SingleHopManager can be used by the LowPan layer to limit communications to nodes within a single radio hop away.

Method Detail

findRoute

public boolean findRoute(long address,
                         RouteEventClient eventClient,
                         Object uniqueKey)
lookup a route to this address. The answer will always be that the destination address is exactly 1 hop away

Specified by:
findRoute in interface IRoutingManager
Parameters:
address - the destination address we are looking for
eventClient - client to be called back with the routing information
uniqueKey - a key that uniquely identifies this request/client
Returns:
always returns success

registerEventListener

public void registerEventListener(IMHEventListener listener)
registers a listener for routing messages. Single hop has no messages so this is a NO OP.

Specified by:
registerEventListener in interface IRoutingManager
Parameters:
listener - event listener for callbacks

deregisterEventListener

public void deregisterEventListener(IMHEventListener listener)
deregisters a listener for routing messages. Single hop has no messages so this is a NO OP.

Specified by:
deregisterEventListener in interface IRoutingManager
Parameters:
listener - the listener to remove

invalidateRoute

public boolean invalidateRoute(long originator,
                               long destination)
Nodes are always 1 hop away. This has no effect

Specified by:
invalidateRoute in interface IRoutingManager
Parameters:
originator - node that requested the route
destination - route destination address
Returns:
always returns true

initialize

public void initialize(long ourAddress,
                       ILowPan lowPanLayer)
setup this routing manager for use. No state needs to be initialized for the single hop routing mananger

Specified by:
initialize in interface IRoutingManager
Parameters:
ourAddress - address used by this LowPan layer
lowPanLayer - a reference to the lowpan layer

getRouteInfo

public RouteInfo getRouteInfo(long address)
retrieve routing information for a destination address. Answer is always that the address is one hop away.

Specified by:
getRouteInfo in interface IRoutingManager
Parameters:
address - destination address of route
Returns:
returns a route info object where nexthop is the destination and is 1 hop away

setServiceName

public void setServiceName(String who)
Description copied from interface: IService
Assign a name to this service. For some fixed services this may not apply and any new name will just be ignored.

Specified by:
setServiceName in interface IService
Parameters:
who - the name for this service

setEnabled

public void setEnabled(boolean enable)
Description copied from interface: IService
Enable/disable whether service is started automatically. This may not apply to some services and calls to setEnabled() may be ignored.

Specified by:
setEnabled in interface IService
Parameters:
enable - true if the service should be started automatically on reboot

stop

public boolean stop()
Description copied from interface: IService
Stop the service, and return whether successful. Stops all running threads. Closes any open IO connections.

Specified by:
stop in interface IService
Returns:
true if the service was successfully stopped

start

public boolean start()
Description copied from interface: IService
Start the service, and return whether successful.

Specified by:
start in interface IService
Returns:
true if the service was successfully started

resume

public boolean resume()
Description copied from interface: IService
Resume the service, and return whether successful. Picks up from state when service was paused. If there was no particular state associated with this service then resume() can be implemented by calling start().

Specified by:
resume in interface IService
Returns:
true if the service was successfully resumed

pause

public boolean pause()
Description copied from interface: IService
Pause the service, and return whether successful. Preserve any current state, but do not handle new requests. Any running threads should block or sleep. Any open IO connections may be kept open. If there is no particular state associated with this service then pause() can be implemented by calling stop().

Specified by:
pause in interface IService
Returns:
true if the service was successfully paused

isRunning

public boolean isRunning()
Description copied from interface: IService
Return whether the service is currently running.

Specified by:
isRunning in interface IService
Returns:
true if the service is currently running

getStatus

public int getStatus()
Description copied from interface: IService
Return the current status of this service.

Specified by:
getStatus in interface IService
Returns:
the current status of this service, e.g. STOPPED, STARTING, RUNNING, PAUSED, STOPPING, etc.

getServiceName

public String getServiceName()
Description copied from interface: IService
Return the name of this service.

Specified by:
getServiceName in interface IService
Returns:
the name of this service

getEnabled

public boolean getEnabled()
Description copied from interface: IService
Return whether service is started automatically on reboot. This may not apply to some services and for those services it will always return false.

Specified by:
getEnabled in interface IService
Returns:
true if the service is started automatically on reboot

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.