SunSPOT API V5.0


com.sun.spot.service
Interface IService

All Known Subinterfaces:
IOTACommandServer, IRoutingManager, ISpotRadioHelper
All Known Implementing Classes:
AODVManager, BasicService, EDemoBoardBlink, Heartbeat, LowPan, LowPanSpotRadioHelper, LQRPManager, NetManagementServer, OTACommandServer, RadioPacketDispatcher, RoutingPolicyManager, SingleHopManager, SpotBlink

public interface IService

Basic interface supported by all SPOT services so they can be started & stopped from SPOT applications. The intent is that applications can get a long-lived reference to a service and then use that reference to change the state of the service, including stopping the service and later restarting it. The lifecycle for a service is:

  1. Create service using a constructor or factory method. May be done automatically by system code. (Service dependent)
  2. If necessary initialize the service by calling methods unique to this service. (Service dependent)
  3. Obtain a reference to the service. (Service dependent)
  4. Start the service running via start() method. (All services)
  5. Check the status of the service via getStatus() or isRunning(). (All services)
  6. Initiate requests by calling methods unique to this service. (Service dependent)
  7. Cause the service to suspend activity via pause(). (All services)
  8. Cause the service to resume activity via resume(). (All services)
  9. Stop the service via stop(), killing all threads and closing any open IO resources. (All services)
  10. Restart the service running via start(). (All services)
  11. repeat any of steps 4-9.

Author:
Ron Goldman

Field Summary
static int PAUSED
          Service is currently paused.
static int PAUSING
          Service is currently in the process of pausing.
static int READY
          Service is ready to be called.
static int RESUMING
          Service is currently in the process of resuming.
static int RUNNING
          Service is currently running.
static int STARTING
          Service is currently in the process of starting up.
static int STOPPED
          Service is currently stopped, i.e. not running.
static int STOPPING
          Service is currently in the process of stopping.
 
Method Summary
 boolean getEnabled()
          Return whether service is started automatically on reboot.
 String getServiceName()
          Return the name of this service.
 int getStatus()
          Return the current status of this service.
 boolean isRunning()
          Return whether the service is currently running.
 boolean pause()
          Pause the service, and return whether successful.
 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.
 

Field Detail

STOPPED

static final int STOPPED
Service is currently stopped, i.e. not running.

See Also:
Constant Field Values

STARTING

static final int STARTING
Service is currently in the process of starting up.

See Also:
Constant Field Values

RUNNING

static final int RUNNING
Service is currently running.

See Also:
Constant Field Values

PAUSED

static final int PAUSED
Service is currently paused.

See Also:
Constant Field Values

STOPPING

static final int STOPPING
Service is currently in the process of stopping.

See Also:
Constant Field Values

PAUSING

static final int PAUSING
Service is currently in the process of pausing.

See Also:
Constant Field Values

RESUMING

static final int RESUMING
Service is currently in the process of resuming.

See Also:
Constant Field Values

READY

static final int READY
Service is ready to be called. Used for services that do not run in their own threads.

See Also:
Constant Field Values
Method Detail

start

boolean start()
Start the service, and return whether successful.

Returns:
true if the service was successfully started

stop

boolean stop()
Stop the service, and return whether successful. Stops all running threads. Closes any open IO connections.

Returns:
true if the service was successfully stopped

pause

boolean pause()
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().

Returns:
true if the service was successfully paused

resume

boolean resume()
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().

Returns:
true if the service was successfully resumed

getStatus

int getStatus()
Return the current status of this service.

Returns:
the current status of this service, e.g. STOPPED, STARTING, RUNNING, PAUSED, STOPPING, etc.

isRunning

boolean isRunning()
Return whether the service is currently running.

Returns:
true if the service is currently running

getServiceName

String getServiceName()
Return the name of this service.

Returns:
the name of this service

setServiceName

void setServiceName(String who)
Assign a name to this service. For some fixed services this may not apply and any new name will just be ignored.

Parameters:
who - the name for this service

getEnabled

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

Returns:
true if the service is started automatically on reboot

setEnabled

void setEnabled(boolean enable)
Enable/disable whether service is started automatically. This may not apply to some services and calls to setEnabled() may be ignored.

Parameters:
enable - true if the service should be started automatically on reboot

SunSPOT API V5.0


Copyright � 2006-2008 Sun Microsystems, Inc. All Rights Reserved.