jklustor-overlap-0.0.2-20140619012940 (ChemAxon)


com.chemaxon.overlap.concurrent
Class ManagedBpp<S,T>

Object
  extended by com.chemaxon.overlap.concurrent.ManagedBpp<S,T>
Type Parameters:
S - Type of processed sources
T - type of results

 class ManagedBpp<S,T>
extends Object

Managed batched parallel processor backend functionality.

Concurrency considerations:

Licensing: this class can be used with valid LicenseGlobals.OVERLAP license.

Author:
Gabor Imre

Nested Class Summary
(package private)  class ManagedBpp.Poker<V>
          Callback interface to notify waiting instance.
 
Constructor Summary
ManagedBpp(int pagesize, int maxQueueSize, ListeningExecutorService ex)
          Construct.
 
Method Summary
(package private)  ProcessPage<S,T> fetch(boolean moreToSubmit)
          Fetch next ready result if any.
(package private)  String[] firstPageToStrings()
          First page in String[] format.
(package private)  int getCurrentNonFinishedCount()
          Number of unfinished items.
(package private)  int getCurrentQueueSize()
          Current size of the processing queue.
(package private)  long getInputCount()
          Total read inputs.
(package private)  int getMaxQueueSize()
          Max queue size.
(package private)  long getOutputCount()
          Total reported outputs.
(package private)  int getPagesize()
          Current page size.
(package private)  boolean isEmpty()
          Check if the results queue is empty.
(package private)  boolean isFirstPageDone()
          Check if first page is done.
(package private)  boolean isFrozen()
          Check frozen status.
(package private)  void kill(boolean onlyFirst)
          Kill one or all pages.
(package private)  void process(BppFrontend<S,T> frontend)
          Launch a managed long running process.
(package private)  void setFrozen(boolean frozen)
          Set frozen status.
(package private)  void setMaxQueueSize(int size)
          Set max queue size.
(package private)  void setPageSize(int size)
          Set page size effective for new submissions.
(package private)  void submit(ProcessPage<S,T> page)
          Submit next page for execution.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ManagedBpp

ManagedBpp(int pagesize,
           int maxQueueSize,
           ListeningExecutorService ex)
Construct.

Parameters:
pagesize - Initial page size parameter
maxQueueSize - Initial max queue size
ex - Initial executor service to use
Throws:
chemaxon.license.LicenseException - when appropriate license is not available
Method Detail

isEmpty

boolean isEmpty()
Check if the results queue is empty.

Returns:
True when the results queue is empty

getPagesize

int getPagesize()
Current page size.

Returns:
Page size to use; value is a positive number

setPageSize

void setPageSize(int size)
Set page size effective for new submissions.

Parameters:
size - New page size

getInputCount

long getInputCount()
Total read inputs.

Returns:
input count

getOutputCount

long getOutputCount()
Total reported outputs.

Returns:
outputs

getMaxQueueSize

int getMaxQueueSize()
Max queue size.

Returns:
Max queue size

setMaxQueueSize

void setMaxQueueSize(int size)
Set max queue size.

If the processing blocks due to full queue and queue size is increased processing unblocks. If queue size decreased below current size then processing blocks until queue is decreased to the specified size.

Parameters:
size - New max queue size.

getCurrentQueueSize

int getCurrentQueueSize()
Current size of the processing queue.

Returns:
current size of the processing queue

getCurrentNonFinishedCount

int getCurrentNonFinishedCount()
Number of unfinished items.

Total number of items in the results queue which are not done according to Future.isDone().

Returns:
Number of unfinished items

firstPageToStrings

String[] firstPageToStrings()
First page in String[] format.

Returns:
Sources of first page

setFrozen

void setFrozen(boolean frozen)
Set frozen status.

Parameters:
frozen - If true processing will prefer emptying process queue

isFrozen

boolean isFrozen()
Check frozen status.

Returns:
true if queue is frozen

kill

void kill(boolean onlyFirst)
Kill one or all pages.

Killed pages will be cancelled using Future.cancel(boolean), invoked with true argument and their inputs will be reported as errors using a cancellation exception as the cause. Note that this will ensure the progression of results queue. However the underlying processing coordinated by the supplied ExecutorService might not be aborted, depending on the underlying implementations.

Note that exception thrown from invoked Future.cancel(boolean) will be propagated. In case of such exception the state of this executor will be left consistent but not necessarily conform to the cancellation request.

Parameters:
onlyFirst - If true kill only the first page in the results queue; otherwise kill all
Throws:
NoSuchElementException - when underlying results queue is empty

isFirstPageDone

boolean isFirstPageDone()
Check if first page is done.

Returns:
True if first page (next to report) is done
Throws:
NoSuchElementException - from Queue.element() when results queue is empty

submit

void submit(ProcessPage<S,T> page)
Submit next page for execution.

Parameters:
page - Page to execute.

fetch

ProcessPage<S,T> fetch(boolean moreToSubmit)
Fetch next ready result if any.

This method usually called from the loop on the "main" thread to report processing results. If the client can not submit further tasks then this method will block until a result can be returned. Otherwise this method will block until the next result to be ready only if no further tasks are supposed to be accepted. In case this status changes through management this method will not block further.

Note that progress reporting and cancellation polling is done in BppFrontend however completion reporting with SubProgressObserver.done() must be implemented by the caller.

Parameters:
moreToSubmit - Indicates that more input will be submitted for execution
Returns:
Next ready result or null when no new result is available and no blocking allowed

process

void process(BppFrontend<S,T> frontend)
Launch a managed long running process.

This method blocks until done or cancelled through the supplied ProgressObserver or through management by other thread.

Parameters:
frontend - Frontend to process
Throws:
CancellationException - when cancelled through thread interruption (not recommended) or from BppFrontend#processResult(com.chemaxon.descriptors.fingerprints.pf2d.pm.cli.ProcessPage).

jklustor-overlap-0.0.2-20140619012940 (ChemAxon)