Search in sources :

Example 1 with ServiceConfig

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

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

the class DefaultDistributedListBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedList<E>> buildAsync() {
    return newProxy(DistributedListService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedListProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawList -> {
        Serializer serializer = serializer();
        AsyncDistributedList<E> list = new TranscodingAsyncDistributedList<>(rawList, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
        if (config.getCacheConfig().isEnabled()) {
            list = new CachingAsyncDistributedList<>(list, config.getCacheConfig());
        }
        if (config.isReadOnly()) {
            list = new UnmodifiableAsyncDistributedList<>(list);
        }
        return list.sync();
    });
}
Also used : DistributedListBuilder(io.atomix.core.list.DistributedListBuilder) DistributedListConfig(io.atomix.core.list.DistributedListConfig) BaseEncoding(com.google.common.io.BaseEncoding) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) AsyncDistributedList(io.atomix.core.list.AsyncDistributedList) DistributedList(io.atomix.core.list.DistributedList) CompletableFuture(java.util.concurrent.CompletableFuture) Serializer(io.atomix.utils.serializer.Serializer) ServiceConfig(io.atomix.primitive.service.ServiceConfig) Serializer(io.atomix.utils.serializer.Serializer)

Example 3 with ServiceConfig

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

the class DefaultAtomicMultimapBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<AtomicMultimap<K, V>> buildAsync() {
    return newProxy(AtomicMultimapService.class, new ServiceConfig()).thenCompose(proxy -> new AtomicMultimapProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawMultimap -> {
        Serializer serializer = serializer();
        AsyncAtomicMultimap<K, V> multimap = new TranscodingAsyncAtomicMultimap<>(rawMultimap, key -> BaseEncoding.base16().encode(serializer.encode(key)), string -> serializer.decode(BaseEncoding.base16().decode(string)), value -> serializer.encode(value), bytes -> serializer.decode(bytes));
        if (config.getCacheConfig().isEnabled()) {
            multimap = new CachingAsyncAtomicMultimap<>(multimap, config.getCacheConfig());
        }
        return multimap.sync();
    });
}
Also used : AtomicMultimap(io.atomix.core.multimap.AtomicMultimap) BaseEncoding(com.google.common.io.BaseEncoding) AtomicMultimapBuilder(io.atomix.core.multimap.AtomicMultimapBuilder) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) AsyncAtomicMultimap(io.atomix.core.multimap.AsyncAtomicMultimap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicMultimapConfig(io.atomix.core.multimap.AtomicMultimapConfig) Serializer(io.atomix.utils.serializer.Serializer) ServiceConfig(io.atomix.primitive.service.ServiceConfig) Serializer(io.atomix.utils.serializer.Serializer)

Example 4 with ServiceConfig

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

the class RaftServiceManager method initializeService.

/**
 * Initializes a new service.
 */
@SuppressWarnings("unchecked")
private RaftServiceContext initializeService(PrimitiveId primitiveId, PrimitiveType primitiveType, String serviceName, byte[] config) {
    RaftServiceContext oldService = raft.getServices().getService(serviceName);
    ServiceConfig serviceConfig = config == null ? new ServiceConfig() : Serializer.using(primitiveType.namespace()).decode(config);
    RaftServiceContext service = new RaftServiceContext(primitiveId, serviceName, primitiveType, serviceConfig, primitiveType.newService(serviceConfig), raft, threadContextFactory);
    raft.getServices().registerService(service);
    // If a service with this name was already registered, remove all of its sessions.
    if (oldService != null) {
        raft.getSessions().removeSessions(oldService.serviceId());
    }
    return service;
}
Also used : ServiceConfig(io.atomix.primitive.service.ServiceConfig) RaftServiceContext(io.atomix.protocols.raft.service.RaftServiceContext)

Example 5 with ServiceConfig

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

the class MultiRaftProtocol 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 -> ((RaftPartition) partition).getClient().sessionBuilder(primitiveName, primitiveType, serviceConfig).withMinTimeout(config.getMinTimeout()).withMaxTimeout(config.getMaxTimeout()).withReadConsistency(config.getReadConsistency()).withCommunicationStrategy(config.getCommunicationStrategy()).withRecoveryStrategy(config.getRecoveryStrategy()).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) Collection(java.util.Collection) RaftPartition(io.atomix.protocols.raft.partition.RaftPartition) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) 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) DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) ConfigurationException(io.atomix.utils.config.ConfigurationException) SessionClient(io.atomix.primitive.session.SessionClient)

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