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 ListenerObjects 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 ListenerObjects.
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
Nested ClassesModifier and TypeClassDescriptionprotected static classThis class represents the outcome of the execution of aListenerObject.protected static classThisAbstractListenerObjectExecutor.ExecutionResultrepresents a successful invocation, along with its result.protected static classThisAbstractListenerObjectExecutor.ExecutionResultrepresents an unsuccessful invocation, where the method threw aThrowable.protected static classThisAbstractListenerObjectExecutor.ExecutionResultrepresents a successful invocation, but no result (method return type was 'void'). -
Constructor Summary
Constructors -
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 allListenerObjects in the givenCollectionand gives the return values back.executeSingleListenerObject(ListenerObject listenerObject, Object... parameters) This method executes a singleListenerObjectand 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:ListenerObjectExecutorExecutes allListenerObjects in the givenCollectionand 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 ofListenerObjectthat are executed may be larger than the number of return values that is returned, because someListenerObjects may return nothing (void). Also note that someListenerObjects in the 'listenerObjects'Collectionmay not match the parameters in the 'parameters' array. Implementation need to take this into account and provide proper error handling. When aListenerObjectdoes not match the parameterObjects, 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 theMethodof theListenerObject. If anyExceptionother thanInvocationTargetExceptionoccurs, it will probably mean that the parameters will not match theMethod. AnInvocationTargetExceptionmeans that there was a successful invocation, but aThrowablewas thrown from the method itself.- Specified by:
executeListenersin interfaceListenerObjectExecutor- Parameters:
listenerObjects- theListenerObjects that have to be executedparameters- the parameters to give to theListenerObjects- Returns:
- the
Responseobject representing the response of this execution
-
executeSingleListenerObject
protected AbstractListenerObjectExecutor.ExecutionResult executeSingleListenerObject(ListenerObject listenerObject, Object... parameters) This method executes a singleListenerObjectand returns the appropriateAbstractListenerObjectExecutor.ExecutionResult. It should be used by subclasses when excuting theListenerObjects.- Parameters:
listenerObject-parameters-- Returns:
- the
AbstractListenerObjectExecutor.ExecutionResultof the execution of theListenerObject, or null if theListenerObjectdid 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
Collectionwith theAbstractListenerObjectExecutor.ExecutionResults of the givenListenerObjects or an emptyCollectionif there are no results, never returns null
-