lt.monarch.print
Class JobProcessor

java.lang.Object
  extended by lt.monarch.print.JobProcessor
All Implemented Interfaces:
java.lang.Runnable

public class JobProcessor
extends java.lang.Object
implements java.lang.Runnable


Field Summary
Modifier and Type Field and Description
protected  boolean jobListEmpty
          Indicated whether job list is empty.
protected  java.util.ArrayList<java.lang.Runnable> jobs
          Jobs list.
protected  java.lang.Thread processor
          Job processor thread.
protected  boolean stopProcessing
          Flag for stopping job processor.
 
Constructor Summary
Constructor and Description
JobProcessor()
          Creates new job processor with name "JobProcessor" and minimal thread priority.
JobProcessor(java.lang.String name)
          Creates new job processor with specified name.
 
Method Summary
Modifier and Type Method and Description
 void abort()
          Aborts the the job processor current job and removes all jobs from processor's jobs list.
 void add(java.lang.Runnable job)
          Adds new job to jobs list.
 void addAndWait(java.lang.Runnable job)
          Adds new job to the jobs list.
 void addAndWait(java.lang.Runnable job, long timeout)
          Adds new job to jobs list with timeout value for it's processing.
static JobProcessor defaultProcessor()
          Creates default job processor if there is no such already running.
 void interruptAndAbort()
          Interrupts and aborts the job processor.
protected  void processJob(java.lang.Runnable job)
          Processes specified job.
 void run()
          Starts the job processor.
 void shutdown()
          Shuts down the job processor.
 void waitForAll()
          Waits until other processors are done processing job lists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jobs

protected final java.util.ArrayList<java.lang.Runnable> jobs
Jobs list.


processor

protected java.lang.Thread processor
Job processor thread.


jobListEmpty

protected volatile boolean jobListEmpty
Indicated whether job list is empty.


stopProcessing

protected volatile boolean stopProcessing
Flag for stopping job processor.

Constructor Detail

JobProcessor

public JobProcessor()
Creates new job processor with name "JobProcessor" and minimal thread priority.


JobProcessor

public JobProcessor(java.lang.String name)
Creates new job processor with specified name.

Parameters:
name - name of new job processor.
Method Detail

defaultProcessor

public static JobProcessor defaultProcessor()
Creates default job processor if there is no such already running. Default name for it is "Default JobProcessor".

Returns:
default job processor

add

public void add(java.lang.Runnable job)
Adds new job to jobs list. If the job processor is nt running, then no operation will be performed.

Parameters:
job - job to be added add to the jobs list.

addAndWait

public void addAndWait(java.lang.Runnable job)
                throws java.lang.InterruptedException
Adds new job to the jobs list.

Parameters:
job - job to be added.
Throws:
java.lang.InterruptedException - when job is waiting in the jobs list and other thread interrupts it.

addAndWait

public void addAndWait(java.lang.Runnable job,
                       long timeout)
                throws java.lang.InterruptedException
Adds new job to jobs list with timeout value for it's processing.

Parameters:
job - job to be added to jobs list.
timeout - timeout value of job processing (job processing is delayed for timeout milliseconds).
Throws:
java.lang.InterruptedException - when job is waiting in the jobs list and other thread interrupts it.

interruptAndAbort

public void interruptAndAbort()
Interrupts and aborts the job processor. If processor is not the current job processor, then all jobs are removed from processors jobs list.


abort

public void abort()
           throws java.lang.InterruptedException
Aborts the the job processor current job and removes all jobs from processor's jobs list.

Throws:
java.lang.InterruptedException - if job processor is interrupted while it waits.

shutdown

public void shutdown()
              throws java.lang.InterruptedException
Shuts down the job processor.

Throws:
java.lang.InterruptedException - if job processor is interrupted while it waits.

waitForAll

public void waitForAll()
                throws java.lang.InterruptedException
Waits until other processors are done processing job lists.

Throws:
java.lang.InterruptedException - if job processor is interrupted while it waits.

run

public void run()
Starts the job processor.

Specified by:
run in interface java.lang.Runnable

processJob

protected void processJob(java.lang.Runnable job)
Processes specified job.

Parameters:
job - job to process.