@SuppressWarnings("unchecked") protected CompletableFuture<P> getPrimitive(String name) { return primitives.getPrimitiveAsync(name, type).thenApply(primitive -> ((SyncPrimitive) primitive).async()); }
/** * Gets or creates a distributed primitive. * <p> * A new primitive of the given {@code primitiveType} will be created if no primitive instance with the given * {@code name} exists on this node, otherwise the existing instance will be returned. The name is used to reference * a distinct instance of the primitive within the cluster. The returned primitive will share the same state with * primitives of the same name on other nodes. * <p> * When the instance is initially constructed, it will be configured with any pre-existing primitive configuration * defined in {@code atomix.conf}. * <p> * To get an asynchronous instance of the primitive, use the {@link SyncPrimitive#async()} method: * <pre> * {@code * AsyncPrimitive async = atomix.getPrimitive("my-primitive").async(); * } * </pre> * * @param name the primitive name * @param primitiveType the primitive type * @param <P> the primitive type * @return the primitive instance */ default <P extends SyncPrimitive> P getPrimitive(String name, PrimitiveType<?, ?, P> primitiveType) { try { return getPrimitiveAsync(name, primitiveType).get(30, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new AtomixRuntimeException(e); } }
@POST @Path("{name}") @Consumes(MediaType.APPLICATION_JSON) @SuppressWarnings("unchecked") public void create( @PathParam("name") String name, C config, @Suspended AsyncResponse response) { primitives.getPrimitiveAsync(name, type, config).whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok().build()); } else { response.resume(error); } }); }
C primitiveConfig) { try { return getPrimitiveAsync(name, primitiveType, primitiveConfig).get(30, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new AtomixRuntimeException(e);
@SuppressWarnings("unchecked") protected CompletableFuture<P> getPrimitive(String name) { return primitives.getPrimitiveAsync(name, type).thenApply(primitive -> ((SyncPrimitive) primitive).async()); }
@POST @Path("{name}") @Consumes(MediaType.APPLICATION_JSON) @SuppressWarnings("unchecked") public void create( @PathParam("name") String name, C config, @Suspended AsyncResponse response) { primitives.getPrimitiveAsync(name, type, config).whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok().build()); } else { response.resume(error); } }); }