uk.co.silentsoftware.dispatcher
Class WorkDispatcher

java.lang.Object
  extended by uk.co.silentsoftware.dispatcher.WorkDispatcher

public class WorkDispatcher
extends java.lang.Object

Central class for the work engine that initialises a fixed thread pool and submits work for preprocessing and processing. This class also holds queues for the pre processed images (for work in process preview) and and the final images (used for both output and work in process preview).


Field Summary
private static java.util.concurrent.ExecutorService exec
          The processing thread
private static java.util.Queue<java.awt.image.BufferedImage> graphicsPreProcessedQueue
          The pre processed image queue for WIP preview
private static java.util.Queue<java.awt.image.BufferedImage> graphicsResultsQueue
          The actual processed image queue for WIP preview (NOT for saving, although the references held are the same object)
static int THREAD_COUNT
          The number of preview threads based on CPU count*4.
 
Constructor Summary
WorkDispatcher()
           
 
Method Summary
static void pollGraphicsResults()
          Pops (polls) the first element off the processing queues, typically done after a preview has been shown.
static java.awt.image.BufferedImage[] retrieveGraphicsResults()
          Returns the best effort sync'd first (peeked) images from the pre processed and graphics results queues, i.e.
static void setThreadsPerCPU(int threads)
          Reconfigure the engine WARNING: Calling this will stop any current processing!!
static void shutdownNow()
          Shut down this engine and threads
static java.util.concurrent.Future<WorkContainer> submitPreviewWork(java.awt.image.BufferedImage original, java.lang.Object dither)
          Similar to submit work (the same processing procedure is followed) however the output is not added to any queues and no SCR output is provided.
static java.util.concurrent.Future<WorkContainer> submitWork(java.awt.image.BufferedImage original, boolean scrRequired)
          Submit a buffered image to be pre processed and processed by a single thread The resulting Future contains the resulting buffered image and optional SCR bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THREAD_COUNT

public static int THREAD_COUNT
The number of preview threads based on CPU count*4. Note that while they may not run on the individual cores it does give a good performance estimate.


exec

private static java.util.concurrent.ExecutorService exec
The processing thread


graphicsPreProcessedQueue

private static java.util.Queue<java.awt.image.BufferedImage> graphicsPreProcessedQueue
The pre processed image queue for WIP preview


graphicsResultsQueue

private static java.util.Queue<java.awt.image.BufferedImage> graphicsResultsQueue
The actual processed image queue for WIP preview (NOT for saving, although the references held are the same object)

Constructor Detail

WorkDispatcher

public WorkDispatcher()
Method Detail

shutdownNow

public static void shutdownNow()
Shut down this engine and threads


setThreadsPerCPU

public static void setThreadsPerCPU(int threads)
Reconfigure the engine WARNING: Calling this will stop any current processing!!

Parameters:
threads -

submitWork

public static java.util.concurrent.Future<WorkContainer> submitWork(java.awt.image.BufferedImage original,
                                                                    boolean scrRequired)
Submit a buffered image to be pre processed and processed by a single thread The resulting Future contains the resulting buffered image and optional SCR bytes. This is the object that should then be saved - do not use the queues in the WorkDispatcher as the queues are popped by the UI threads so a result may be missed.

Parameters:
original -
scrRequired -
Returns:

submitPreviewWork

public static java.util.concurrent.Future<WorkContainer> submitPreviewWork(java.awt.image.BufferedImage original,
                                                                           java.lang.Object dither)
Similar to submit work (the same processing procedure is followed) however the output is not added to any queues and no SCR output is provided. This ensures that dither preview work and actual finished result work is not mixed.

Parameters:
original -
dither -
Returns:
See Also:
submitWork(BufferedImage, boolean)

retrieveGraphicsResults

public static java.awt.image.BufferedImage[] retrieveGraphicsResults()
Returns the best effort sync'd first (peeked) images from the pre processed and graphics results queues, i.e. the source image and it's equivalent result. Not synchronized to maintain performance at expense of an inexact/out of sync preview. This method only returns a non null when both queues have at least one element each.

Returns:

pollGraphicsResults

public static void pollGraphicsResults()
Pops (polls) the first element off the processing queues, typically done after a preview has been shown.