org.apache.jetspeed.aggregator.impl
Class WorkerMonitorImpl

java.lang.Object
  extended by org.apache.jetspeed.aggregator.impl.WorkerMonitorImpl
All Implemented Interfaces:
org.apache.jetspeed.aggregator.WorkerMonitor

public class WorkerMonitorImpl
extends Object
implements org.apache.jetspeed.aggregator.WorkerMonitor

The WorkerMonitor is responsible for dispatching jobs to workers It uses an Apache HTTPd configuration style of min/max/spare workers threads to throttle the rendering work. If jobs come in faster that processing, they are stored in a queue which is flushed periodically by a QueueMonitor.

Version:
$Id: WorkerMonitorImpl.java 591867 2007-11-05 02:20:06Z woonsan $
Author:
Raphaël Luta, David Sean Taylor

Nested Class Summary
(package private)  class WorkerMonitorImpl.RenderingJobTimeoutMonitor
           
 
Field Summary
static String ACCESS_CONTROL_CONTEXT_WORKER_ATTR
           
protected  WorkerMonitorImpl.RenderingJobTimeoutMonitor jobMonitor
          Renering Job Timeout monitor
protected static org.apache.commons.logging.Log log
          Commons logging
protected  int maxJobsPerWorker
          Maximum of job processed by a worker before being released
protected  int maxWorkers
          Maximum number of workers
protected  int minWorkers
          Minimum number of wokers to create
protected  org.apache.jetspeed.util.Queue queue
          Job queue
protected  int runningJobs
          Count of running jobs
protected static long sCount
          Static counters for identifying workers
protected  int spareWorkers
          Minimum amount of spare workers
protected  ThreadGroup tg
          The thread group used to group all worker threads
protected  Stack workers
          Stack containing currently idle workers
protected  List workersMonitored
          Workers to be monitored for timeout checking
 
Constructor Summary
WorkerMonitorImpl(int minWorkers, int maxWorkers, int spareWorkers, int maxJobsPerWorker)
           
 
Method Summary
protected  void addWorkers(int wCount)
          Create the request number of workers and add them to list of available workers.
 int getAvailableJobsCount()
          Returns a snapshot of the available jobs
 int getQueuedJobsCount()
           
 int getRunningJobsCount()
           
protected  org.apache.jetspeed.aggregator.Worker getWorker()
          Retrieves an idle worker
 void process(org.apache.jetspeed.aggregator.RenderingJob job)
          Assign a job to a worker and execute it or queue the job if no worker is available.
protected  void release(org.apache.jetspeed.aggregator.Worker worker)
          Put back the worker in the idle queue unless there are pending jobs and worker can still be committed to a new job before being released.
 void start()
           
 void stop()
           
 void waitForRenderingJobs(List renderingJobs)
          Wait for all rendering jobs in the collection to finish successfully or otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCESS_CONTROL_CONTEXT_WORKER_ATTR

public static final String ACCESS_CONTROL_CONTEXT_WORKER_ATTR

log

protected static final org.apache.commons.logging.Log log
Commons logging


sCount

protected static long sCount
Static counters for identifying workers


runningJobs

protected int runningJobs
Count of running jobs


minWorkers

protected int minWorkers
Minimum number of wokers to create


maxWorkers

protected int maxWorkers
Maximum number of workers


spareWorkers

protected int spareWorkers
Minimum amount of spare workers


maxJobsPerWorker

protected int maxJobsPerWorker
Maximum of job processed by a worker before being released


workers

protected Stack workers
Stack containing currently idle workers


tg

protected ThreadGroup tg
The thread group used to group all worker threads


queue

protected org.apache.jetspeed.util.Queue queue
Job queue


workersMonitored

protected List workersMonitored
Workers to be monitored for timeout checking


jobMonitor

protected WorkerMonitorImpl.RenderingJobTimeoutMonitor jobMonitor
Renering Job Timeout monitor

Constructor Detail

WorkerMonitorImpl

public WorkerMonitorImpl(int minWorkers,
                         int maxWorkers,
                         int spareWorkers,
                         int maxJobsPerWorker)
Method Detail

start

public void start()
Specified by:
start in interface org.apache.jetspeed.aggregator.WorkerMonitor

stop

public void stop()
Specified by:
stop in interface org.apache.jetspeed.aggregator.WorkerMonitor

addWorkers

protected void addWorkers(int wCount)
Create the request number of workers and add them to list of available workers.

Parameters:
wCount - the number of workers to create

getWorker

protected org.apache.jetspeed.aggregator.Worker getWorker()
Retrieves an idle worker

Returns:
a Worker from the idle pool or null if non available

process

public void process(org.apache.jetspeed.aggregator.RenderingJob job)
Assign a job to a worker and execute it or queue the job if no worker is available.

Specified by:
process in interface org.apache.jetspeed.aggregator.WorkerMonitor
Parameters:
job - the Job to process

waitForRenderingJobs

public void waitForRenderingJobs(List renderingJobs)
Wait for all rendering jobs in the collection to finish successfully or otherwise.

Specified by:
waitForRenderingJobs in interface org.apache.jetspeed.aggregator.WorkerMonitor
Parameters:
renderingJobs - the Collection of rendering job objects to wait for.

release

protected void release(org.apache.jetspeed.aggregator.Worker worker)
Put back the worker in the idle queue unless there are pending jobs and worker can still be committed to a new job before being released.


getQueuedJobsCount

public int getQueuedJobsCount()
Specified by:
getQueuedJobsCount in interface org.apache.jetspeed.aggregator.WorkerMonitor

getAvailableJobsCount

public int getAvailableJobsCount()
Returns a snapshot of the available jobs

Specified by:
getAvailableJobsCount in interface org.apache.jetspeed.aggregator.WorkerMonitor
Returns:
available jobs

getRunningJobsCount

public int getRunningJobsCount()
Specified by:
getRunningJobsCount in interface org.apache.jetspeed.aggregator.WorkerMonitor


Copyright © 1999-2007 Apache Software Foundation. All Rights Reserved.