com.sun.sgs.impl.kernel
Class TaskSchedulerImpl

java.lang.Object
  extended by com.sun.sgs.impl.kernel.TaskSchedulerImpl
All Implemented Interfaces:
TaskScheduler

final class TaskSchedulerImpl
extends Object
implements TaskScheduler

Package-private implementation of TaskScheduler that is used by the system scheduling and running all non-transactional, arbitrary-length tasks. This is an intentionally simple implementation that uses a backing Executor instead of a SchedulerQueue until there is better understanding of what (if any) custom scheduling behavior will help these kinds of tasks.

This class supports the following configuration properties:

Property: "com.sun.sgs.impl.kernel.task.threads"
Default: "4"
The number of initial threads used to process non-transactional tasks.

FIXME: the profiling code needs a way to learn about the thread count from this scheduler separately from the transaction pool. When this gets added, this class should start tracking thread counts.


Field Summary
static String CONSUMER_THREADS_PROPERTY
          The property used to define the default number of initial consumer threads.
static String DEFAULT_CONSUMER_THREADS
          The default number of initial consumer threads.
 
Constructor Summary
TaskSchedulerImpl(Properties properties, ProfileCollectorHandle profileCollectorHandle)
          Creates an instance of TaskSchedulerImpl.
 
Method Summary
 TaskQueue createTaskQueue()
          Creates a new TaskQueue to use in scheduling dependent tasks.
 TaskReservation reserveTask(KernelRunnable task, Identity owner)
          Reserves the ability to run the given task.
 TaskReservation reserveTask(KernelRunnable task, Identity owner, long startTime)
          Reserves the ability to run the given task at a specified point in the future.
 RecurringTaskHandle scheduleRecurringTask(KernelRunnable task, Identity owner, long startTime, long period)
          Schedules a task to start running at a specified point in the future, and continuing running on a regular period starting from that initial point.
 void scheduleTask(KernelRunnable task, Identity owner)
          Schedules a task to run as soon as possible based on the specific scheduler implementation.
 void scheduleTask(KernelRunnable task, Identity owner, long startTime)
          Schedules a task to run at a specified point in the future.
(package private)  void setContext(KernelContext kernelContext)
          Package-private method used to set the context being used by the kernel.
(package private)  void shutdown()
          Tells this scheduler to shutdown.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSUMER_THREADS_PROPERTY

public static final String CONSUMER_THREADS_PROPERTY
The property used to define the default number of initial consumer threads.

See Also:
Constant Field Values

DEFAULT_CONSUMER_THREADS

public static final String DEFAULT_CONSUMER_THREADS
The default number of initial consumer threads.

See Also:
Constant Field Values
Constructor Detail

TaskSchedulerImpl

TaskSchedulerImpl(Properties properties,
                  ProfileCollectorHandle profileCollectorHandle)
            throws Exception
Creates an instance of TaskSchedulerImpl.

Parameters:
properties - the Properties for the system
profileCollectorHandle - the ProfileCollectorHandler used to manage collection of per-task profiling data
Throws:
Exception - if there is any failure creating the scheduler
Method Detail

setContext

void setContext(KernelContext kernelContext)
Package-private method used to set the context being used by the kernel.

Parameters:
kernelContext - the KernelContext for this scheduler

reserveTask

public TaskReservation reserveTask(KernelRunnable task,
                                   Identity owner)
Reserves the ability to run the given task.

Specified by:
reserveTask in interface TaskScheduler
Parameters:
task - the KernelRunnable to execute
owner - the entity on who's behalf this task is run
Returns:
a TaskReservation for the task

reserveTask

public TaskReservation reserveTask(KernelRunnable task,
                                   Identity owner,
                                   long startTime)
Reserves the ability to run the given task at a specified point in the future. The startTime is a value in milliseconds measured from 1/1/1970.

Specified by:
reserveTask in interface TaskScheduler
Parameters:
task - the KernelRunnable to execute
owner - the entity on who's behalf this task is run
startTime - the time at which to start the task
Returns:
a TaskReservation for the task

scheduleTask

public void scheduleTask(KernelRunnable task,
                         Identity owner)
Schedules a task to run as soon as possible based on the specific scheduler implementation.

Specified by:
scheduleTask in interface TaskScheduler
Parameters:
task - the KernelRunnable to execute
owner - the entity on who's behalf this task is run

scheduleTask

public void scheduleTask(KernelRunnable task,
                         Identity owner,
                         long startTime)
Schedules a task to run at a specified point in the future. The startTime is a value in milliseconds measured from 1/1/1970. If the starting time has already passed, then the task is run immediately.

Specified by:
scheduleTask in interface TaskScheduler
Parameters:
task - the KernelRunnable to execute
owner - the entity on who's behalf this task is run
startTime - the time at which to start the task

scheduleRecurringTask

public RecurringTaskHandle scheduleRecurringTask(KernelRunnable task,
                                                 Identity owner,
                                                 long startTime,
                                                 long period)
Schedules a task to start running at a specified point in the future, and continuing running on a regular period starting from that initial point. Unlike the other scheduleTask methods, this method will never fail to accept to the task so there is no need for a reservation. Note, however, that the task will not actually start executing until start is called on the returned RecurringTaskHandle.

At each execution point the scheduler will make a best effort to run the task, but based on available resources scheduling the task may fail. Regardless, the scheduler will always try again at the next execution time.

Specified by:
scheduleRecurringTask in interface TaskScheduler
Parameters:
task - the KernelRunnable to execute
owner - the entity on who's behalf this task is run
startTime - the time at which to start the task
period - the length of time in milliseconds between each recurring task execution
Returns:
a RecurringTaskHandle used to manage the recurring task

createTaskQueue

public TaskQueue createTaskQueue()
Creates a new TaskQueue to use in scheduling dependent tasks. Once a given task has completed the next task will be submitted to the scheduler to run.

Specified by:
createTaskQueue in interface TaskScheduler
Returns:
a new TaskQueue

shutdown

void shutdown()
Tells this scheduler to shutdown.


RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved