Java Code Examples for org.apache.ratis.util.CollectionUtils#putNew()

The following examples show how to use org.apache.ratis.util.CollectionUtils#putNew() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrpcClientProtocolClient.java    From ratis with Apache License 2.0 6 votes vote down vote up
CompletableFuture<RaftClientReply> onNext(RaftClientRequest request) {
  final Map<Long, CompletableFuture<RaftClientReply>> map = replies.get();
  if (map == null) {
    return JavaUtils.completeExceptionally(new AlreadyClosedException(getName() + " is closed."));
  }
  final CompletableFuture<RaftClientReply> f = new CompletableFuture<>();
  CollectionUtils.putNew(request.getCallId(), f, map,
      () -> getName() + ":" + getClass().getSimpleName());
  try {
    requestStreamObserver.onNext(ClientProtoUtils.toRaftClientRequestProto(request));
    scheduler.onTimeout(requestTimeoutDuration, () -> timeoutCheck(request), LOG,
        () -> "Timeout check failed for client request: " + request);
  } catch(Throwable t) {
    handleReplyFuture(request.getCallId(), future -> future.completeExceptionally(t));
  }
  return f;
}
 
Example 2
Source File: FileInfo.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Integer> submitWrite(
    CheckedSupplier<Integer, IOException> task,
    ExecutorService executor, RaftPeerId id, long index) {
  final CompletableFuture<Integer> f = writeQueue.submit(task, executor,
      e -> new IOException("Failed " + task, e));
  final WriteInfo info = new WriteInfo(f, lastWriteIndex.getAndSet(index));
  CollectionUtils.putNew(index, info, writeInfos, () ->  id + ":writeInfos");
  return f;
}
 
Example 3
Source File: FileInfo.java    From ratis with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Integer> submitWrite(
    CheckedSupplier<Integer, IOException> task,
    ExecutorService executor, RaftPeerId id, long index) {
  final CompletableFuture<Integer> f = writeQueue.submit(task, executor,
      e -> new IOException("Failed " + task, e));
  final WriteInfo info = new WriteInfo(f, lastWriteIndex.getAndSet(index));
  CollectionUtils.putNew(index, info, writeInfos, () ->  id + ":writeInfos");
  return f;
}
 
Example 4
Source File: FileStore.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
void putNew(UnderConstruction uc) {
  LOG.trace("{}: putNew {}", name, uc.getRelativePath());
  CollectionUtils.putNew(uc.getRelativePath(), uc, map, name::toString);
}
 
Example 5
Source File: GrpcClientProtocolService.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
void putNew(OrderedRequestStreamObserver so) {
  CollectionUtils.putNew(so.getId(), so, map, () -> getClass().getSimpleName());
}
 
Example 6
Source File: FileStore.java    From ratis with Apache License 2.0 4 votes vote down vote up
void putNew(UnderConstruction uc) {
  LOG.trace("{}: putNew {}", name, uc.getRelativePath());
  CollectionUtils.putNew(uc.getRelativePath(), uc, map, name::toString);
}