/** * Returns the partition for the given key. * * @param key the key for which to return the partition * @return the partition for the given key */ default LogSession getPartition(String key) { return getPartition(getPartitionId(key)); }
/** * Adds a new consumer. * * @param consumer the consumer to add * @return a future to be completed once the consumer has been added */ default CompletableFuture<Void> consume(Consumer<LogRecord> consumer) { return consume(1, consumer); }
@Override public CompletableFuture<Void> delete() { return client.close(); } }
public DefaultAsyncDistributedLog(String name, LogClient client, Serializer serializer) { this.name = checkNotNull(name); this.client = checkNotNull(client); this.serializer = checkNotNull(serializer); client.getPartitions().forEach(partition -> { DefaultAsyncDistributedLogPartition<E> logPartition = new DefaultAsyncDistributedLogPartition<>(this, partition, serializer); partitions.put(partition.partitionId().id(), logPartition); sortedPartitions.add(logPartition); }); }
@Override public PartitionId partitionId() { return session.partitionId(); }
@Override public CompletableFuture<Void> close() { return session.close(); }
@Override public PartitionId getPartitionId(String key) { return client.getPartitionId(key); }
@Override public void addStateChangeListener(Consumer<PrimitiveState> listener) { session.addStateChangeListener(listener); }
@Override public PrimitiveState getState() { return session.getState(); }
@Override public void removeStateChangeListener(Consumer<PrimitiveState> listener) { session.removeStateChangeListener(listener); }
@Override public PrimitiveProtocol protocol() { return client.protocol(); }
@Override public ThreadContext context() { return session.context(); }
@Override public int id() { return session.partitionId().id(); }
@Override public CompletableFuture<Void> close() { return session.close(); }
@Override public PartitionId getPartitionId(Object key) { return client.getPartitionId(BaseEncoding.base16().encode(serializer.encode(key))); } }
@Override public CompletableFuture<Void> close() { return client.close(); }
/** * Invokes a function on the underlying proxy. * * @param operation the operation to perform on the proxy * @param <T> the operation return type * @return the future result */ <T> CompletableFuture<T> apply(Function<S, T> operation) { operation.apply(proxy); return handler.getResultFuture(); } }