NASA World Wind

gov.nasa.worldwind.util
Class BasicScheduledTaskService

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.util.BasicScheduledTaskService
All Implemented Interfaces:
AVList, MessageListener, ScheduledTaskService, WWObject, PropertyChangeListener, Thread.UncaughtExceptionHandler, EventListener

public class BasicScheduledTaskService
extends WWObjectImpl
implements ScheduledTaskService, Thread.UncaughtExceptionHandler

A service to execute tasks periodically, or after a delay.


Nested Class Summary
protected  class BasicScheduledTaskService.ScheduledTaskExecutor
          Custom executor to run tasks.
 
Field Summary
protected  ConcurrentLinkedQueue<Runnable> activeTasks
          Tasks currently running.
protected static int DEFAULT_POOL_SIZE
          Default thread pool size.
protected  BasicScheduledTaskService.ScheduledTaskExecutor executor
          Executor for running tasks.
protected static String IDLE_THREAD_NAME_PREFIX
          Name assigned to idle threads.
protected static String RUNNING_THREAD_NAME_PREFIX
          Name assigned to active threads.
 
Constructor Summary
BasicScheduledTaskService()
          Create a new scheduled task service.
 
Method Summary
 ScheduledFuture<?> addRepeatingTask(Runnable runnable, long initialDelay, long period, TimeUnit timeunit)
          Enqueues a task to run periodically.
 ScheduledFuture<?> addScheduledTask(Runnable runnable, long delay, TimeUnit timeunit)
          Enqueues a task to run after a delay.
 void addTask(Runnable runnable)
          Enqueues a task to run.
 void shutdown(boolean immediately)
          Shut down the service.
 void uncaughtException(Thread thread, Throwable throwable)
           
 
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
 
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 

Field Detail

activeTasks

protected ConcurrentLinkedQueue<Runnable> activeTasks
Tasks currently running.


DEFAULT_POOL_SIZE

protected static final int DEFAULT_POOL_SIZE
Default thread pool size.

See Also:
Constant Field Values

executor

protected BasicScheduledTaskService.ScheduledTaskExecutor executor
Executor for running tasks.


IDLE_THREAD_NAME_PREFIX

protected static final String IDLE_THREAD_NAME_PREFIX
Name assigned to idle threads.


RUNNING_THREAD_NAME_PREFIX

protected static final String RUNNING_THREAD_NAME_PREFIX
Name assigned to active threads.

Constructor Detail

BasicScheduledTaskService

public BasicScheduledTaskService()
Create a new scheduled task service. The thread pool size is from the WorldWind configuration file property AVKey.TASK_POOL_SIZE.

Method Detail

addRepeatingTask

public ScheduledFuture<?> addRepeatingTask(Runnable runnable,
                                           long initialDelay,
                                           long period,
                                           TimeUnit timeunit)
Enqueues a task to run periodically. This method follows the same semantics as ScheduledExecutorService.scheduleAtFixedRate(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit). Duplicate tasks are ignored.

Specified by:
addRepeatingTask in interface ScheduledTaskService
Parameters:
runnable - the task to add.
initialDelay - delay before the first execution of the task. timeUnit determines the units of the value.
period - interval between executions of the task. timeUnit determines the units of the value.
timeunit - time unit of initialDelay and period.
Returns:
a ScheduledFuture that can be used to get the result of the task, or cancel the task, or null if the task was not enqueued.

addScheduledTask

public ScheduledFuture<?> addScheduledTask(Runnable runnable,
                                           long delay,
                                           TimeUnit timeunit)
Enqueues a task to run after a delay. Duplicate tasks are ignored.

Specified by:
addScheduledTask in interface ScheduledTaskService
Parameters:
runnable - the task to add.
delay - delay before execution of the task. timeUnit determines the units of the value.
timeunit - time unit of initialDelay and period.
Returns:
a ScheduledFuture that can be used to get the result of the task, or cancel the task, or null if the task was not enqueued.

addTask

public void addTask(Runnable runnable)
Enqueues a task to run. Duplicate tasks are ignored.

Specified by:
addTask in interface ScheduledTaskService
Parameters:
runnable - the task to add

shutdown

public void shutdown(boolean immediately)
Description copied from interface: ScheduledTaskService
Shut down the service. If the immediate parameter is true, the service will attempt to stop all active tasks, and will not begin work on any other tasks in the queue. Otherwise, the service will complete all tasks in the work queue, but will not accept any new tasks.

Specified by:
shutdown in interface ScheduledTaskService
Parameters:
immediately - true to shutdown immediately.

uncaughtException

public void uncaughtException(Thread thread,
                              Throwable throwable)
Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler

NASA World Wind