use of org.apache.ratis.statemachine.StateMachine.DataStream in project incubator-ratis by apache.
the class DataStreamManagement method computeDataStreamIfAbsent.
private CompletableFuture<DataStream> computeDataStreamIfAbsent(RaftClientRequest request) throws IOException {
final Division division = server.getDivision(request.getRaftGroupId());
final ClientInvocationId invocationId = ClientInvocationId.valueOf(request);
final MemoizedSupplier<CompletableFuture<DataStream>> supplier = JavaUtils.memoize(() -> {
final RequestMetrics metrics = getMetrics().newRequestMetrics(RequestType.STATE_MACHINE_STREAM);
final RequestContext context = metrics.start();
return division.getStateMachine().data().stream(request).whenComplete((r, e) -> metrics.stop(context, e == null));
});
final CompletableFuture<DataStream> f = division.getDataStreamMap().computeIfAbsent(invocationId, key -> supplier.get());
if (!supplier.isInitialized()) {
throw new AlreadyExistsException("A DataStream already exists for " + invocationId);
}
return f;
}
Aggregations