Search in sources :

Example 1 with PrimitiveInfo

use of io.atomix.primitive.PrimitiveInfo in project atomix by atomix.

the class CorePrimitiveRegistry method createPrimitive.

@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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) PrimitiveInfo(io.atomix.primitive.PrimitiveInfo) PrimitiveException(io.atomix.primitive.PrimitiveException)

Example 2 with PrimitiveInfo

use of io.atomix.primitive.PrimitiveInfo in project atomix by atomix.

the class RaftTest method createPrimitive.

/**
 * Creates a new primitive instance.
 */
private TestPrimitive createPrimitive(RaftClient client, ReadConsistency consistency) throws Exception {
    SessionClient partition = createSession(client, consistency);
    ProxyClient<TestPrimitiveService> proxy = new DefaultProxyClient<>("test", TestPrimitiveType.INSTANCE, MultiRaftProtocol.builder().build(), TestPrimitiveService.class, Collections.singletonList(partition), (key, partitions) -> partitions.get(0));
    PrimitiveRegistry registry = mock(PrimitiveRegistry.class);
    when(registry.createPrimitive(any(String.class), any(PrimitiveType.class))).thenReturn(CompletableFuture.completedFuture(new PrimitiveInfo("raft-test", TestPrimitiveType.INSTANCE)));
    when(registry.deletePrimitive(any(String.class))).thenReturn(CompletableFuture.completedFuture(null));
    return new TestPrimitiveImpl(proxy, registry);
}
Also used : DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) PrimitiveInfo(io.atomix.primitive.PrimitiveInfo) SessionClient(io.atomix.primitive.session.SessionClient) PrimitiveRegistry(io.atomix.primitive.PrimitiveRegistry) PrimitiveType(io.atomix.primitive.PrimitiveType)

Aggregations

PrimitiveInfo (io.atomix.primitive.PrimitiveInfo)2 PrimitiveException (io.atomix.primitive.PrimitiveException)1 PrimitiveRegistry (io.atomix.primitive.PrimitiveRegistry)1 PrimitiveType (io.atomix.primitive.PrimitiveType)1 DefaultProxyClient (io.atomix.primitive.proxy.impl.DefaultProxyClient)1 SessionClient (io.atomix.primitive.session.SessionClient)1 CompletableFuture (java.util.concurrent.CompletableFuture)1