SunSPOT API V6.0


com.sun.spot.service
Class TaskManager

java.lang.Object
  extended by com.sun.spot.resources.Resource
      extended by com.sun.spot.service.TaskManager
All Implemented Interfaces:
IResource, IService, Runnable

public class TaskManager
extends Resource
implements IService, Runnable

TaskManager schedules and executes all current Tasks, including Conditions. Please see the javadoc for Task for more details.

Author:
Ron Goldman

Field Summary
 
Fields inherited from interface com.sun.spot.service.IService
PAUSED, PAUSING, READY, RESUMING, RUNNING, STARTING, STOPPED, STOPPING
 
Constructor Summary
protected TaskManager()
           
 
Method Summary
 Task[] getAllTasks()
          Return an array of all Tasks scheduled to be run.
 boolean getEnabled()
          Return whether service is started automatically on reboot.
static TaskManager getInstance()
          Get the singleton instance of TaskManager.
 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.
 void removeAllTasks()
          Remove all Tasks from the list of Tasks scheduled to be run.
 boolean resume()
          Resume the service, and return whether successful.
 void run()
          Internal method.
static void schedule(Task t)
          Schedule a Task to run.
static void schedule(Task t, long period)
          Schedule a Task to run.
 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.
static void unschedule(Task t)
          Remove a Task from the list of Tasks scheduled to be run.
 
Methods inherited from class com.sun.spot.resources.Resource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 

Constructor Detail

TaskManager

protected TaskManager()
Method Detail

getInstance

public static TaskManager getInstance()
Get the singleton instance of TaskManager.

Returns:
the TaskManager instance

schedule

public static void schedule(Task t)
Schedule a Task to run. The task specifies when it is to be run.

Parameters:
t - the Task to schedule

schedule

public static void schedule(Task t,
                            long period)
Schedule a Task to run. The task specifies when it is to be run, but that time may be adjusted by a specified slop period in order to have it run at the same time as another task. This adjustment is so that the SPOT will be more likely to be able to deep sleep. (Currently not implemented)

Parameters:
t - the Task to schedule
period - the amount of time (in milliseconds) that the schedule may be adjusted

unschedule

public static void unschedule(Task t)
Remove a Task from the list of Tasks scheduled to be run.

Parameters:
t - the Task to remove

removeAllTasks

public void removeAllTasks()
Remove all Tasks from the list of Tasks scheduled to be run.


getAllTasks

public Task[] getAllTasks()
Return an array of all Tasks scheduled to be run.

Returns:
an array of all Tasks scheduled to be run

run

public void run()
Internal method. Do not call explicitly.

Specified by:
run in interface Runnable
See Also:
Thread.run()

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

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

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

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

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.

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

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

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

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

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

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.