-
Notifications
You must be signed in to change notification settings - Fork 8
Result
Result
is the result of an async operation. This was modeled after Vert.x AsyncResult
and after the types of results one would deal with in JavaScript. A Promise
is both a Result
and a Callback
.
employeeService.lookupEmployee(33, result -> {
result.then(e -> saveEmployee(e))
.catchError(error -> {
logger.error("Unable to lookup", error);
});
});
employeeService.lookupEmployee(33, result -> {
result.thenExpect(Expected -> Expected.ifPresent(e -> saveEmployee(e)))
.catchError(error -> {
logger.error("Unable to lookup", error);
});
});
####Result
package io.advantageous.reakt;
import io.advantageous.reakt.impl.ResultImpl;
import java.util.function.Consumer;
/**
* The result of an async operation.
* <p>
* This was modeled after Vert.x AsyncResult and after the types of results one would deal with in JavaScript.
*
* @param <T> type of value expected in the result.
*/
public interface Result<T> {
/**
* Create a result
*
* @param value value
* @param <T> T
* @return result
*/
static <T> Result<T> result(T value) {
return new ResultImpl<>(value);
}
/**
* Create a result
*
* @param error error
* @param <T> T
* @return result
*/
static <T> Result<T> error(Throwable error) {
return new ResultImpl<>(error);
}
/**
* If a result is sent, and there was no error, then handle the result.
*
* @param consumer executed if result has no error.
* @throws NullPointerException if result is present and {@code consumer} is
* null
*/
Result<T> then(Consumer<T> consumer);
/**
* If a result is sent, and there was no error, then handle the result as a value which could be null.
*
* @param consumer executed if result has no error.
* @throws NullPointerException if result is present and {@code consumer} is
* null
*/
Result<T> thenExpect(Consumer<Expected<T>> consumer);
/**
* If a result is sent, and there is an error, then handle handle the error.
*
* @param consumer executed if result has error.
* @throws NullPointerException if result is present and {@code consumer} is
* null
*/
Result<T> catchError(Consumer<Throwable> consumer);
/**
* @return true if result is sent successfully.
*/
boolean success();
/**
* @return true if result is sent and this is the last result.
*/
boolean complete();
/**
* If failure is true then cause will not be null.
*
* @return true if result is sent and result outcome is a failure.
*/
boolean failure();
/**
* If failure is true, the cause will not be null.
*
* @return cause of error associated with the result
*/
Throwable cause();
/**
* If the value of the result can be null, it is better to use Expected which is like Optional.
*
* @return value associated with a successful result.
*/
Expected<T> expect();
/**
* Raw value of the result.
* You should not use this if the result could be null, use getExpected instead.
*
* @return raw value associated with the result.
*/
T get();
}
Reakt throws exceptions when you call get()
on a result
or promise
and the result
or promise
is in an error state.
If the cause
is a RuntimeException, then the original exception will be thrown.
If the cause
is not a RuntimeException, then it will be wrapped in on of the following RuntimeExceptions.
- RejectedPromiseException - The promise was rejected with a non-runtime Exception.
- ResultFailedException - The
result
failed due to a non-runtime Exception. - ThenHandlerException - The
promise
was successful but yourthen
handler orthenExpect
handler threw an exception.
Java Promises
- Promise
- Promise then*() and catchError()
- Promise thenMap()
- Promise all()
- Promise any()
- Blocking Promise
- Invokable Promise
- Reactor Replay Promises
Reactor, Stream, Results
- QBit Reactive Microservices
- Reakt Reactive Java
- Reakt Guava Bridge
- QBit Extensions
- Elekt Consul Leadership election
- Elekt Leadership election
- Reactive Microservices
What is Microservices Architecture?
QBit Java Micorservices lib tutorials
The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
Reactive Programming, Java Microservices, Rick Hightower
Java Microservices Architecture
[Microservice Service Discovery with Consul] (http://www.mammatustech.com/Microservice-Service-Discovery-with-Consul)
Microservices Service Discovery Tutorial with Consul
[Reactive Microservices] (http://www.mammatustech.com/reactive-microservices)
[High Speed Microservices] (http://www.mammatustech.com/high-speed-microservices)
Reactive Microservices Tutorial, using the Reactor
QBit is mentioned in the Restlet blog
All code is written using JetBrains Idea - the best IDE ever!
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting
Java Promises
- Promise
- Promise then*() and catchError()
- Promise thenMap()
- Promise all()
- Promise any()
- Blocking Promise
- Invokable Promise
- Reactor Replay Promises
Callback, and async Results
Reactor, Stream and Stream Result
Expected & Circuit Breaker
Scala Akka and Reakt