public final class Cluster extends Object
Constructor and Description |
---|
Cluster(Collection<Node> nodes,
Collection<PartitionInfo> partitions,
Set<String> unauthorizedTopics)
Create a new cluster with the given nodes and partitions
|
Modifier and Type | Method and Description |
---|---|
List<PartitionInfo> |
availablePartitionsForTopic(String topic)
Get the list of available partitions for this topic
|
static Cluster |
bootstrap(List<InetSocketAddress> addresses)
Create a "bootstrap" cluster using the given list of host/ports
|
static Cluster |
empty()
Create an empty cluster instance with no nodes and no topic-partitions.
|
boolean |
isBootstrapConfigured() |
Node |
leaderFor(TopicPartition topicPartition)
Get the current leader for the given topic-partition
|
Node |
nodeById(int id)
Get the node by the node id (or null if no such node exists)
|
List<Node> |
nodes() |
PartitionInfo |
partition(TopicPartition topicPartition)
Get the metadata for the specified partition
|
Integer |
partitionCountForTopic(String topic)
Get the number of partitions for the given topic
|
List<PartitionInfo> |
partitionsForNode(int nodeId)
Get the list of partitions whose leader is this node
|
List<PartitionInfo> |
partitionsForTopic(String topic)
Get the list of partitions for this topic
|
Set<String> |
topics()
Get all topics.
|
String |
toString() |
Set<String> |
unauthorizedTopics() |
Cluster |
withPartitions(Map<TopicPartition,PartitionInfo> partitions)
Return a copy of this cluster combined with `partitions`.
|
public Cluster(Collection<Node> nodes, Collection<PartitionInfo> partitions, Set<String> unauthorizedTopics)
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hostspublic static Cluster empty()
public static Cluster bootstrap(List<InetSocketAddress> addresses)
addresses
- The addressespublic Cluster withPartitions(Map<TopicPartition,PartitionInfo> partitions)
public Node nodeById(int id)
id
- The id of the nodepublic Node leaderFor(TopicPartition topicPartition)
topicPartition
- The topic and partition we want to know the leader forpublic PartitionInfo partition(TopicPartition topicPartition)
topicPartition
- The topic and partition to fetch info forpublic List<PartitionInfo> partitionsForTopic(String topic)
topic
- The topic namepublic List<PartitionInfo> availablePartitionsForTopic(String topic)
topic
- The topic namepublic List<PartitionInfo> partitionsForNode(int nodeId)
nodeId
- The node idpublic Integer partitionCountForTopic(String topic)
topic
- The topic to get the number of partitions forpublic boolean isBootstrapConfigured()