Search in sources :

Example 1 with PrimitiveProtocol

use of io.atomix.primitive.protocol.PrimitiveProtocol in project atomix by atomix.

the class CoreTransactionService method start.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<TransactionService> start() {
    PrimitiveProtocol protocol = managementService.getPartitionService().getSystemPartitionGroup().newProtocol();
    return AtomicMapType.<TransactionId, TransactionInfo>instance().newBuilder("atomix-transactions", new AtomicMapConfig(), managementService).withSerializer(SERIALIZER).withProtocol((ProxyProtocol) protocol).withCacheEnabled().buildAsync().thenApply(transactions -> {
        this.transactions = transactions.async();
        managementService.getMembershipService().addListener(clusterEventListener);
        LOGGER.info("Started");
        started.set(true);
        return this;
    });
}
Also used : AtomicMapConfig(io.atomix.core.map.AtomicMapConfig) ProxyProtocol(io.atomix.primitive.protocol.ProxyProtocol) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) TransactionId(io.atomix.core.transaction.TransactionId)

Example 2 with PrimitiveProtocol

use of io.atomix.primitive.protocol.PrimitiveProtocol in project atomix by atomix.

the class DefaultDistributedSetBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedSet<E>> buildAsync() {
    PrimitiveProtocol protocol = protocol();
    if (protocol instanceof GossipProtocol) {
        if (protocol instanceof SetProtocol) {
            return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((SetProtocol) protocol).<E>newSetDelegate(name, serializer(), managementService)).thenApply(set -> new GossipDistributedSet<>(name, protocol, set))).thenApply(AsyncDistributedSet::sync);
        } else {
            return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol"));
        }
    } else {
        return newProxy(DistributedSetService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedSetProxy((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawSet -> {
            Serializer serializer = serializer();
            AsyncDistributedSet<E> set = new TranscodingAsyncDistributedSet<>(rawSet, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
            if (config.getCacheConfig().isEnabled()) {
                set = new CachingAsyncDistributedSet<>(set, config.getCacheConfig());
            }
            if (config.isReadOnly()) {
                set = new UnmodifiableAsyncDistributedSet<>(set);
            }
            return set.sync();
        });
    }
}
Also used : ProxyClient(io.atomix.primitive.proxy.ProxyClient) BaseEncoding(com.google.common.io.BaseEncoding) CompletableFuture(java.util.concurrent.CompletableFuture) DistributedSetBuilder(io.atomix.core.set.DistributedSetBuilder) DistributedSet(io.atomix.core.set.DistributedSet) DistributedSetConfig(io.atomix.core.set.DistributedSetConfig) SetProtocol(io.atomix.primitive.protocol.set.SetProtocol) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) AsyncDistributedSet(io.atomix.core.set.AsyncDistributedSet) GossipProtocol(io.atomix.primitive.protocol.GossipProtocol) Serializer(io.atomix.utils.serializer.Serializer) Futures(io.atomix.utils.concurrent.Futures) AsyncDistributedSet(io.atomix.core.set.AsyncDistributedSet) ServiceConfig(io.atomix.primitive.service.ServiceConfig) GossipProtocol(io.atomix.primitive.protocol.GossipProtocol) ProxyClient(io.atomix.primitive.proxy.ProxyClient) SetProtocol(io.atomix.primitive.protocol.set.SetProtocol) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) Serializer(io.atomix.utils.serializer.Serializer)

Aggregations

PrimitiveProtocol (io.atomix.primitive.protocol.PrimitiveProtocol)2 BaseEncoding (com.google.common.io.BaseEncoding)1 AtomicMapConfig (io.atomix.core.map.AtomicMapConfig)1 AsyncDistributedSet (io.atomix.core.set.AsyncDistributedSet)1 DistributedSet (io.atomix.core.set.DistributedSet)1 DistributedSetBuilder (io.atomix.core.set.DistributedSetBuilder)1 DistributedSetConfig (io.atomix.core.set.DistributedSetConfig)1 TransactionId (io.atomix.core.transaction.TransactionId)1 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)1 GossipProtocol (io.atomix.primitive.protocol.GossipProtocol)1 ProxyProtocol (io.atomix.primitive.protocol.ProxyProtocol)1 SetProtocol (io.atomix.primitive.protocol.set.SetProtocol)1 ProxyClient (io.atomix.primitive.proxy.ProxyClient)1 ServiceConfig (io.atomix.primitive.service.ServiceConfig)1 Futures (io.atomix.utils.concurrent.Futures)1 Serializer (io.atomix.utils.serializer.Serializer)1 CompletableFuture (java.util.concurrent.CompletableFuture)1