org.apache.jetspeed.aggregator.impl
Class WorkerMonitorImpl

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

public class WorkerMonitorImpl
extends java.lang.Object
implements 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

Field Summary
static java.lang.String ACCESS_CONTROL_CONTEXT_WORKER_ATTR
           
protected  org.apache.jetspeed.aggregator.impl.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  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  java.lang.ThreadGroup tg
          The thread group used to group all worker threads
protected  java.util.Stack workers
          Stack containing currently idle workers
protected  java.util.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()
          Retrieves a snapshot of job count in the waiting (backlogged) queue
 int getRunningJobsCount()
          Returns a snapshot count of the jobs currently running
protected  Worker getWorker()
          Retrieves an idle worker
 void process(RenderingJob job)
          Assign a job to a worker and execute it or queue the job if no worker is available.
protected  void release(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()
          Start processing the worker monitor
 void stop()
          Stop processing the worker monitor Finish all jobs
 void waitForRenderingJobs(java.util.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 java.lang.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 java.util.Stack workers
Stack containing currently idle workers


tg

protected java.lang.ThreadGroup tg
The thread group used to group all worker threads


queue

protected Queue queue
Job queue


workersMonitored

protected java.util.List workersMonitored
Workers to be monitored for timeout checking


jobMonitor

protected org.apache.jetspeed.aggregator.impl.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()
Description copied from interface: WorkerMonitor
Start processing the worker monitor

Specified by:
start in interface WorkerMonitor

stop

public void stop()
Description copied from interface: WorkerMonitor
Stop processing the worker monitor Finish all jobs

Specified by:
stop in interface 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 Worker getWorker()
Retrieves an idle worker

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

process

public void process(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 WorkerMonitor
Parameters:
job - the Job to process

waitForRenderingJobs

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

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

release

protected void release(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()
Description copied from interface: WorkerMonitor
Retrieves a snapshot of job count in the waiting (backlogged) queue

Specified by:
getQueuedJobsCount in interface WorkerMonitor
Returns:
snapshot count of waiting jobs

getAvailableJobsCount

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

Specified by:
getAvailableJobsCount in interface WorkerMonitor
Returns:
available jobs

getRunningJobsCount

public int getRunningJobsCount()
Description copied from interface: WorkerMonitor
Returns a snapshot count of the jobs currently running

Specified by:
getRunningJobsCount in interface WorkerMonitor
Returns:
snapshot count of running jobs


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