org.objectweb.jonathan.resources.lib

Class JScheduler

Implemented Interfaces:
Scheduler

public class JScheduler
extends Object
implements Scheduler

Default scheduler implementation.

This implementation has exactly the same behaviour as the default Java scheduling.

This scheduler manages a pool of re-usable threads. The size of this pool may be customized in the bootstrap context.

Field Summary

protected ContextFactory
context_factory
boolean
verbose
Indicates whether warning message should be printed to stderr.

Constructor Summary

JScheduler(ContextFactory context_factory)
Returns a new scheduler.
JScheduler(int max_waiting, boolean verbose, ContextFactory context_factory)
Returns a new scheduler.

Method Summary

void
enter()
Causes a job "escaped" from the scheduler to be re-admitted in the set of jobs managed by the target scheduler.
void
escape()
Causes the calling job to be removed from the set of jobs managed by the target scheduler.
Job
getCurrent()
Returns the currently executing job (the job performing the call).
Job
newJob()
Returns a new job created by the scheduler.
void
notify(Object lock)
Unblocks a job waiting on the lock.
void
notifyAll(Object lock)
Unblocks all jobs waiting on the lock.
void
wait(Object lock)
Blocks the calling job until the notify or notifyAll method is called providing the same lock identifier.
void
wait(Object lock, long millis)
Blocks the calling job until the notify or notifyAll method is called providing the same lock identifier.
void
yield()
Calling this method gives the opportunity to the scheduler to re-schedule the currently executing jobs.

Field Details

context_factory

protected ContextFactory context_factory


verbose

public boolean verbose
Indicates whether warning message should be printed to stderr.

This value is defined under the name "/jonathan/JScheduler/verbose" in the bootstrap context.

This variable is not used in the current implementation.

Constructor Details

JScheduler

public JScheduler(ContextFactory context_factory)
Returns a new scheduler.

Parameters:
context_factory - a context factory.


JScheduler

public JScheduler(int max_waiting,
                  boolean verbose,
                  ContextFactory context_factory)
Returns a new scheduler.

Parameters:
max_waiting - maximum number of idle threads
verbose - indicates whether warning messsages should be output on stderr.
context_factory - a context factory.

Method Details

enter

public void enter()
Causes a job "escaped" from the scheduler to be re-admitted in the set of jobs managed by the target scheduler.

This implementation has nothing to do.

Specified by:
enter in interface Scheduler


escape

public void escape()
Causes the calling job to be removed from the set of jobs managed by the target scheduler. It is necessary to call this method before every possibly blocking method so that the scheduler can give a chance to run to another job.

This implementation has nothing to do.

Specified by:
escape in interface Scheduler


getCurrent

public Job getCurrent()
Returns the currently executing job (the job performing the call).
Specified by:
getCurrent in interface Scheduler

Returns:
the currently executing job.


newJob

public Job newJob()
Returns a new job created by the scheduler.
Specified by:
newJob in interface Scheduler

Returns:
a new job created by the scheduler.


notify

public void notify(Object lock)
Unblocks a job waiting on the lock.

This implementation calls the standard notify() method on the provided lock.

Specified by:
notify in interface Scheduler

Parameters:
lock - the lock identifier.


notifyAll

public void notifyAll(Object lock)
Unblocks all jobs waiting on the lock.

This implementation calls the standard notifyAll() method on the provided lock.

Specified by:
notifyAll in interface Scheduler

Parameters:
lock - the lock identifier.


wait

public void wait(Object lock)
            throws InterruptedException
Blocks the calling job until the notify or notifyAll method is called providing the same lock identifier.

This implementation calls the standard wait() method on the provided lock.

Specified by:
wait in interface Scheduler

Parameters:
lock - the lock identifier.


wait

public void wait(Object lock,
                 long millis)
            throws InterruptedException
Blocks the calling job until the notify or notifyAll method is called providing the same lock identifier.

This implementation calls the standard wait() method on the provided lock.

Specified by:
wait in interface Scheduler

Parameters:
lock - the lock identifier.


yield

public void yield()
Calling this method gives the opportunity to the scheduler to re-schedule the currently executing jobs.

This implementation calls the static yield() method on the Thread class.

Specified by:
yield in interface Scheduler