com.faunos.util.cc
Class CompoundScheduler

java.lang.Object
  extended by com.faunos.util.cc.CompoundScheduler
All Implemented Interfaces:
Scheduler

public class CompoundScheduler
extends Object
implements Scheduler

A contraption for packing a bunch of Schedulers together as one scheduler. This allows running a group of schedulers in a same thread.

Author:
Babak Farhang

Field Summary
protected  List<Scheduler> schedulers
          The internal list of schedulers.
 
Constructor Summary
CompoundScheduler()
           
 
Method Summary
 void addScheduler(Scheduler scheduler)
          Adds the given scheduler.
 int inProgressCount()
          Returns the aggregate number of tasks in progress as computed in the last invocation of the schedule() method.
protected  void removeSchedulers(Collection<Scheduler> deadSchedulers)
          Callback invoked by the schedule() method.
 int schedule(ExecutorService service)
          Schedules background tasks on the given service and returns the aggregate number of tasks scheduled.
 int size()
          Returns the number of internal schedulers that remain in this compound instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schedulers

protected final List<Scheduler> schedulers
The internal list of schedulers. A subclass accessing this field must synchronize on the instance itself. E.g.
      synchronized (this) {
          if (schedulers.isEmpty())
              ..
      }
 

Constructor Detail

CompoundScheduler

public CompoundScheduler()
Method Detail

inProgressCount

public int inProgressCount()
Returns the aggregate number of tasks in progress as computed in the last invocation of the schedule() method.

Specified by:
inProgressCount in interface Scheduler

schedule

public int schedule(ExecutorService service)
Schedules background tasks on the given service and returns the aggregate number of tasks scheduled. This scheduler never returns -1.

Specified by:
schedule in interface Scheduler
Returns:
the number of new tasks (possibly zero) scheduled on this invocation, or -1 if this scheduler will not schedule any more tasks

addScheduler

public void addScheduler(Scheduler scheduler)
Adds the given scheduler. The scheduler is assumed not to be already added; o.w. the behavior is undefined (haven't thought about it).


size

public int size()
Returns the number of internal schedulers that remain in this compound instance.


removeSchedulers

protected void removeSchedulers(Collection<Scheduler> deadSchedulers)
Callback invoked by the schedule() method.

Parameters:
deadSchedulers - the set of schedulers that returned -1


SourceForge.net Logo