public final class ArgumentConvertingConsumerInvoker extends java.lang.Object implements ConsumerInvoker
ConsumerInvoker will attempt to invoke
a Consumer as-is and, if that fails with a ClassCastException because the
argument declared in the Consumer isn't of the correct type, it tries to find an
object of that type in the array of possible arguments passed to the invoker. If that fails,
it will attempt to use a Converter to convert the argument into a form acceptable to
the Consumer. If the argument is of type Event and the data inside that
event is of a compatible type with the argument to the consumer, this invoker will unwrap that
Event and try to invoke the consumer using the data itself.
Finally, if the Consumer also implements Callable, then it will invoke the Callable.call() method to obtain a return value and return that. Otherwise it will return
null or throw any raised exceptions.| Constructor and Description |
|---|
ArgumentConvertingConsumerInvoker(Converter converter)
Creates a new
ArgumentConvertingConsumerInvoker that will use the given
converter for any necessary argument conversion. |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
invoke(Consumer<?> consumer,
java.lang.Class<? extends T> returnType,
java.lang.Object possibleArg)
Invoke a
Consumer. |
static <T> java.lang.Class<? extends T> |
resolveArgType(Consumer<?> consumer)
Resolves the type of argument that can be
accepted by the
given consumer. |
boolean |
supports(Consumer<?> consumer)
Implementations should decided whether they support the given object or not.
|
public ArgumentConvertingConsumerInvoker(Converter converter)
ArgumentConvertingConsumerInvoker that will use the given
converter for any necessary argument conversion.converter - The converter to be usedpublic <T> T invoke(Consumer<?> consumer, java.lang.Class<? extends T> returnType, java.lang.Object possibleArg) throws java.lang.Exception
ConsumerInvokerConsumer.invoke in interface ConsumerInvokerT - The return type.consumer - The Consumer to invoke.returnType - If the Consumer also implements a value-returning type, convert it to this type before
returning.possibleArg - Possible argument that may or may not be used.java.lang.Exceptionpublic boolean supports(Consumer<?> consumer)
Supports