Search in sources :

Example 1 with AsyncAtomicMultimap

use of io.atomix.core.multimap.AsyncAtomicMultimap 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)

Aggregations

BaseEncoding (com.google.common.io.BaseEncoding)1 AsyncAtomicMultimap (io.atomix.core.multimap.AsyncAtomicMultimap)1 AtomicMultimap (io.atomix.core.multimap.AtomicMultimap)1 AtomicMultimapBuilder (io.atomix.core.multimap.AtomicMultimapBuilder)1 AtomicMultimapConfig (io.atomix.core.multimap.AtomicMultimapConfig)1 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)1 ServiceConfig (io.atomix.primitive.service.ServiceConfig)1 Serializer (io.atomix.utils.serializer.Serializer)1 CompletableFuture (java.util.concurrent.CompletableFuture)1