org.amino.scheduler.internal
Class AbstractScheduler

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by org.amino.scheduler.internal.AbstractScheduler
All Implemented Interfaces:
java.util.concurrent.Executor, java.util.concurrent.ExecutorService, Scheduler
Direct Known Subclasses:
WorkStealingScheduler

public abstract class AbstractScheduler
extends java.util.concurrent.AbstractExecutorService
implements Scheduler

Abstract class for Amino schedulers.


Nested Class Summary
protected  class AbstractScheduler.WorkThread
           
 
Constructor Summary
AbstractScheduler(int numWorkers)
           
 
Method Summary
protected abstract  void addWork(java.lang.Runnable command)
          Submit a new work item.
 boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
          
static int defaultNumberOfWorkers()
           
 void execute(java.lang.Runnable command)
          
protected abstract  java.util.List<java.lang.Runnable> getOutstandingWork()
           
 java.util.concurrent.RejectedExecutionHandler getRejectedExecutionHandler()
          Get handler used for rejected executions.
protected abstract  java.lang.Runnable getWork(int id)
          Get work item identified by id.
 boolean isShutdown()
          
 boolean isTerminated()
          
 int numWorkers()
          Get number of workers.
static void setNumberOfWorkers(int workers)
           
 void setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler handler)
          Set handler.
 void shutdown()
           
 java.util.List<java.lang.Runnable> shutdownNow()
          
protected  void signalNewWork()
          Wakeup waiting workers when new workload arrived.
protected  void startWorkers()
          start to execute all workers.
protected  void waitNewWork(int id)
          Wait for new workload.
 
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.ExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
 

Constructor Detail

AbstractScheduler

public AbstractScheduler(int numWorkers)
Parameters:
numWorkers - maximum number of worker threads to create.
Method Detail

getWork

protected abstract java.lang.Runnable getWork(int id)
Get work item identified by id.

Parameters:
id - id for work item
Returns:
Runnable method

waitNewWork

protected void waitNewWork(int id)
Wait for new workload.

Parameters:
id - thread id

signalNewWork

protected void signalNewWork()
Wakeup waiting workers when new workload arrived.


startWorkers

protected void startWorkers()
start to execute all workers.


numWorkers

public int numWorkers()
Get number of workers.

Specified by:
numWorkers in interface Scheduler
Returns:
number of workers.

isTerminated

public boolean isTerminated()

Specified by:
isTerminated in interface java.util.concurrent.ExecutorService

awaitTermination

public boolean awaitTermination(long timeout,
                                java.util.concurrent.TimeUnit unit)
                         throws java.lang.InterruptedException

Specified by:
awaitTermination in interface java.util.concurrent.ExecutorService
Throws:
java.lang.InterruptedException

isShutdown

public boolean isShutdown()

Specified by:
isShutdown in interface java.util.concurrent.ExecutorService

shutdown

public void shutdown()
Specified by:
shutdown in interface java.util.concurrent.ExecutorService

getOutstandingWork

protected abstract java.util.List<java.lang.Runnable> getOutstandingWork()
Returns:
List of remaining work items that have not yet finished running.

shutdownNow

public java.util.List<java.lang.Runnable> shutdownNow()

Specified by:
shutdownNow in interface java.util.concurrent.ExecutorService

getRejectedExecutionHandler

public java.util.concurrent.RejectedExecutionHandler getRejectedExecutionHandler()
Description copied from interface: Scheduler
Get handler used for rejected executions.

Specified by:
getRejectedExecutionHandler in interface Scheduler
Returns:
handler for rejected executions.

setRejectedExecutionHandler

public void setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler handler)
Description copied from interface: Scheduler
Set handler.

Specified by:
setRejectedExecutionHandler in interface Scheduler
Parameters:
handler - Rejected execution handler.

addWork

protected abstract void addWork(java.lang.Runnable command)
Submit a new work item.

Parameters:
command - work item to run

execute

public void execute(java.lang.Runnable command)

Specified by:
execute in interface java.util.concurrent.Executor

defaultNumberOfWorkers

public static int defaultNumberOfWorkers()
Returns:
default number of worker threads.

setNumberOfWorkers

public static void setNumberOfWorkers(int workers)


Copyright © 2008. All Rights Reserved.