Package org.rribbit.execution
Class AbstractListenerObjectExecutor
java.lang.Object
org.rribbit.execution.AbstractListenerObjectExecutor
- All Implemented Interfaces:
ListenerObjectExecutor
- Direct Known Subclasses:
MultiThreadedListenerObjectExecutor
,SequentialListenerObjectExecutor
public abstract class AbstractListenerObjectExecutor
extends Object
implements ListenerObjectExecutor
This
ListenerObjectExecutor
provides a blueprint for the execution of a Collection
of ListenerObject
s and the processing of their results. The
only thing left to implementation subclasses is to actually use the methods provided in this class to actually do the execution. The implementations can decide on, for example, sequential
or multi-threaded execution of the different ListenerObject
s.
Please note that this class uses the java method Method
.invoke() and this method does NOT work with varargs. So, if you want to call a listener method that accepts varargs, you MUST
explicitly pass an array where the varargs are expected, even if that array is empty, otherwise, the method will NOT match and will NOT be executed.- Author:
- G.J. Schouten
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
This class represents the outcome of the execution of aListenerObject
.protected static class
ThisAbstractListenerObjectExecutor.ExecutionResult
represents a successful invocation, along with its result.protected static class
ThisAbstractListenerObjectExecutor.ExecutionResult
represents an unsuccessful invocation, where the method threw aThrowable
.protected static class
ThisAbstractListenerObjectExecutor.ExecutionResult
represents a successful invocation, but no result (method return type was 'void'). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Collection
<AbstractListenerObjectExecutor.ExecutionResult> doExecuteListeners
(Collection<ListenerObject> listenerObjects, Object... parameters) This method should callexecuteSingleListenerObject(ListenerObject, Object...)
on eachListenerObject
, accumulate the results, and return.<T> Response
<T> executeListeners
(Collection<ListenerObject> listenerObjects, Object... parameters) Executes allListenerObject
s in the givenCollection
and gives the return values back.executeSingleListenerObject
(ListenerObject listenerObject, Object... parameters) This method executes a singleListenerObject
and returns the appropriateAbstractListenerObjectExecutor.ExecutionResult
.
-
Constructor Details
-
AbstractListenerObjectExecutor
public AbstractListenerObjectExecutor()
-
-
Method Details
-
executeListeners
public <T> Response<T> executeListeners(Collection<ListenerObject> listenerObjects, Object... parameters) Description copied from interface:ListenerObjectExecutor
Executes allListenerObject
s in the givenCollection
and gives the return values back. There is no guarantee on the ordering of the results. This means that implementations can use any execution order they like. The number ofListenerObject
that are executed may be larger than the number of return values that is returned, because someListenerObject
s may return nothing (void). Also note that someListenerObject
s in the 'listenerObjects'Collection
may not match the parameters in the 'parameters' array. Implementation need to take this into account and provide proper error handling. When aListenerObject
does not match the parameterObject
s, it is to be ignored and not to be incorporated into the results. Generally, the most efficient way of checking this is to just try to call invoke() on theMethod
of theListenerObject
. If anyException
other thanInvocationTargetException
occurs, it will probably mean that the parameters will not match theMethod
. AnInvocationTargetException
means that there was a successful invocation, but aThrowable
was thrown from the method itself.- Specified by:
executeListeners
in interfaceListenerObjectExecutor
- Parameters:
listenerObjects
- theListenerObject
s that have to be executedparameters
- the parameters to give to theListenerObject
s- Returns:
- the
Response
object representing the response of this execution
-
executeSingleListenerObject
protected AbstractListenerObjectExecutor.ExecutionResult executeSingleListenerObject(ListenerObject listenerObject, Object... parameters) This method executes a singleListenerObject
and returns the appropriateAbstractListenerObjectExecutor.ExecutionResult
. It should be used by subclasses when excuting theListenerObject
s.- Parameters:
listenerObject
-parameters
-- Returns:
- the
AbstractListenerObjectExecutor.ExecutionResult
of the execution of theListenerObject
, or null if theListenerObject
did not match the parameters
-
doExecuteListeners
protected abstract Collection<AbstractListenerObjectExecutor.ExecutionResult> doExecuteListeners(Collection<ListenerObject> listenerObjects, Object... parameters) This method should callexecuteSingleListenerObject(ListenerObject, Object...)
on eachListenerObject
, accumulate the results, and return. Typical implementations do this either sequentially, or multi-threaded.- Parameters:
listenerObjects
-parameters
-- Returns:
- a
Collection
with theAbstractListenerObjectExecutor.ExecutionResult
s of the givenListenerObject
s or an emptyCollection
if there are no results, never returns null
-