Search in sources :

Example 1 with PrimitiveRegistry

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

the class CorePrimitiveRegistry method start.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<PrimitiveRegistry> start() {
    ProxyProtocol protocol = partitionService.getSystemPartitionGroup().newProtocol();
    ProxyClient proxy = protocol.newProxy("primitives", AtomicMapType.instance(), AtomicMapService.class, new ServiceConfig(), partitionService);
    return proxy.connect().thenApply(v -> {
        AtomicMapProxy mapProxy = new AtomicMapProxy(proxy, this);
        primitives = new TranscodingAsyncAtomicMap<>(mapProxy, key -> key, key -> key, value -> value != null ? SERIALIZER.encode(value) : null, value -> value != null ? SERIALIZER.decode(value) : null);
        started.set(true);
        return this;
    });
}
Also used : DistributedPrimitive(io.atomix.primitive.DistributedPrimitive) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PrimitiveTypeRegistry(io.atomix.primitive.PrimitiveTypeRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) Namespaces(io.atomix.utils.serializer.Namespaces) ManagedPrimitiveRegistry(io.atomix.primitive.ManagedPrimitiveRegistry) PrimitiveInfo(io.atomix.primitive.PrimitiveInfo) TranscodingAsyncAtomicMap(io.atomix.core.map.impl.TranscodingAsyncAtomicMap) AtomicMapService(io.atomix.core.map.impl.AtomicMapService) AsyncAtomicMap(io.atomix.core.map.AsyncAtomicMap) AtomicMapProxy(io.atomix.core.map.impl.AtomicMapProxy) ProxyProtocol(io.atomix.primitive.protocol.ProxyProtocol) ProxyClient(io.atomix.primitive.proxy.ProxyClient) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Collectors(java.util.stream.Collectors) PrimitiveRegistry(io.atomix.primitive.PrimitiveRegistry) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimitiveType(io.atomix.primitive.PrimitiveType) PartitionService(io.atomix.primitive.partition.PartitionService) AtomicMapType(io.atomix.core.map.AtomicMapType) PrimitiveException(io.atomix.primitive.PrimitiveException) Serializer(io.atomix.utils.serializer.Serializer) AtomicMapProxy(io.atomix.core.map.impl.AtomicMapProxy) ServiceConfig(io.atomix.primitive.service.ServiceConfig) ProxyClient(io.atomix.primitive.proxy.ProxyClient) ProxyProtocol(io.atomix.primitive.protocol.ProxyProtocol)

Example 2 with PrimitiveRegistry

use of io.atomix.primitive.PrimitiveRegistry 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 PrimitiveRegistry (io.atomix.primitive.PrimitiveRegistry)2 PrimitiveType (io.atomix.primitive.PrimitiveType)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 AsyncAtomicMap (io.atomix.core.map.AsyncAtomicMap)1 AtomicMapType (io.atomix.core.map.AtomicMapType)1 AtomicMapProxy (io.atomix.core.map.impl.AtomicMapProxy)1 AtomicMapService (io.atomix.core.map.impl.AtomicMapService)1 TranscodingAsyncAtomicMap (io.atomix.core.map.impl.TranscodingAsyncAtomicMap)1 DistributedPrimitive (io.atomix.primitive.DistributedPrimitive)1 ManagedPrimitiveRegistry (io.atomix.primitive.ManagedPrimitiveRegistry)1 PrimitiveException (io.atomix.primitive.PrimitiveException)1 PrimitiveTypeRegistry (io.atomix.primitive.PrimitiveTypeRegistry)1 PartitionService (io.atomix.primitive.partition.PartitionService)1 ProxyProtocol (io.atomix.primitive.protocol.ProxyProtocol)1 ProxyClient (io.atomix.primitive.proxy.ProxyClient)1 DefaultProxyClient (io.atomix.primitive.proxy.impl.DefaultProxyClient)1 ServiceConfig (io.atomix.primitive.service.ServiceConfig)1 SessionClient (io.atomix.primitive.session.SessionClient)1 Namespaces (io.atomix.utils.serializer.Namespaces)1