org.openstreetmap.gui.jmapviewer
Class JobDispatcher

java.lang.Object
  extended by org.openstreetmap.gui.jmapviewer.JobDispatcher

public class JobDispatcher
extends java.lang.Object

A generic class that processes a list of Runnable one-by-one using one or more JobDispatcher.JobThread-instances. The number of instances varies between 1 and WORKER_THREAD_MAX_COUNT (default: 8). If an instance is idle more than WORKER_THREAD_TIMEOUT seconds (default: 30), the instance ends itself.


Nested Class Summary
 class JobDispatcher.JobThread
           
 
Field Summary
private static JobDispatcher instance
           
protected  java.util.concurrent.BlockingDeque<TileJob> jobQueue
           
protected  boolean modeLIFO
          Type of queue, FIFO if false, LIFO if true
static int WORKER_THREAD_MAX_COUNT
           
static int WORKER_THREAD_TIMEOUT
          Specifies the time span in seconds that a worker thread waits for new jobs to perform.
protected  int workerThreadCount
          Total number of worker threads currently idle or active
protected  int workerThreadId
          Just an id for identifying an worker thread instance
protected  int workerThreadIdleCount
          Number of worker threads currently idle
 
Constructor Summary
private JobDispatcher()
           
 
Method Summary
 void addJob(TileJob job)
          Adds a job to the queue.
protected  JobDispatcher.JobThread addWorkerThread()
           
 void cancelOutstandingJobs()
          Removes all jobs from the queue that are currently not being processed.
static JobDispatcher getInstance()
           
 void setLIFO(boolean lifo)
          Function to set the LIFO/FIFO mode for tile loading job.
static void setMaxWorkers(int workers)
          Function to set the maximum number of workers for tile loading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static final JobDispatcher instance

jobQueue

protected java.util.concurrent.BlockingDeque<TileJob> jobQueue

WORKER_THREAD_MAX_COUNT

public static int WORKER_THREAD_MAX_COUNT

WORKER_THREAD_TIMEOUT

public static int WORKER_THREAD_TIMEOUT
Specifies the time span in seconds that a worker thread waits for new jobs to perform. If the time span has elapsed the worker thread terminates itself. Only the first worker thread works differently, it ignores the timeout and will never terminate itself.


modeLIFO

protected boolean modeLIFO
Type of queue, FIFO if false, LIFO if true


workerThreadCount

protected int workerThreadCount
Total number of worker threads currently idle or active


workerThreadIdleCount

protected int workerThreadIdleCount
Number of worker threads currently idle


workerThreadId

protected int workerThreadId
Just an id for identifying an worker thread instance

Constructor Detail

JobDispatcher

private JobDispatcher()
Method Detail

getInstance

public static JobDispatcher getInstance()
Returns:
the singelton instance of the JobDispatcher

cancelOutstandingJobs

public void cancelOutstandingJobs()
Removes all jobs from the queue that are currently not being processed.


setMaxWorkers

public static void setMaxWorkers(int workers)
Function to set the maximum number of workers for tile loading.


setLIFO

public void setLIFO(boolean lifo)
Function to set the LIFO/FIFO mode for tile loading job.

Parameters:
lifo - true for LIFO mode, false for FIFO mode

addJob

public void addJob(TileJob job)
Adds a job to the queue. Jobs for tiles already contained in the are ignored (using a null tile prevents skipping).

Parameters:
job - the the job to be added

addWorkerThread

protected JobDispatcher.JobThread addWorkerThread()


JOSM