|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.executor.MethodExecutor
public abstract class MethodExecutor
This class is a generic framework for executing methods on a specified object. Methods must match the specified prototype. Then the method execute method can be called. This method invokes the method of the instance (provided in constructor), which is appropriate for the provided arguments. Method backgroundExecute can be called to invoke the method in a new thread. A returned thread can be used for wait calls to test, whether the execution has finished and also to retrieve the data.
Nested Class Summary | |
---|---|
static interface |
MethodExecutor.ExecutableMethod
Annotation for methods that provide usage description. |
Field Summary | |
---|---|
protected java.lang.Object |
executionObject
The object that the operations are invoked on |
Constructor Summary | |
---|---|
protected |
MethodExecutor(java.lang.Object executionObject)
Create new instance of MethodExecutor |
Method Summary | |
---|---|
MethodThread |
backgroundExecute(java.lang.Object... arguments)
Execute a registered method by arguments on background. |
MethodThread |
backgroundExecute(java.lang.Object[] arguments,
Executable executeBefore,
Executable executeAfter)
Execute a registered method by arguments on background. |
MethodThread |
backgroundExecute(java.lang.Object[] arguments,
java.util.List<Executable> executeBefore,
java.util.List<Executable> executeAfter)
Execute a registered method by arguments on background. |
protected static java.lang.Object |
execute(java.lang.reflect.Method method,
java.lang.Object executionObject,
java.lang.Object[] arguments)
Execute specified method on exectutionObject with specified arguments and handle exceptions properly. |
java.lang.Object |
execute(java.lang.Object... arguments)
Execute a registered method using the specified arguments. |
protected abstract java.lang.reflect.Method |
getMethod(java.lang.Object[] arguments)
Returns the method that is appropriate for the provided arguments. |
protected abstract java.util.Collection<java.lang.reflect.Method> |
getRegisteredMethods()
Returns all methods that are registered within this executor. |
void |
printUsage(java.io.PrintStream out,
boolean printArguments,
boolean printDescription)
Prints usage of all methods managed by this executor. |
static void |
printUsage(java.io.PrintStream out,
boolean printArguments,
boolean printDescription,
java.lang.reflect.Method method)
Prints the method usage built from the MethodExecutor.ExecutableMethod annotation. |
void |
printUsage(java.io.PrintStream out,
boolean printArguments,
boolean printDescription,
java.lang.Object[] arguments)
Prints usage of method that is to be called for the given arguments. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.lang.Object executionObject
Constructor Detail |
---|
protected MethodExecutor(java.lang.Object executionObject) throws java.lang.IllegalArgumentException
executionObject
- an instance of the object to execute the operations on
java.lang.IllegalArgumentException
- if the execution object is nullMethod Detail |
---|
protected abstract java.util.Collection<java.lang.reflect.Method> getRegisteredMethods()
public static void printUsage(java.io.PrintStream out, boolean printArguments, boolean printDescription, java.lang.reflect.Method method)
MethodExecutor.ExecutableMethod
annotation.
If the annotation is not present, nothing is printed out.
Otherwise the concatenation of the method name, its argument descriptions
(in sharp parenthesis) and the method's description is printed out.
out
- the print stream where the usage is printprintArguments
- flag whether to print the method's
argument descriptions
printDescription
- flag whether to print the method's
description
method
- the method for which to get the usagepublic void printUsage(java.io.PrintStream out, boolean printArguments, boolean printDescription)
out
- the print stream where the usage is printprintArguments
- flag whether to print the method's
argument descriptions
printDescription
- flag whether to print the method's
description
public void printUsage(java.io.PrintStream out, boolean printArguments, boolean printDescription, java.lang.Object[] arguments) throws java.lang.NoSuchMethodException
out
- the print stream where the usage is printprintArguments
- flag whether to print the method's
argument descriptions
printDescription
- flag whether to print the method's
description
arguments
- the arguments for the method
java.lang.NoSuchMethodException
- if there is no method for the specified parameters in this executorprotected abstract java.lang.reflect.Method getMethod(java.lang.Object[] arguments) throws java.lang.NoSuchMethodException
arguments
- the arguments for the method
java.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executorprotected static java.lang.Object execute(java.lang.reflect.Method method, java.lang.Object executionObject, java.lang.Object[] arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
method
- the method to executeexecutionObject
- the instance on which to invoke the methodarguments
- the method arguments
java.lang.NoSuchMethodException
- if the arguments are not compatible with the method
java.lang.reflect.InvocationTargetException
- if an exeception was thrown when the method was executedpublic java.lang.Object execute(java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
arguments
- the array of arguments for the execution method
(must be consistent with the prototype in constructor)
java.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executor
java.lang.reflect.InvocationTargetException
- if an exeception was thrown when the method was executedpublic MethodThread backgroundExecute(java.lang.Object[] arguments, Executable executeBefore, Executable executeAfter) throws java.lang.NoSuchMethodException
arguments
- the array of arguments for the execution method
(must be consistent with the prototype in constructor)executeBefore
- method to call before registered methodexecuteAfter
- method to call after registered method
MethodThread.waitExecutionEnd()
can be used to retrieve the results
java.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executorpublic MethodThread backgroundExecute(java.lang.Object[] arguments, java.util.List<Executable> executeBefore, java.util.List<Executable> executeAfter) throws java.lang.NoSuchMethodException
arguments
- The array of arguments for the execution method
(must be consistent with the prototype in constructor)executeBefore
- list of methods to call before registered methodexecuteAfter
- list of methods to call after registered method
MethodThread.waitExecutionEnd()
can be used to retrieve the results
java.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executorpublic MethodThread backgroundExecute(java.lang.Object... arguments) throws java.lang.NoSuchMethodException
arguments
- the array of arguments for the execution method
(must be consistent with the prototype in constructor)
MethodThread.waitExecutionEnd()
can be used to retrieve the results
java.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executor
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |