Interface Invocation
-
- All Known Implementing Classes:
MethodInvocation
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Invocation
Invocation of execution point.This class represents captured invocation of some element in program with all needed data to proceed. It can be analyzed, replaced or just executed at any time.
Depending on the proxy mechanism, this potentially could be any point in program, but most implementations only support capturing method calls into
MethodInvocation
.- See Also:
InvocationHandler
,MethodInvocation
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static Invocation
fromCallable(Callable<?> callable)
AdaptsCallable
to this interface.static Invocation
fromRunnable(Runnable runnable)
AdaptsRunnable
to this interface.Object
invoke()
Invokes the execution point.static Invocation
returning(Object result)
Creates invocation that does only one thing: returns the provided argument.static Invocation
throwing(Supplier<Throwable> thrownSupplier)
Creates invocation that only throws exceptions obtained from supplier.
-
-
-
Method Detail
-
invoke
@Nullable Object invoke() throws Throwable
Invokes the execution point.It will either succeed and return a result, possibly null, or fail and throw an exception.
- Returns:
- result of an invocation.
- Throws:
Throwable
- exception that was thrown by invocation
-
fromRunnable
static Invocation fromRunnable(Runnable runnable)
AdaptsRunnable
to this interface.- Parameters:
runnable
- runnable to run- Returns:
- invocation that when invoked, will call the runnable and if it doesn't throw runtime exception, it will return null.
-
fromCallable
static Invocation fromCallable(Callable<?> callable)
AdaptsCallable
to this interface.- Parameters:
callable
- runnable to run- Returns:
- invocation that when invoked, will call the runnable and if it doesn't throw exception, it will return whatever callable execution returns.
-
returning
static Invocation returning(@Nullable Object result)
Creates invocation that does only one thing: returns the provided argument.- Parameters:
result
- what the invocation should return- Returns:
- invocation that returns provided result.
-
throwing
static Invocation throwing(Supplier<Throwable> thrownSupplier)
Creates invocation that only throws exceptions obtained from supplier.Each execution of the invocation will fetch new exception.
- Parameters:
thrownSupplier
- supplier that will produce exceptions to throw- Returns:
- invocation that throws exception
-
-