Search in sources :

Example 1 with AsyncConsistentMultimap

use of io.atomix.core.multimap.AsyncConsistentMultimap in project atomix by atomix.

the class ConsistentMultimapProxyBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<ConsistentMultimap<K, V>> buildAsync() {
    PrimitiveProtocol protocol = protocol();
    return managementService.getPartitionService().getPartitionGroup(protocol).getPartition(name()).getPrimitiveClient().newProxy(name(), primitiveType(), protocol).connect().thenApply(proxy -> {
        AsyncConsistentMultimap<String, byte[]> rawMap = new ConsistentSetMultimapProxy(proxy);
        Serializer serializer = serializer();
        return new TranscodingAsyncConsistentMultimap<K, V, String, byte[]>(rawMap, key -> BaseEncoding.base16().encode(serializer.encode(key)), string -> serializer.decode(BaseEncoding.base16().decode(string)), value -> serializer.encode(value), bytes -> serializer.decode(bytes)).sync();
    });
}
Also used : AsyncConsistentMultimap(io.atomix.core.multimap.AsyncConsistentMultimap) BaseEncoding(com.google.common.io.BaseEncoding) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ConsistentMultimapBuilder(io.atomix.core.multimap.ConsistentMultimapBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) ConsistentMultimap(io.atomix.core.multimap.ConsistentMultimap) Serializer(io.atomix.utils.serializer.Serializer) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol) Serializer(io.atomix.utils.serializer.Serializer)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 BaseEncoding (com.google.common.io.BaseEncoding)1 AsyncConsistentMultimap (io.atomix.core.multimap.AsyncConsistentMultimap)1 ConsistentMultimap (io.atomix.core.multimap.ConsistentMultimap)1 ConsistentMultimapBuilder (io.atomix.core.multimap.ConsistentMultimapBuilder)1 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)1 PrimitiveProtocol (io.atomix.primitive.PrimitiveProtocol)1 Serializer (io.atomix.utils.serializer.Serializer)1 CompletableFuture (java.util.concurrent.CompletableFuture)1