Jumpi v1.2.0

org.jumpi.impl.taskscheduler
Class TaskSchedulerImpl

java.lang.Object
  |
  +--org.jumpi.impl.taskscheduler.TaskSchedulerImpl
All Implemented Interfaces:
Component, Configurable, Manageable, java.lang.Runnable, TaskScheduler

public class TaskSchedulerImpl
extends java.lang.Object
implements java.lang.Runnable, TaskScheduler

A TaskSchedulerImpl implementation using an internal Thread pool to run concurrent Tasks.


Constructor Summary
TaskSchedulerImpl()
           
 
Method Summary
 void configure(java.lang.String name, Properties props)
           Configure the TaskSchedulerImpl.
 java.lang.String getName()
          Get the fully qualified name of the instance.
 void manage(Component root, Component parent, java.lang.String operation, java.util.Hashtable parameters)
          Perform a recursive management operation through the Jumpi component tree, using the parameters provided.
 void run()
           All thread pool threads call run() to take the next available tasks for running, and run them until the task is no longer schedulable.
 void schedule(Task task)
           Schedule the given Task to run as soon as possible, using one of the threads in the TaskSchedulerImpl's internal thread pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskSchedulerImpl

public TaskSchedulerImpl()
Method Detail

configure

public void configure(java.lang.String name,
                      Properties props)
               throws java.lang.Exception

Configure the TaskSchedulerImpl.

The following configuration attributes are defined:

Specified by:
configure in interface Configurable
Parameters:
name - the fully qualified instance name.
props - the read-only properties to configure the instance with.
Throws:
java.lang.Exception - when configuration is unsuccessful.
java.lang.IllegalArgumentException - if name or props are missing.

manage

public void manage(Component root,
                   Component parent,
                   java.lang.String operation,
                   java.util.Hashtable parameters)
            throws java.lang.Exception
Perform a recursive management operation through the Jumpi component tree, using the parameters provided.

The following management actions are handled:

Specified by:
manage in interface Manageable
Parameters:
root - the Jumpi instance at the root of the component tree.
parent - the immediate parent of the component.
operation - the operation.
parameters - the operation parameters.
Throws:
java.lang.Exception - if any failure to perform management occurs.
java.lang.IllegalArgumentException - when parameters are missing.

schedule

public void schedule(Task task)

Schedule the given Task to run as soon as possible, using one of the threads in the TaskSchedulerImpl's internal thread pool.

A Task is run as long as it is schedulable once a thread has been assigned to handle it. Even if the run method exits or exits through a runtime exception , the assigned thread re-runs the method.

A Task should never call schedule for itself from a synchronized block which shares a synchronization with isSchedulable(). This could cause deadlock.

Specified by:
schedule in interface TaskScheduler
Parameters:
task - the Task to schedule.
Throws:
java.lang.IllegalArgumentException - if task is null.
java.lang.IllegalStateException - if scheduler not started.

run

public void run()

All thread pool threads call run() to take the next available tasks for running, and run them until the task is no longer schedulable.

If a Task is long running, then the thread pool thread is taken out of the pool and allowed to run the task until completion. Threads for long running tasks exit after the task is no longer schedulable, and are not reclaimed to the thread pool.

Specified by:
run in interface java.lang.Runnable

getName

public java.lang.String getName()
Get the fully qualified name of the instance. Identical to the name used in configure.

Specified by:
getName in interface Configurable
Returns:
the fully qualified name of the instance.
See Also:
configure(java.lang.String, org.jumpi.spi.Properties)

Jumpi v1.2.0

Copyright © 2003, Peter Jonathan Klauser.