/** * Gets or builds a singleton instance of the primitive asynchronously. * <p> * The returned primitive will be shared by all {@code get()} calls for the named primitive. If no instance has yet * been constructed, the instance will be built from this builder's configuration. * * @return a singleton instance of the primitive */ public CompletableFuture<P> getAsync() { return managementService.getPrimitiveCache().getPrimitive(name, this::buildAsync); } }
@Override public Collection<PrimitiveInfo> getPrimitives() { return managementService.getPrimitiveRegistry().getPrimitives(); }
@Override @SuppressWarnings("unchecked") public <C extends PrimitiveConfig<C>, P extends SyncPrimitive> CompletableFuture<P> getPrimitiveAsync( String name, PrimitiveType<?, C, P> primitiveType, C primitiveConfig) { return cache.getPrimitive(name, () -> { C config = primitiveConfig; if (config == null) { config = configService.getConfig(name, primitiveType); } return primitiveType.newBuilder(name, config, managementService).buildAsync(); }); }
/** * Connects the primitive. * * @return a future to be completed once the primitive has been connected */ @SuppressWarnings("unchecked") public CompletableFuture<A> connect() { return registry.createPrimitive(name(), type()) .thenApply(v -> (A) this); }
@SuppressWarnings("unchecked") protected CompletableFuture<P> getPrimitive(String name) { return primitives.getPrimitiveAsync(name, type).thenApply(primitive -> ((SyncPrimitive) primitive).async()); }
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()); } } }
@Override public String name() { return primitive.name(); }
@Override public PrimitiveType type() { return primitive.type(); }
@Override public PrimitiveProtocol protocol() { return primitive.protocol(); }
/** * Creates a snapshot ID from the given number. * * @param id the number from which to create the identifier * @return the snapshot identifier */ public static PrimitiveId from(long id) { return new PrimitiveId(id); }
@Override public CompletableFuture<Void> delete() { return primitive.delete(); }
@Override public void removeStateChangeListener(Consumer<PrimitiveState> listener) { primitive.removeStateChangeListener(listener); }
@Override protected Throwable defaultException() { return new PrimitiveException.CommandFailure("failed to complete command"); }
@Override protected Throwable defaultException() { return new PrimitiveException.QueryFailure("failed to complete query"); }
@Override public void addStateChangeListener(Consumer<PrimitiveState> listener) { primitive.addStateChangeListener(listener); }
@Override public CompletableFuture<Void> close() { return primitive.close(); }
@Override public Collection<PrimitiveInfo> getPrimitives(PrimitiveType primitiveType) { return managementService.getPrimitiveRegistry().getPrimitives(primitiveType); }
@Override public String name() { return primitive.name(); }
@Override public PrimitiveType type() { return primitive.type(); }
@Override public PrimitiveProtocol protocol() { return primitive.protocol(); }