messif.executor
Class MethodThreadList

java.lang.Object
  extended by messif.executor.MethodThreadList

public class MethodThreadList
extends java.lang.Object

This is a wrapper for the MethodExecutor object, which automatically remembers all the method threads that were executed on background. The list of the threads is kept per ThreadLocal variable, thus accessible only by one thread - the one that has started the background execute operation.

A wait function is available - it is a blocking method, which waits for the end of execution for all stored threads.

Parameters from all the stored methods can be retrieved by get operations.


Field Summary
protected  MethodExecutor methodExecutor
          MethodExecutor object that is bound to this
protected  java.util.List<MethodThread> methodFinishedList
          List of MethodThreads executed on background and now finished
protected  java.util.List<MethodThread> methodStartedList
          List of MethodThreads currently executed on background
 
Constructor Summary
MethodThreadList(MethodExecutor methodExecutor)
          Create a new instance of MethodThreadList.
 
Method Summary
 MethodThread backgroundExecute(java.lang.Object... arguments)
          Execute registered method by arguments on background.
 MethodThread backgroundExecute(java.lang.Object[] arguments, Executable executeBefore, Executable executeAfter)
          Execute registered method by arguments on background.
 MethodThread backgroundExecute(java.lang.Object[] arguments, java.util.List<Executable> executeBefore, java.util.List<Executable> executeAfter)
          Execute registered method by arguments on background.
 void clearThreadLists()
          Clears both the lists - started and finished threads.
 void execute(java.lang.Object... arguments)
          Execute registered method by arguments
<E> java.util.List<E>
getAllMethodsArgument(java.lang.Class<E> argClass)
          Returns list of selected arguments from each finished method.
 java.util.List<java.lang.Object> getAllMethodsArgument(int position)
          Get executed argument on the given position from all finished methods
 java.util.List<java.lang.Object> getAllMethodsReturnValue()
          Returns a list of values returned from each finished method.
<E> java.util.List<E>
getAllMethodsReturnValue(java.lang.Class<E> valuesClass)
          Returns a list of values returned from each finished method.
 int waitBackgroundExecuteOperation()
          Wait for all operations executed on background to finish
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

methodExecutor

protected final MethodExecutor methodExecutor
MethodExecutor object that is bound to this


methodStartedList

protected final java.util.List<MethodThread> methodStartedList
List of MethodThreads currently executed on background


methodFinishedList

protected final java.util.List<MethodThread> methodFinishedList
List of MethodThreads executed on background and now finished

Constructor Detail

MethodThreadList

public MethodThreadList(MethodExecutor methodExecutor)
Create a new instance of MethodThreadList.

Parameters:
methodExecutor -
Method Detail

execute

public void execute(java.lang.Object... arguments)
             throws java.lang.NoSuchMethodException,
                    java.lang.reflect.InvocationTargetException
Execute registered method by arguments

Parameters:
arguments - The array of arguments for the execution method (must be consistent with the prototype in constructor)
Throws:
java.lang.NoSuchMethodException - if the specified arguments are invalid or a method for them was not found
java.lang.reflect.InvocationTargetException - if there was an exception during the method execution

backgroundExecute

public MethodThread backgroundExecute(java.lang.Object[] arguments,
                                      Executable executeBefore,
                                      Executable executeAfter)
                               throws java.lang.NoSuchMethodException
Execute registered method by arguments on background. Another methods - executeBefore and executeAfter - can be called before and after the execution in the same thread.

Parameters:
arguments - The array of arguments for the execution method (must be consistent with the prototype in constructor)
executeBefore - method to call before registered method
executeAfter - method to call after registered method
Returns:
method execution thread object. Method waitExecutionEnd of this object can be used to retrieve the results
Throws:
java.lang.NoSuchMethodException - if there was no valid method for the specified arguments

backgroundExecute

public MethodThread backgroundExecute(java.lang.Object[] arguments,
                                      java.util.List<Executable> executeBefore,
                                      java.util.List<Executable> executeAfter)
                               throws java.lang.NoSuchMethodException
Execute registered method by arguments on background. Another methods - executeBefore and executeAfter - can be called before and after the execution in the same thread.

Parameters:
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 method
executeAfter - list of methods to call after registered method
Returns:
method execution thread object. Method waitExecutionEnd of this object can be used to retrieve the results
Throws:
java.lang.NoSuchMethodException - if there was no valid method for the specified arguments

backgroundExecute

public MethodThread backgroundExecute(java.lang.Object... arguments)
                               throws java.lang.NoSuchMethodException
Execute registered method by arguments on background.

Parameters:
arguments - The array of arguments for the execution method (must be consistent with the prototype in constructor)
Returns:
method execution thread object. Method waitExecutionEnd of this object can be used to retrieve the results
Throws:
java.lang.NoSuchMethodException - if there was no valid method for the specified arguments

waitBackgroundExecuteOperation

public int waitBackgroundExecuteOperation()
                                   throws java.lang.Exception
Wait for all operations executed on background to finish

Returns:
Number of currently finished methods
Throws:
java.lang.Exception - if there was an exception during waiting (the waiting is not finished then)

clearThreadLists

public void clearThreadLists()
Clears both the lists - started and finished threads.


getAllMethodsArgument

public <E> java.util.List<E> getAllMethodsArgument(java.lang.Class<E> argClass)
Returns list of selected arguments from each finished method. The respective argument is specified by class, one argument is returned for each method.

Type Parameters:
E - the class of the selected argument
Parameters:
argClass - the class of the selected argument
Returns:
list of executed methods' arguments
Throws:
java.util.NoSuchElementException - if a parameter with the argClass class was not found

getAllMethodsArgument

public java.util.List<java.lang.Object> getAllMethodsArgument(int position)
Get executed argument on the given position from all finished methods

Parameters:
position - the argument position to get
Returns:
a list of the argument on the given position from all finished methods
Throws:
java.util.NoSuchElementException - if a parameter with the argClass class was not found

getAllMethodsReturnValue

public <E> java.util.List<E> getAllMethodsReturnValue(java.lang.Class<E> valuesClass)
                                           throws java.lang.ClassCastException
Returns a list of values returned from each finished method.

Type Parameters:
E - the class of the return types
Parameters:
valuesClass - the class of the return types
Returns:
list of executed methods' returned values
Throws:
java.lang.ClassCastException - if some of the returned values cannot be cast to valuesClass

getAllMethodsReturnValue

public java.util.List<java.lang.Object> getAllMethodsReturnValue()
Returns a list of values returned from each finished method.

Returns:
list of executed methods' returned values