@Override public synchronized void accept(R newValue, Throwable exception) { if (remainingResponses <= 0) return; if (exception != null) { remainingResponses = 0; future.completeExceptionally(exception); } else { remainingResponses--; maybeComplete(); } }
/** * The topic the record was appended to */ public String topic() { return this.topicPartition.topic(); }
private static TopicPartition tp(String topic, int partition) { return new TopicPartition(topic, partition); } }
/** * The partition the record was sent to */ public int partition() { return this.topicPartition.partition(); }
private Node getControllerNode(int controllerId, Collection<Node> brokers) { for (Node broker : brokers) { if (broker.id() == controllerId) return broker; } return null; }
@Override public void onCommit(Map<TopicPartition, OffsetAndMetadata> offsets) { onCommitCount++; if (throwExceptionOnCommit) throw new KafkaException("Injected exception in FilterConsumerInterceptor.onCommit."); }
@Override public String toString() { return topicPartition.toString() + "@" + offset; } }
@Override public String toString() { return String.format("Partition(topic = %s, partition = %d, leader = %s, replicas = %s, isr = %s, offlineReplicas = %s)", topic, partition, leader == null ? "none" : leader.idString(), formatNodeIds(replicas), formatNodeIds(inSyncReplicas), formatNodeIds(offlineReplicas)); }
/** * Create a new mock producer with invented metadata the given autoComplete setting, partitioner and key\value serializers. * * Equivalent to {@link #MockProducer(Cluster, boolean, Partitioner, Serializer, Serializer)} new MockProducer(Cluster.empty(), autoComplete, partitioner, keySerializer, valueSerializer)} */ public MockProducer(final boolean autoComplete, final Partitioner partitioner, final Serializer<K> keySerializer, final Serializer<V> valueSerializer) { this(Cluster.empty(), autoComplete, partitioner, keySerializer, valueSerializer); }
@Override public List<Node> fetchNodes() { return cluster.nodes(); }
/** * Return a future which yields a collection of TopicListing objects. */ public KafkaFuture<Collection<TopicListing>> listings() { return future.thenApply(new KafkaFuture.BaseFunction<Map<String, TopicListing>, Collection<TopicListing>>() { @Override public Collection<TopicListing> apply(Map<String, TopicListing> namesToDescriptions) { return namesToDescriptions.values(); } }); }
/** * Send the updated cluster metadata to all {@link ClusterResourceListener}. * @param cluster Cluster metadata */ public void onUpdate(ClusterResource cluster) { for (ClusterResourceListener clusterResourceListener : clusterResourceListeners) { clusterResourceListener.onUpdate(cluster); } } }
public AllOfAdapter(int remainingResponses, KafkaFuture<?> future) { this.remainingResponses = remainingResponses; this.future = future; maybeComplete(); }
private void maybeComplete() { if (remainingResponses <= 0) future.complete(null); } }
/** * Create a new template. Note that the order of the tags will be preserved. * * @param name the name of the metric; may not be null * @param group the name of the group; may not be null * @param description the description of the metric; may not be null * @param tagsNames the names of the metric tags in the preferred order; none of the tag names should be null */ public MetricNameTemplate(String name, String group, String description, String... tagsNames) { this(name, group, description, getTags(tagsNames)); }
private static TopicPartition tp(String topic, int partition) { return new TopicPartition(topic, partition); } }
/** * Create a new mock producer with invented metadata. * * Equivalent to {@link #MockProducer(Cluster, boolean, Partitioner, Serializer, Serializer)} new MockProducer(Cluster.empty(), false, null, null, null)} */ public MockProducer() { this(Cluster.empty(), false, null, null, null); }
@Override public List<Node> fetchNodes() { return cluster.nodes(); }
/** * Return a future which yields a collection of topic names. */ public KafkaFuture<Set<String>> names() { return future.thenApply(new KafkaFuture.BaseFunction<Map<String, TopicListing>, Set<String>>() { @Override public Set<String> apply(Map<String, TopicListing> namesToListings) { return namesToListings.keySet(); } }); } }