messif.executor
Class MethodThread

java.lang.Object
  extended by messif.executor.SingleMethodExecutor
      extended by messif.executor.MethodThread
All Implemented Interfaces:
java.lang.Runnable, Executable

public final class MethodThread
extends SingleMethodExecutor
implements java.lang.Runnable

This class allows the background method execution (i.e. in a new thread) using the MethodExecutor interface. Use backgroundExecute method in MethodExecutor to start the execution. Use waitExecutionEnd method to block until the thread finished the execution of the invocated method.


Field Summary
 
Fields inherited from class messif.executor.SingleMethodExecutor
arguments, method, object, returnedValue
 
Constructor Summary
protected MethodThread(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object[] arguments)
          Create new instance of MethodThread The constructor can't be called directly, use backgroundExecute "factory" member of MethodExecutor
protected MethodThread(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object[] arguments, Executable executeBefore, Executable executeAfter)
          Create new instance of MethodThread The constructor can't be called directly, use backgroundExecute "factory" member of MethodExecutor
protected MethodThread(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object[] arguments, java.util.List<Executable> executeBefore, java.util.List<Executable> executeAfter)
          Create new instance of MethodThread The constructor can't be called directly, use backgroundExecute "factory" member of MethodExecutor
 
Method Summary
 java.lang.Exception getException()
          Returns the exception thrown while executing or null if the execution finished with no exception.
 boolean isRunning()
          Returns true if the method is still being executed, otherwise false is returned.
 boolean isSuccess()
          This method waits for the end of execution.
 void run()
          Execute the method inside the thread
 void waitExecutionEnd()
          Wait for the end of the operation execution in specified thread (returned by backgroundExecute) This method will block until the background operation finishes its processing.
 
Methods inherited from class messif.executor.SingleMethodExecutor
execute, getArgument, getArgument, getArgumentCount, getArguments, getDeclaredMethod, getReturnedValue, chooseExecutionObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodThread

protected MethodThread(java.lang.reflect.Method method,
                       java.lang.Object object,
                       java.lang.Object[] arguments)
Create new instance of MethodThread The constructor can't be called directly, use backgroundExecute "factory" member of MethodExecutor

Parameters:
method - method to call on the specified object
object - the executor object, that is used for invocation of methods
arguments - the arguments of the executed method

MethodThread

protected MethodThread(java.lang.reflect.Method method,
                       java.lang.Object object,
                       java.lang.Object[] arguments,
                       java.util.List<Executable> executeBefore,
                       java.util.List<Executable> executeAfter)
Create new instance of MethodThread The constructor can't be called directly, use backgroundExecute "factory" member of MethodExecutor

Parameters:
method - method to call on the specified object
object - the executor object, that is used for invocation of methods
arguments - the arguments of the executed method
executeBefore - list of methods to call before the execution of the method (can be null if no pre/post execution is required)
executeAfter - list of methods to call after the successful execution of the method (can be null if no pre/post execution is required)

MethodThread

protected MethodThread(java.lang.reflect.Method method,
                       java.lang.Object object,
                       java.lang.Object[] arguments,
                       Executable executeBefore,
                       Executable executeAfter)
Create new instance of MethodThread The constructor can't be called directly, use backgroundExecute "factory" member of MethodExecutor

Parameters:
method - method to call on the specified object
object - the executor object, that is used for invocation of methods
arguments - the arguments of the executed method
executeBefore - a method to call before the execution of the method (can be null if no pre/post execution is required)
executeAfter - a method to call after the successful execution of the method (can be null if no pre/post execution is required)
Method Detail

isRunning

public boolean isRunning()
Returns true if the method is still being executed, otherwise false is returned.

Returns:
true if the method is still being executed, otherwise false is returned

isSuccess

public boolean isSuccess()
                  throws java.lang.InterruptedException
This method waits for the end of execution. If the method is already finished, this method returns immediately.

Returns:
true if the execution was successful
Throws:
java.lang.InterruptedException - if the waiting was interrupted

getException

public java.lang.Exception getException()
Returns the exception thrown while executing or null if the execution finished with no exception.

Returns:
the exception thrown in execution

waitExecutionEnd

public void waitExecutionEnd()
                      throws java.lang.InterruptedException
Wait for the end of the operation execution in specified thread (returned by backgroundExecute) This method will block until the background operation finishes its processing.

Throws:
java.lang.InterruptedException - if the waiting was interrupted

run

public void run()
Execute the method inside the thread

Specified by:
run in interface java.lang.Runnable