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;
});
}
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();
});
}
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();
});
}
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;
}
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());
}
Aggregations