public DistributedLogClient( LogProtocol protocol, Collection<LogSession> partitions, Partitioner<String> partitioner) { this.protocol = checkNotNull(protocol, "protocol cannot be null"); this.partitioner = checkNotNull(partitioner, "partitioner cannot be null"); partitions.forEach(partition -> { this.partitionIds.add(partition.partitionId()); this.partitions.put(partition.partitionId(), partition); this.sortedPartitions.add(partition); states.put(partition.partitionId(), PrimitiveState.CLOSED); partition.addStateChangeListener(state -> onStateChange(partition.partitionId(), state)); }); }
@Override public CompletableFuture<Void> close() { return session.close(); }
@Override public PartitionId partitionId() { return session.partitionId(); }
@Override public CompletableFuture<Void> consume(long offset, Consumer<Record<E>> consumer) { return session.consumer().consume(offset, record -> consumer.accept(new Record<E>(record.index(), record.timestamp(), decode(record.value())))); }
@Override public void addStateChangeListener(Consumer<PrimitiveState> listener) { session.addStateChangeListener(listener); }
@Override public PrimitiveState getState() { return session.getState(); }
/** * Produces the given bytes to the partition. * * @param bytes the bytes to produce * @return a future to be completed once the bytes have been written to the partition */ CompletableFuture<Void> produce(byte[] bytes) { return session.producer().append(bytes).thenApply(v -> null); }
@Override public void removeStateChangeListener(Consumer<PrimitiveState> listener) { session.removeStateChangeListener(listener); }
@Override public ThreadContext context() { return session.context(); }
@Override public int id() { return session.partitionId().id(); }
@Override public CompletableFuture<Void> consume(long offset, Consumer<Record<E>> consumer) { return session.consumer().consume(offset, record -> consumer.accept(new Record<E>(record.index(), record.timestamp(), decode(record.value())))); }
/** * 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(); } }
/** * Produces the given bytes to the partition. * * @param bytes the bytes to produce * @return a future to be completed once the bytes have been written to the partition */ CompletableFuture<Void> produce(byte[] bytes) { return session.producer().append(bytes).thenApply(v -> null); }
public DistributedLogClient( LogProtocol protocol, Collection<LogSession> partitions, Partitioner<String> partitioner) { this.protocol = checkNotNull(protocol, "protocol cannot be null"); this.partitioner = checkNotNull(partitioner, "partitioner cannot be null"); partitions.forEach(partition -> { this.partitionIds.add(partition.partitionId()); this.partitions.put(partition.partitionId(), partition); this.sortedPartitions.add(partition); states.put(partition.partitionId(), PrimitiveState.CLOSED); partition.addStateChangeListener(state -> onStateChange(partition.partitionId(), state)); }); }
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 CompletableFuture<Void> close() { return session.close(); }
/** * Invokes a void method on the underlying proxy. * * @param operation the operation to perform on the proxy * @return the resulting void future */ CompletableFuture<Void> accept(Consumer<S> operation) { operation.accept(proxy); return handler.getResultFuture(); }
@Override public int id() { return session.partitionId().id(); }
@Override public CompletableFuture<Void> close() { return session.close(); }