|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.algorithms.Algorithm
public abstract class Algorithm
Abstract algorithm framework - support for algorithm naming and operation executive Every algorithm may suport any number of operations (subclasses of AbstractOperation). This algorithm framework automatically register all methods that have a subclass of AbstractOperation as the only argument. The registered operations are executed using executeOperation method, unsupported operation will throw an AlgorithmMethodException
Nested Class Summary | |
---|---|
static interface |
Algorithm.AlgorithmConstructor
Annotation for algorithm constructors. |
Field Summary | |
---|---|
protected static java.util.logging.Logger |
log
Logger |
protected static int |
maximalConcurrentOperations
Maximal number of currently executed operations |
Constructor Summary | |
---|---|
Algorithm(java.lang.String algorithmName)
Create new instance of Algorithm and initialize the operation executor. |
Method Summary | ||
---|---|---|
protected void |
backgroundExecute(boolean updateStatistics,
java.lang.Object... params)
Execute operation with additional parameters on background. |
|
void |
backgroundExecuteOperation(AbstractOperation operation)
Execute algorithm operation on background. |
|
void |
backgroundExecuteOperation(AbstractOperation operation,
boolean updateStatistics)
Execute algorithm operation on background. |
|
void |
destroy()
Destroy this algorithm. |
|
protected void |
execute(boolean addTimeStatistic,
java.lang.Object... params)
Execute operation with additional parameters. |
|
|
executeOperation(T operation)
Execute operation on this algorithm. |
|
void |
finalize()
Finalize the algorithm. |
|
static
|
getAnnotatedConstructors(java.lang.Class<E> algorithmClass)
Returns all annotated constructors of the provided algorithm class. |
|
static java.lang.String[] |
getConstructorArgumentDescriptions(java.lang.reflect.Constructor<? extends Algorithm> constructor)
Returns constructor argument descriptions for the provided algorithm constuctor. |
|
static java.lang.String |
getConstructorDescription(java.lang.reflect.Constructor<? extends Algorithm> constructor)
Returns algorithm constructor description including descriptions for all its arguments. |
|
static java.lang.String |
getConstructorDescriptionSimple(java.lang.reflect.Constructor<? extends Algorithm> constructor)
Returns constructor description (without description of arguments) for the provided algorithm constuctor. |
|
protected java.lang.Class[] |
getExecutorParamClasses()
This method should return an array of additional parameters that are needed for operation execution. |
|
|
getFirstSupportedOperation(java.lang.Class<? extends E> subclassToSearch)
Returns the first operation that is a supported by this algorithm and is a subclass of (or the same class as) subclassToSearch . |
|
java.lang.String |
getName()
Returns the name of this algorithm |
|
java.lang.Class<? extends LocalAbstractObject> |
getObjectClass()
Returns the class of objects indexed by this algorithm. |
|
OperationStatistics |
getOperationStatistics()
Returns the statistics of the executed operations. |
|
|
getQueryAnswer(java.lang.Class<? extends QueryOperation<? extends T>> operationClass,
java.lang.Object... arguments)
Execute query operation on this algorithm and return the answer. |
|
|
getQueryAnswer(QueryOperation<? extends T> operation)
Execute query operation on this algorithm and return the answer. |
|
int |
getRunningOperationsCount()
Returns the number of currently evaluated operations. |
|
java.util.List<java.lang.Class<? extends AbstractOperation>> |
getSupportedOperations()
Returns the list of operations this particular algorithm supports. |
|
|
getSupportedOperations(java.lang.Class<? extends E> subclassToSearch)
Returns the list of operations this particular algorithm supports. |
|
void |
resetOperationStatistics()
Resets all the statistics of the executed operations gathered so far. |
|
static Algorithm |
restoreFromFile(java.lang.String filepath)
Load the algorithm from the specified file and return it. |
|
static
|
restoreFromFile(java.lang.String filepath,
java.lang.Class<T> algorithmClass)
Load the algorithm from the specified file and return it. |
|
void |
statisticsAfterOperation(AbstractOperation operation)
This method can be used by all algorithms after processing any operation to set default (operation) statistics. |
|
void |
statisticsBeforeOperation()
This method can be used by all algorithms before processing any operation to set default (operation) statistics. |
|
void |
storeToFile(java.lang.String filepath)
Store the algorithm to the specified file. |
|
java.util.List<AbstractOperation> |
waitBackgroundExecuteOperation()
Wait for all operations executed on background to finish. |
|
|
waitBackgroundExecuteOperation(java.lang.Class<E> argClass)
Wait for all operations executed on background to finish. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static java.util.logging.Logger log
protected static final int maximalConcurrentOperations
Constructor Detail |
---|
public Algorithm(java.lang.String algorithmName) throws java.lang.IllegalArgumentException
algorithmName
- the name of this algorithm
java.lang.IllegalArgumentException
- if the prototype returned by getExecutorParamClasses
has no itemsMethod Detail |
---|
public void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- if there was an error finalizingpublic void destroy() throws java.lang.Throwable
This implementation defaults to call finalize()
, but should be overriden
if the algorithm needs to differentiate between finalizing and destroying. In that case
the "super.destroy()" should not be called if finalizing is not part of destroy.
java.lang.Throwable
- if there was an error while cleaningpublic java.lang.String getName()
public java.lang.Class<? extends LocalAbstractObject> getObjectClass()
LocalAbstractObject
class.
public static <T extends Algorithm> T restoreFromFile(java.lang.String filepath, java.lang.Class<T> algorithmClass) throws java.io.IOException, java.lang.NullPointerException, java.lang.ClassNotFoundException, java.lang.ClassCastException
T
- class of the stored algorithmalgorithmClass
- class of the stored algorithmfilepath
- the path to a file from which the algorithm should be restored
java.io.IOException
- if the specified filename is not a readable serialized algorithm
(see readObject
method for detailed description)
java.lang.NullPointerException
- if the specified filename is null
java.lang.ClassNotFoundException
- if the class of serialized object cannot be found
java.lang.ClassCastException
- if the filename doesn't contain serialized algorithmpublic static Algorithm restoreFromFile(java.lang.String filepath) throws java.io.IOException, java.lang.NullPointerException, java.lang.ClassNotFoundException, java.lang.ClassCastException
filepath
- the path to file from which the algorithm should be restored
java.io.IOException
- if the specified filename is not a readable serialized algorithm
(see readObject
method for detailed description)
java.lang.NullPointerException
- if the specified filename is null
java.lang.ClassNotFoundException
- if the class of serialized object cannot be found
java.lang.ClassCastException
- if the filename doesn't contain serialized algorithmpublic void storeToFile(java.lang.String filepath) throws java.io.IOException
filepath
- the path to a file where the algorithm should be stored. If this path is a directory,
the algorithm name (all non alphanumeric characters are replaced by underscore) with .bin
extension is appended to the path.
java.io.IOException
- if the specified filename is not writable or if an error occurrs during the serialization
(see writeObject
method for detailed description)public int getRunningOperationsCount()
public OperationStatistics getOperationStatistics()
resetOperationStatistics()
, the cumulative statistics
for all operations run in this thread are returned.
public void resetOperationStatistics()
public java.util.List<java.lang.Class<? extends AbstractOperation>> getSupportedOperations()
public <E extends AbstractOperation> java.util.List<java.lang.Class<? extends E>> getSupportedOperations(java.lang.Class<? extends E> subclassToSearch)
E
- type of the returned operationssubclassToSearch
- ancestor class of the returned operations.
public final <E extends AbstractOperation> java.lang.Class<? extends E> getFirstSupportedOperation(java.lang.Class<? extends E> subclassToSearch) throws java.lang.NoSuchMethodException
subclassToSearch
.
The operations returned can be further queried on arguments by static methods in AbstractOperation.
E
- type of the returned operationssubclassToSearch
- ancestor class of the returned operations
subclassToSearch
that is a supported by this algorithm
java.lang.NoSuchMethodException
- if this algorithm does not support any operation of the given subclassToSearch
protected final void execute(boolean addTimeStatistic, java.lang.Object... params) throws AlgorithmMethodException, java.lang.NoSuchMethodException
MethodExecutor.execute(java.lang.reflect.Method, java.lang.Object, java.lang.Object[])
.
addTimeStatistic
- add the execution time statistic to OperationStatistics
params
- the parameters compatible with getExecutorParamClasses()
AlgorithmMethodException
- if the execution has thrown an exception
java.lang.NoSuchMethodException
- if the operation is unsupported (there is no method for the operation)protected final void backgroundExecute(boolean updateStatistics, java.lang.Object... params) throws java.lang.NoSuchMethodException
MethodExecutor.backgroundExecute(java.lang.Object[], messif.executor.Executable, messif.executor.Executable)
.
updateStatistics
- set to true if the operations statistic should be updated after the operation finishes its background executionparams
- the parameters compatible with getExecutorParamClasses()
java.lang.NoSuchMethodException
- if the operation is unsupported (there is no method for the operation)public <T extends AbstractOperation> T executeOperation(T operation) throws AlgorithmMethodException, java.lang.NoSuchMethodException
T
- the type of executed operationoperation
- the operation to execute on this algorithm
AlgorithmMethodException
- if the execution has thrown an exception
java.lang.NoSuchMethodException
- if the operation is unsupported (there is no method for the operation)public <T> java.util.Iterator<? extends T> getQueryAnswer(QueryOperation<? extends T> operation) throws AlgorithmMethodException, java.lang.NoSuchMethodException
executeOperation(messif.operations.AbstractOperation)
and
QueryOperation.getAnswer()
.
T
- the type of query operation answeroperation
- the operation to execute on this algorithm
AlgorithmMethodException
- if the execution has thrown an exception
java.lang.NoSuchMethodException
- if the operation is unsupported (there is no method for the operation)public <T> java.util.Iterator<? extends T> getQueryAnswer(java.lang.Class<? extends QueryOperation<? extends T>> operationClass, java.lang.Object... arguments) throws java.lang.reflect.InvocationTargetException, AlgorithmMethodException, java.lang.NoSuchMethodException
AbstractOperation.createOperation(java.lang.Class, java.lang.Object[])
and
getQueryAnswer(messif.operations.QueryOperation)
.
T
- the type of query operation answeroperationClass
- the class of the operation to execute on this algorithmarguments
- the arguments for the operation constructor
java.lang.reflect.InvocationTargetException
- if the operation constructor has thrown an exception
java.lang.NoSuchMethodException
- if the operation is unknown or unsupported by this algorithm
AlgorithmMethodException
- if the execution has thrown an exceptionpublic void backgroundExecuteOperation(AbstractOperation operation) throws java.lang.NoSuchMethodException
waitBackgroundExecuteOperation()
MUST be called in the future to release resources.
operation
- the operation to execute on this algorithm
java.lang.NoSuchMethodException
- if the operation is unsupported (there is no method for the operation)public void backgroundExecuteOperation(AbstractOperation operation, boolean updateStatistics) throws java.lang.NoSuchMethodException
waitBackgroundExecuteOperation()
MUST be called in the future to release resources.
operation
- the operation to execute on this algorithmupdateStatistics
- set to true if the operations statistic should be updated after the operation finishes its background execution
java.lang.NoSuchMethodException
- if the operation is unsupported (there is no method for the operation)public java.util.List<AbstractOperation> waitBackgroundExecuteOperation() throws AlgorithmMethodException, java.lang.InterruptedException
AlgorithmMethodException
- if there was an exception during the background execution
java.lang.InterruptedException
- if the waiting was interruptedpublic <E extends AbstractOperation> java.util.List<E> waitBackgroundExecuteOperation(java.lang.Class<E> argClass) throws AlgorithmMethodException, java.lang.InterruptedException
E
- type of the returned operationsargClass
- filter on the returned operation classes
AlgorithmMethodException
- if there was an exception during the background execution
java.lang.InterruptedException
- if the waiting was interruptedpublic void statisticsBeforeOperation() throws java.lang.ClassCastException
java.lang.ClassCastException
- if new statistic cannot be createdpublic void statisticsAfterOperation(AbstractOperation operation)
statisticsBeforeOperation()
method was used before.
operation
- (typically query) operation that was just processedprotected java.lang.Class[] getExecutorParamClasses()
execute(boolean, java.lang.Object...)
and backgroundExecute(boolean, java.lang.Object...)
.
public static <E extends Algorithm> java.util.List<java.lang.reflect.Constructor<E>> getAnnotatedConstructors(java.lang.Class<E> algorithmClass)
E
- class of algorithm for which to get constructorsalgorithmClass
- the class of an algorithm for which to get constructors
public static java.lang.String[] getConstructorArgumentDescriptions(java.lang.reflect.Constructor<? extends Algorithm> constructor)
getAnnotatedConstructors
.
This is used by auto-generated clients to show descriptiron during algorithm creation.
constructor
- an algorithm constructor to get the descriptions for
public static java.lang.String getConstructorDescriptionSimple(java.lang.reflect.Constructor<? extends Algorithm> constructor)
getAnnotatedConstructors
.
This is used by auto-generated clients to show descriptiron during algorithm creation.
constructor
- an algorithm constructor to get the descriptions for
public static java.lang.String getConstructorDescription(java.lang.reflect.Constructor<? extends Algorithm> constructor)
getAnnotatedConstructors
.
This is used by auto-generated clients to show descriptiron during algorithm creation.
constructor
- an algorithm constructor to get the descriptions for
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |