public abstract class AAlgorithm<I,O> extends java.lang.Object implements IAlgorithm<I,O>, ILoggingCustomizable
| Modifier | Constructor and Description |
|---|---|
protected |
AAlgorithm(I input)
C'tor providing the input for the algorithm already.
|
protected |
AAlgorithm(IAlgorithmConfig config,
I input)
Internal c'tore overwriting the internal configuration and setting the input.
|
| Modifier and Type | Method and Description |
|---|---|
protected AlgorithmInitializedEvent |
activate()
This method
- defines the definite deadline for when the algorithm must have finished
- sets the algorithm state to ACTIVE
- sends the mandatory AlgorithmInitializedEvent over the event bus.
|
protected void |
announceTimeoutDetected() |
protected void |
avoidReinterruptionOnShutdownOnCurrentThread() |
void |
cancel() |
protected void |
checkAndConductTermination() |
protected void |
checkTermination(boolean shutdownOnStoppingCriterion) |
protected <T> T |
computeTimeoutAware(java.util.concurrent.Callable<T> r,
java.lang.String reasonToLogOnTimeout,
boolean shutdownOnStoppingCriterionSatisfied) |
long |
getActivationTime() |
IAlgorithmConfig |
getConfig() |
java.lang.String |
getId()
globally unique identifier for the algorithm run
|
I |
getInput() |
java.lang.String |
getLoggerName() |
int |
getNumCPUs() |
protected TimeOut |
getRemainingTimeToDeadline() |
AlgorithmState |
getState() |
TimeOut |
getTimeout() |
int |
getTimeoutPrecautionOffset() |
boolean |
hasNext() |
boolean |
hasThreadBeenInterruptedDuringShutdown(java.lang.Thread t) |
protected void |
interruptThreadAsPartOfShutdown(java.lang.Thread t) |
boolean |
isCanceled() |
boolean |
isShutdownInitialized() |
boolean |
isStopCriterionSatisfied() |
boolean |
isTimeouted() |
java.util.Iterator<AlgorithmEvent> |
iterator() |
AlgorithmEvent |
next() |
protected void |
post(java.lang.Object e)
This methods allows for posting an event on the algorithm's event bus.
|
protected void |
registerActiveThread() |
void |
registerListener(java.lang.Object listener)
Registers a listener to the algorithm's event bus.
|
protected void |
resolveShutdownInterruptOnCurrentThread() |
void |
setConfig(IAlgorithmConfig config)
Sets the config object to the new config object.
|
void |
setLoggerName(java.lang.String name) |
void |
setMaxNumThreads(int maxNumberOfThreads)
While setNumCPUs aims at telling the algorithm how many CPUs *should* be used for parallelization,
this method can be used to define a strict constraint on the number of threads that must be spawned
by the algorithm itself at most.
|
void |
setNumCPUs(int numberOfCPUs) |
protected void |
setState(AlgorithmState state) |
void |
setTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Sets the timeout for the algorithm to the given value in the given time unit.
|
void |
setTimeout(TimeOut timeout) |
void |
setTimeoutPrecautionOffset(int timeoutPrecautionOffset) |
protected void |
shutdown()
This method does two things:
1. it interrupts all threads that are registered to be active inside this algorithm
2. it cancels the (possibly created) timeout thread
This method should be called ALWAYS when the algorithm activity ceases.
|
protected AlgorithmFinishedEvent |
terminate()
This methods terminates the algorithm, setting the internal state to inactive and emitting the mandatory AlgorithmFinishedEvent over the event bus.
|
protected void |
unregisterActiveThread() |
protected void |
unregisterThreadAndShutdown() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcall, nextWithExceptionprotected AAlgorithm(I input)
input - The input for the algorithm.protected AAlgorithm(IAlgorithmConfig config, I input)
input - The input for the algorithm.config - The configuration to take as the internal configuration object.public java.util.Iterator<AlgorithmEvent> iterator()
iterator in interface java.lang.Iterable<AlgorithmEvent>public boolean hasNext()
hasNext in interface java.util.Iterator<AlgorithmEvent>public AlgorithmEvent next()
next in interface java.util.Iterator<AlgorithmEvent>public I getInput()
getInput in interface IAlgorithm<I,O>public void registerListener(java.lang.Object listener)
IAlgorithmregisterListener in interface IAlgorithm<I,O>listener - The listener to register.public int getNumCPUs()
getNumCPUs in interface IAlgorithm<I,O>public void setNumCPUs(int numberOfCPUs)
setNumCPUs in interface IAlgorithm<I,O>numberOfCPUs - The numer of cpus that is allowed to be used by the algorithm.public void setMaxNumThreads(int maxNumberOfThreads)
IAlgorithmsetNumCPUs
does not put such a restriction, because this is unnecessarily limiting in environment where such
constraints do not exist.
If the value is set to 0, no own threads must be used at all. Note that this may not be possible for
some algorithms that need observers in the background.
If the value is set to -1, any restriction on the number of threads is removed.
Note that different algorithms may have different default behaviors if this number is not set.setMaxNumThreads in interface IAlgorithm<I,O>maxNumberOfThreads - The maximum number of threads that may be spawned by the algorithm itself.public void setTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
IAlgorithmsetTimeout in interface IAlgorithm<I,O>timeout - The number of e.g. ms, seconds, minutes according to the given time unit.timeUnit - The time unit for which the timeout variable will be interpreted.public void setTimeout(TimeOut timeout)
setTimeout in interface IAlgorithm<I,O>timeout - The timeout for the algorithm.public int getTimeoutPrecautionOffset()
public void setTimeoutPrecautionOffset(int timeoutPrecautionOffset)
public TimeOut getTimeout()
getTimeout in interface IAlgorithm<I,O>public boolean isTimeouted()
protected TimeOut getRemainingTimeToDeadline()
public boolean isStopCriterionSatisfied()
public boolean isCanceled()
public java.lang.String getId()
IAlgorithmgetId in interface IAlgorithm<I,O>protected void checkTermination(boolean shutdownOnStoppingCriterion)
throws java.lang.InterruptedException,
AlgorithmExecutionCanceledException,
AlgorithmTimeoutedException
java.lang.InterruptedExceptionAlgorithmExecutionCanceledExceptionAlgorithmTimeoutedExceptionprotected void checkAndConductTermination()
throws java.lang.InterruptedException,
AlgorithmExecutionCanceledException,
AlgorithmTimeoutedException
java.lang.InterruptedExceptionAlgorithmExecutionCanceledExceptionAlgorithmTimeoutedExceptionprotected void shutdown()
protected void interruptThreadAsPartOfShutdown(java.lang.Thread t)
public boolean hasThreadBeenInterruptedDuringShutdown(java.lang.Thread t)
protected void resolveShutdownInterruptOnCurrentThread()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected void avoidReinterruptionOnShutdownOnCurrentThread()
public boolean isShutdownInitialized()
protected void unregisterThreadAndShutdown()
protected void registerActiveThread()
protected void unregisterActiveThread()
public long getActivationTime()
public AlgorithmState getState()
protected void setState(AlgorithmState state)
state - The new state of the algorithm.public void cancel()
cancel in interface Cancelableprotected AlgorithmInitializedEvent activate()
protected AlgorithmFinishedEvent terminate()
protected void post(java.lang.Object e)
e - The event to post on the event bus.public IAlgorithmConfig getConfig()
getConfig in interface IAlgorithm<I,O>public void setConfig(IAlgorithmConfig config)
config - The new config object.public void setLoggerName(java.lang.String name)
setLoggerName in interface ILoggingCustomizablepublic java.lang.String getLoggerName()
getLoggerName in interface ILoggingCustomizableprotected void announceTimeoutDetected()
protected <T> T computeTimeoutAware(java.util.concurrent.Callable<T> r,
java.lang.String reasonToLogOnTimeout,
boolean shutdownOnStoppingCriterionSatisfied)
throws java.lang.InterruptedException,
AlgorithmException,
AlgorithmExecutionCanceledException,
AlgorithmTimeoutedException
java.lang.InterruptedExceptionAlgorithmExceptionAlgorithmExecutionCanceledExceptionAlgorithmTimeoutedException