Supporting Lamda Expressions with asynchronous invocations
- Dominant language
- Java
- Stars
- 400
- Forks
- 143
- PR merge metrics
- No merged PRs in 30d
Description
The JAX-RS API 2.0 defines the InvocationCallback interface to specify reaction upon task termination, which includes either task completion or task failure.
With the rise of Java 8 in the incarnation of both, the current Java SE 8 and the future Java EE 8 platforms, Lambda expression are the typical means to express callbacks. Java SE 8 for example was overhauled to allow Lambda expressions as substitutes for lots of previous callback classes, like Runnable and Callable. Not only this made usage of those particular APIs more readible and consise, it also reduces the sheer number of classes to load at runtime.
As Java SE 8 might be very popular at time of JAX-RS 2.1 publication, and as Java EE 8 is assumed to demand JAX-RS 2.1 and Java SE 8 as core technologies, it would be wise and beneficial to define additional APIs which allow to provide two distinct Lambda expressions for processing task termination.
The following serves as a proposal to discuss:
Wherever the InvocationCallback is used in JAX-RS 2.0, there should be an additional, similar method defined accepting a type-sequence of Consumer (onCompletion) and Consumer (onFailure). To illustrate this, the following API...
```
AsyncInvoker.get(InvocationCallback callback)
```
...should get extended by the following API...
```
AsyncInvoker.get(Consumer onCompletion, Consumer onFailure)
```
...to support the use of Lambda expressions.
While it is clear that it is possible to simply write an anonymous class...
```
AsyncInvoker.get(new InvocationCallback() {
public final void completed(final RESPONSE r) {
System.out.println(r);
}
public final void failed(final Throwable t) {
System.err.println(t);
}
});
```
...it is obviously much more consise, easier to read, and potentially faster to execute at runtime, to instead write...
```
AsyncInvoker.get((r) -> System.out::println, (t) -> System.err::println);
```
...to get the rather exactly same reaction.
#### Environment
Java SE 8, Java EE 8
#### Affected Versions
[2.1]
Contributor guide
Assessment
This issue has not been assessed yet.