private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { throw new PrimitiveException(e.getCause()); } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { throw new PrimitiveException(e.getCause()); } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause()); throw new PrimitiveException(e.getCause()); } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause()); throw new PrimitiveException(e.getCause()); } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { throw new PrimitiveException(e.getCause()); } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { if (e.getCause() instanceof PrimitiveException) { throw (PrimitiveException) e.getCause(); } else { throw new PrimitiveException(e.getCause()); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { if (e.getCause() instanceof PrimitiveException) { throw (PrimitiveException) e.getCause(); } else { throw new PrimitiveException(e.getCause()); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { if (e.getCause() instanceof PrimitiveException) { throw (PrimitiveException) e.getCause(); } else { throw new PrimitiveException(e.getCause()); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
private <T> T complete(CompletableFuture<T> future) { try { return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { Throwable cause = Throwables.getRootCause(e); if (cause instanceof PrimitiveException) { throw (PrimitiveException) cause; } else { throw new PrimitiveException(cause); } } } }
@Override public CompletableFuture<PrimitiveInfo> createPrimitive(String name, PrimitiveType type) { PrimitiveInfo info = new PrimitiveInfo(name, type); CompletableFuture<PrimitiveInfo> future = new CompletableFuture<>(); primitives.putIfAbsent(name, type.name()).whenComplete((result, error) -> { if (error != null) { future.completeExceptionally(error); } else if (result == null || result.value().equals(type.name())) { future.complete(info); } else { future.completeExceptionally(new PrimitiveException("A different primitive with the same name already exists")); } }); return future; }
@Override public PrimitiveInfo getPrimitive(String name) { try { return primitives.get(name) .thenApply(value -> value == null ? null : value.map(type -> new PrimitiveInfo(name, primitiveTypeRegistry.getPrimitiveType(type))).value()) .get(DistributedPrimitive.DEFAULT_OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PrimitiveException.Interrupted(); } catch (TimeoutException e) { throw new PrimitiveException.Timeout(); } catch (ExecutionException e) { throw new PrimitiveException(e.getCause()); } }