O
- the type of the operation that are processed by this navigation processorT
- the type of processing items used by this navigation processorpublic abstract class AbstractNavigationProcessor<O extends AbstractOperation,T> extends java.lang.Object implements AsynchronousNavigationProcessor<O>
NavigationProcessor
that processes any AbstractOperation
on a set of processing items (e.g. buckets).
Modifier | Constructor and Description |
---|---|
|
AbstractNavigationProcessor(O operation,
boolean cloneAsynchronousOperation)
Create a new navigation processor.
|
|
AbstractNavigationProcessor(O operation,
boolean cloneAsynchronousOperation,
boolean cloneSequentialOperation,
java.util.Collection<? extends T> processingItems)
Create a new navigation processor.
|
protected |
AbstractNavigationProcessor(O operation,
boolean cloneAsynchronousOperation,
boolean cloneSequentialOperation,
java.util.Queue<T> processingItems,
boolean queueClosed)
Create a new navigation processor with a given queue instance.
|
|
AbstractNavigationProcessor(O operation,
boolean cloneAsynchronousOperation,
java.util.Collection<? extends T> processingItems)
Create a new navigation processor.
|
Modifier and Type | Method and Description |
---|---|
void |
abort() |
T |
addProcessingItem(T processingItem)
Adds a processing item to this processor.
|
void |
addProcessingItems(java.util.Collection<? extends T> processingItems)
Adds a collection of processing items to this processor.
|
void |
close()
Method to be called after processing all the steps.
|
protected T |
getNextProcessingItem(boolean isAsynchronous)
Returns the next processing item in the queue.
|
O |
getOperation()
Returns the operation for which this navigator was created.
|
int |
getProcessedCount()
Returns the number of processing steps already evaluated by this processor.
|
int |
getRemainingCount()
Returns the number of the remaining processing steps.
|
boolean |
isFinished()
Returns whether this processor is finished.
|
boolean |
isQueueClosed()
Returns whether additional processing items can be added to this processor (false)
or this processor is closed (true).
|
protected abstract O |
processItem(O operation,
T processingItem)
Processes the encapsulated operation using the given processing item.
|
boolean |
processStep()
Processes the encapsulated operation by the next processing step.
|
java.util.concurrent.Callable<O> |
processStepAsynchronously()
Returns a
Callable that allows to execute the next processing step asynchronously. |
void |
queueClose()
Closes this processor queue.
|
protected void |
stepFinished(O processedOperation)
This method is called immediately after a single processing step of this navigation processor
was finished.
|
protected AbstractNavigationProcessor(O operation, boolean cloneAsynchronousOperation, boolean cloneSequentialOperation, java.util.Queue<T> processingItems, boolean queueClosed)
closed
and contains only the specified processing items.
No additional processing items can be added.operation
- the operation to processcloneAsynchronousOperation
- the flag whether to clone the operation for asynchronous processingcloneSequentialOperation
- the flag whether to clone the operation also for sequential processingprocessingItems
- the processing items queuequeueClosed
- the flag whether the given queue is closed, if false, i.e. getting a next element from the queue blocks and waits for the queue to fillpublic AbstractNavigationProcessor(O operation, boolean cloneAsynchronousOperation, boolean cloneSequentialOperation, java.util.Collection<? extends T> processingItems)
closed
and contains only the specified processing items.
No additional processing items can be added.operation
- the operation to processcloneAsynchronousOperation
- the flag whether to clone the operation for asynchronous processingcloneSequentialOperation
- the flag whether to clone the operation also for sequential processingprocessingItems
- the processing items for the operationpublic AbstractNavigationProcessor(O operation, boolean cloneAsynchronousOperation, java.util.Collection<? extends T> processingItems)
closed
and contains only the specified processing items.
No additional processing items can be added.operation
- the operation to processcloneAsynchronousOperation
- the flag whether to clone the operation for asynchronous processingprocessingItems
- the processing items for the operationpublic AbstractNavigationProcessor(O operation, boolean cloneAsynchronousOperation)
processStep()
. Additional processing items
must be added via addProcessingItem(T)
methods and then closed
in order to be able to finish the processing.operation
- the operation to processcloneAsynchronousOperation
- the flag whether to clone the operation for asynchronous processingpublic final void addProcessingItems(java.util.Collection<? extends T> processingItems) throws java.lang.IllegalStateException
closed
.processingItems
- the collection of processing items to addjava.lang.IllegalStateException
- if this processor is already closed
.public T addProcessingItem(T processingItem) throws java.lang.IllegalStateException
closed
.processingItem
- the processing item to addjava.lang.IllegalStateException
- if this processor is already closed
.public void queueClose() throws java.lang.IllegalStateException
processStep()
method will no longer block and wait for additional processing items.java.lang.IllegalStateException
- if this processor is already closed
.public boolean isQueueClosed()
public void close()
NavigationProcessor
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface NavigationProcessor<O extends AbstractOperation>
public void abort() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public O getOperation()
NavigationProcessor
getOperation
in interface NavigationProcessor<O extends AbstractOperation>
public boolean isFinished()
NavigationProcessor
NavigationProcessor.processStep()
returns false.isFinished
in interface NavigationProcessor<O extends AbstractOperation>
NavigationProcessor.processStep()
is possible or
true if this processor has finishedpublic int getProcessedCount()
NavigationProcessor
getProcessedCount
in interface NavigationProcessor<O extends AbstractOperation>
public int getRemainingCount()
NavigationProcessor
getRemainingCount
in interface NavigationProcessor<O extends AbstractOperation>
protected T getNextProcessingItem(boolean isAsynchronous) throws java.lang.InterruptedException
java.lang.InterruptedException
- if the waiting for the next item in the queue has been interruptedprotected abstract O processItem(O operation, T processingItem) throws AlgorithmMethodException
operation
- the operation that is to be processedprocessingItem
- the processing item using which to process the operationAlgorithmMethodException
- if an error occurred during the evaluation of the processing steppublic final boolean processStep() throws java.lang.InterruptedException, AlgorithmMethodException, java.lang.CloneNotSupportedException
NavigationProcessor
processStep
in interface NavigationProcessor<O extends AbstractOperation>
java.lang.InterruptedException
- if the thread processing the step is interruptedAlgorithmMethodException
- if an error occurred during the evaluation of the processing stepjava.lang.CloneNotSupportedException
- if there was a need for cloning (due to asynchronous access) but cloning was not supportedpublic final java.util.concurrent.Callable<O> processStepAsynchronously() throws java.lang.InterruptedException
AsynchronousNavigationProcessor
Callable
that allows to execute the next processing step asynchronously.
Note that this method may block if necessary.processStepAsynchronously
in interface AsynchronousNavigationProcessor<O extends AbstractOperation>
Callable
for next step or null if there are no more stepsjava.lang.InterruptedException
- if the processing thread was interruptedprotected void stepFinished(O processedOperation)
processedOperation
- the instance of the operation that has been just processed