Search in sources :

Example 6 with ServiceConfig

use of io.atomix.primitive.service.ServiceConfig in project atomix by atomix.

the class DefaultDistributedQueueBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedQueue<E>> buildAsync() {
    return newProxy(DistributedQueueService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedQueueProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawQueue -> {
        Serializer serializer = serializer();
        AsyncDistributedQueue<E> queue = new TranscodingAsyncDistributedQueue<>(rawQueue, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
        if (config.getCacheConfig().isEnabled()) {
            queue = new CachingAsyncDistributedQueue<>(queue, config.getCacheConfig());
        }
        if (config.isReadOnly()) {
            queue = new UnmodifiableAsyncDistributedQueue<>(queue);
        }
        return queue.sync();
    });
}
Also used : AsyncDistributedQueue(io.atomix.core.queue.AsyncDistributedQueue) BaseEncoding(com.google.common.io.BaseEncoding) DistributedQueueConfig(io.atomix.core.queue.DistributedQueueConfig) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) DistributedQueue(io.atomix.core.queue.DistributedQueue) CompletableFuture(java.util.concurrent.CompletableFuture) DistributedQueueBuilder(io.atomix.core.queue.DistributedQueueBuilder) Serializer(io.atomix.utils.serializer.Serializer) ServiceConfig(io.atomix.primitive.service.ServiceConfig) Serializer(io.atomix.utils.serializer.Serializer)

Example 7 with ServiceConfig

use of io.atomix.primitive.service.ServiceConfig 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)

Example 8 with ServiceConfig

use of io.atomix.primitive.service.ServiceConfig in project atomix by atomix.

the class DefaultLeaderElectorBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<LeaderElector<T>> buildAsync() {
    return newProxy(LeaderElectorService.class, new ServiceConfig()).thenCompose(proxy -> new LeaderElectorProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(proxy -> {
        Serializer serializer = serializer();
        AsyncLeaderElector<T> elector = new TranscodingAsyncLeaderElector<>(proxy, key -> serializer.encode(key), bytes -> serializer.decode(bytes));
        if (config.getCacheConfig().isEnabled()) {
            elector = new CachingAsyncLeaderElector<T>(elector, config.getCacheConfig());
        }
        return elector.sync();
    });
}
Also used : LeaderElectorBuilder(io.atomix.core.election.LeaderElectorBuilder) AsyncLeaderElector(io.atomix.core.election.AsyncLeaderElector) LeaderElector(io.atomix.core.election.LeaderElector) LeaderElectorConfig(io.atomix.core.election.LeaderElectorConfig) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) Serializer(io.atomix.utils.serializer.Serializer) ServiceConfig(io.atomix.primitive.service.ServiceConfig) Serializer(io.atomix.utils.serializer.Serializer)

Example 9 with ServiceConfig

use of io.atomix.primitive.service.ServiceConfig in project atomix by atomix.

the class DefaultDistributedMultisetBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedMultiset<E>> buildAsync() {
    return newProxy(DistributedMultisetService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedMultisetProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawList -> {
        Serializer serializer = serializer();
        AsyncDistributedMultiset<E> list = new TranscodingAsyncDistributedMultiset<>(rawList, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
        if (config.getCacheConfig().isEnabled()) {
            list = new CachingAsyncDistributedMultiset<>(list, config.getCacheConfig());
        }
        if (config.isReadOnly()) {
            list = new UnmodifiableAsyncDistributedMultiset<>(list);
        }
        return list.sync();
    });
}
Also used : DistributedMultisetConfig(io.atomix.core.multiset.DistributedMultisetConfig) DistributedMultisetBuilder(io.atomix.core.multiset.DistributedMultisetBuilder) BaseEncoding(com.google.common.io.BaseEncoding) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) DistributedMultiset(io.atomix.core.multiset.DistributedMultiset) AsyncDistributedMultiset(io.atomix.core.multiset.AsyncDistributedMultiset) CompletableFuture(java.util.concurrent.CompletableFuture) Serializer(io.atomix.utils.serializer.Serializer) ServiceConfig(io.atomix.primitive.service.ServiceConfig) Serializer(io.atomix.utils.serializer.Serializer)

Example 10 with ServiceConfig

use of io.atomix.primitive.service.ServiceConfig in project atomix by atomix.

the class MultiPrimaryProtocol method newProxy.

@Override
public <S> ProxyClient<S> newProxy(String primitiveName, PrimitiveType primitiveType, Class<S> serviceType, ServiceConfig serviceConfig, PartitionService partitionService) {
    PartitionGroup partitionGroup = partitionService.getPartitionGroup(this);
    if (partitionGroup == null) {
        throw new ConfigurationException("No Raft partition group matching the configured protocol exists");
    }
    Collection<SessionClient> partitions = partitionGroup.getPartitions().stream().map(partition -> ((PrimaryBackupPartition) partition).getClient().sessionBuilder(primitiveName, primitiveType, serviceConfig).withConsistency(config.getConsistency()).withReplication(config.getReplication()).withRecovery(config.getRecovery()).withNumBackups(config.getBackups()).withMaxRetries(config.getMaxRetries()).withRetryDelay(config.getRetryDelay()).build()).collect(Collectors.toList());
    return new DefaultProxyClient<>(primitiveName, primitiveType, this, serviceType, partitions, config.getPartitioner());
}
Also used : PartitionGroup(io.atomix.primitive.partition.PartitionGroup) ProxyProtocol(io.atomix.primitive.protocol.ProxyProtocol) ProxyClient(io.atomix.primitive.proxy.ProxyClient) PrimaryBackupPartition(io.atomix.protocols.backup.partition.PrimaryBackupPartition) Collection(java.util.Collection) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) ConfigurationException(io.atomix.utils.config.ConfigurationException) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimitiveType(io.atomix.primitive.PrimitiveType) PartitionService(io.atomix.primitive.partition.PartitionService) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) SessionClient(io.atomix.primitive.session.SessionClient) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) ConfigurationException(io.atomix.utils.config.ConfigurationException) SessionClient(io.atomix.primitive.session.SessionClient) PrimaryBackupPartition(io.atomix.protocols.backup.partition.PrimaryBackupPartition)

Aggregations

ServiceConfig (io.atomix.primitive.service.ServiceConfig)11 Serializer (io.atomix.utils.serializer.Serializer)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)7 BaseEncoding (com.google.common.io.BaseEncoding)5 ProxyClient (io.atomix.primitive.proxy.ProxyClient)4 PrimitiveType (io.atomix.primitive.PrimitiveType)3 PartitionService (io.atomix.primitive.partition.PartitionService)3 PrimitiveProtocol (io.atomix.primitive.protocol.PrimitiveProtocol)3 ProxyProtocol (io.atomix.primitive.protocol.ProxyProtocol)3 Collection (java.util.Collection)3 Collectors (java.util.stream.Collectors)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 AsyncLeaderElector (io.atomix.core.election.AsyncLeaderElector)1 LeaderElector (io.atomix.core.election.LeaderElector)1 LeaderElectorBuilder (io.atomix.core.election.LeaderElectorBuilder)1 LeaderElectorConfig (io.atomix.core.election.LeaderElectorConfig)1 AsyncDistributedList (io.atomix.core.list.AsyncDistributedList)1 DistributedList (io.atomix.core.list.DistributedList)1