Search in sources :

Example 1 with AsyncDistributedList

use of io.atomix.core.list.AsyncDistributedList 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)

Aggregations

BaseEncoding (com.google.common.io.BaseEncoding)1 AsyncDistributedList (io.atomix.core.list.AsyncDistributedList)1 DistributedList (io.atomix.core.list.DistributedList)1 DistributedListBuilder (io.atomix.core.list.DistributedListBuilder)1 DistributedListConfig (io.atomix.core.list.DistributedListConfig)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