Search in sources :

Example 1 with DistributedQueue

use of io.atomix.core.queue.DistributedQueue in project atomix by atomix.

the class DefaultDistributedQueueBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedQueue<E>> buildAsync() {
    return newProxy(DistributedQueueService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedQueueProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawQueue -> {
        Serializer serializer = serializer();
        AsyncDistributedQueue<E> queue = new TranscodingAsyncDistributedQueue<>(rawQueue, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
        if (config.getCacheConfig().isEnabled()) {
            queue = new CachingAsyncDistributedQueue<>(queue, config.getCacheConfig());
        }
        if (config.isReadOnly()) {
            queue = new UnmodifiableAsyncDistributedQueue<>(queue);
        }
        return queue.sync();
    });
}
Also used : AsyncDistributedQueue(io.atomix.core.queue.AsyncDistributedQueue) BaseEncoding(com.google.common.io.BaseEncoding) DistributedQueueConfig(io.atomix.core.queue.DistributedQueueConfig) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) DistributedQueue(io.atomix.core.queue.DistributedQueue) CompletableFuture(java.util.concurrent.CompletableFuture) DistributedQueueBuilder(io.atomix.core.queue.DistributedQueueBuilder) 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 AsyncDistributedQueue (io.atomix.core.queue.AsyncDistributedQueue)1 DistributedQueue (io.atomix.core.queue.DistributedQueue)1 DistributedQueueBuilder (io.atomix.core.queue.DistributedQueueBuilder)1 DistributedQueueConfig (io.atomix.core.queue.DistributedQueueConfig)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