Search in sources :

Example 6 with PrimitiveProtocol

use of io.atomix.primitive.PrimitiveProtocol 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)6 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)6 PrimitiveProtocol (io.atomix.primitive.PrimitiveProtocol)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Serializer (io.atomix.utils.serializer.Serializer)4 Maps (com.google.common.collect.Maps)3 BaseEncoding (com.google.common.io.BaseEncoding)3 Partition (io.atomix.primitive.partition.Partition)3 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)3 PartitionId (io.atomix.primitive.partition.PartitionId)3 Partitioner (io.atomix.primitive.partition.Partitioner)3 Futures (io.atomix.utils.concurrent.Futures)3 Map (java.util.Map)3 Lists (com.google.common.collect.Lists)2 Hashing (com.google.common.hash.Hashing)2 AsyncLeaderElector (io.atomix.core.election.AsyncLeaderElector)1 LeaderElector (io.atomix.core.election.LeaderElector)1 LeaderElectorBuilder (io.atomix.core.election.LeaderElectorBuilder)1 AsyncConsistentMap (io.atomix.core.map.AsyncConsistentMap)1 AsyncConsistentTreeMap (io.atomix.core.map.AsyncConsistentTreeMap)1