Package org.apache.kafka.common
Class Cluster
- java.lang.Object
-
- org.apache.kafka.common.Cluster
-
public final class Cluster extends java.lang.Object
An immutable representation of a subset of the nodes, topics, and partitions in the Kafka cluster.
-
-
Constructor Summary
Constructors Constructor Description Cluster(java.lang.String clusterId, java.util.Collection<Node> nodes, java.util.Collection<PartitionInfo> partitions, java.util.Set<java.lang.String> unauthorizedTopics, java.util.Set<java.lang.String> internalTopics)
Create a new cluster with the given id, nodes and partitionsCluster(java.lang.String clusterId, java.util.Collection<Node> nodes, java.util.Collection<PartitionInfo> partitions, java.util.Set<java.lang.String> unauthorizedTopics, java.util.Set<java.lang.String> invalidTopics, java.util.Set<java.lang.String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitionsCluster(java.lang.String clusterId, java.util.Collection<Node> nodes, java.util.Collection<PartitionInfo> partitions, java.util.Set<java.lang.String> unauthorizedTopics, java.util.Set<java.lang.String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitions
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<PartitionInfo>
availablePartitionsForTopic(java.lang.String topic)
Get the list of available partitions for this topicstatic Cluster
bootstrap(java.util.List<java.net.InetSocketAddress> addresses)
Create a "bootstrap" cluster using the given list of host/portsClusterResource
clusterResource()
Node
controller()
static Cluster
empty()
Create an empty cluster instance with no nodes and no topic-partitions.boolean
equals(java.lang.Object o)
int
hashCode()
java.util.Set<java.lang.String>
internalTopics()
java.util.Set<java.lang.String>
invalidTopics()
boolean
isBootstrapConfigured()
Node
leaderFor(TopicPartition topicPartition)
Get the current leader for the given topic-partitionNode
nodeById(int id)
Get the node by the node id (or null if no such node exists)java.util.Optional<Node>
nodeIfOnline(TopicPartition partition, int id)
Get the node by node id if the replica for the given partition is onlinejava.util.List<Node>
nodes()
PartitionInfo
partition(TopicPartition topicPartition)
Get the metadata for the specified partitionjava.lang.Integer
partitionCountForTopic(java.lang.String topic)
Get the number of partitions for the given topic.java.util.List<PartitionInfo>
partitionsForNode(int nodeId)
Get the list of partitions whose leader is this nodejava.util.List<PartitionInfo>
partitionsForTopic(java.lang.String topic)
Get the list of partitions for this topicjava.util.Set<java.lang.String>
topics()
Get all topics.java.lang.String
toString()
java.util.Set<java.lang.String>
unauthorizedTopics()
Cluster
withPartitions(java.util.Map<TopicPartition,PartitionInfo> partitions)
Return a copy of this cluster combined with `partitions`.
-
-
-
Constructor Detail
-
Cluster
public Cluster(java.lang.String clusterId, java.util.Collection<Node> nodes, java.util.Collection<PartitionInfo> partitions, java.util.Set<java.lang.String> unauthorizedTopics, java.util.Set<java.lang.String> internalTopics)
Create a new cluster with the given id, nodes and partitions- Parameters:
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hosts
-
Cluster
public Cluster(java.lang.String clusterId, java.util.Collection<Node> nodes, java.util.Collection<PartitionInfo> partitions, java.util.Set<java.lang.String> unauthorizedTopics, java.util.Set<java.lang.String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitions- Parameters:
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hosts
-
Cluster
public Cluster(java.lang.String clusterId, java.util.Collection<Node> nodes, java.util.Collection<PartitionInfo> partitions, java.util.Set<java.lang.String> unauthorizedTopics, java.util.Set<java.lang.String> invalidTopics, java.util.Set<java.lang.String> internalTopics, Node controller)
Create a new cluster with the given id, nodes and partitions- Parameters:
nodes
- The nodes in the clusterpartitions
- Information about a subset of the topic-partitions this cluster hosts
-
-
Method Detail
-
empty
public static Cluster empty()
Create an empty cluster instance with no nodes and no topic-partitions.
-
bootstrap
public static Cluster bootstrap(java.util.List<java.net.InetSocketAddress> addresses)
Create a "bootstrap" cluster using the given list of host/ports- Parameters:
addresses
- The addresses- Returns:
- A cluster for these hosts/ports
-
withPartitions
public Cluster withPartitions(java.util.Map<TopicPartition,PartitionInfo> partitions)
Return a copy of this cluster combined with `partitions`.
-
nodes
public java.util.List<Node> nodes()
- Returns:
- The known set of nodes
-
nodeById
public Node nodeById(int id)
Get the node by the node id (or null if no such node exists)- Parameters:
id
- The id of the node- Returns:
- The node, or null if no such node exists
-
nodeIfOnline
public java.util.Optional<Node> nodeIfOnline(TopicPartition partition, int id)
Get the node by node id if the replica for the given partition is online- Parameters:
partition
-id
-- Returns:
- the node
-
leaderFor
public Node leaderFor(TopicPartition topicPartition)
Get the current leader for the given topic-partition- Parameters:
topicPartition
- The topic and partition we want to know the leader for- Returns:
- The node that is the leader for this topic-partition, or null if there is currently no leader
-
partition
public PartitionInfo partition(TopicPartition topicPartition)
Get the metadata for the specified partition- Parameters:
topicPartition
- The topic and partition to fetch info for- Returns:
- The metadata about the given topic and partition, or null if none is found
-
partitionsForTopic
public java.util.List<PartitionInfo> partitionsForTopic(java.lang.String topic)
Get the list of partitions for this topic- Parameters:
topic
- The topic name- Returns:
- A list of partitions
-
partitionCountForTopic
public java.lang.Integer partitionCountForTopic(java.lang.String topic)
Get the number of partitions for the given topic.- Parameters:
topic
- The topic to get the number of partitions for- Returns:
- The number of partitions or null if there is no corresponding metadata
-
availablePartitionsForTopic
public java.util.List<PartitionInfo> availablePartitionsForTopic(java.lang.String topic)
Get the list of available partitions for this topic- Parameters:
topic
- The topic name- Returns:
- A list of partitions
-
partitionsForNode
public java.util.List<PartitionInfo> partitionsForNode(int nodeId)
Get the list of partitions whose leader is this node- Parameters:
nodeId
- The node id- Returns:
- A list of partitions
-
topics
public java.util.Set<java.lang.String> topics()
Get all topics.- Returns:
- a set of all topics
-
unauthorizedTopics
public java.util.Set<java.lang.String> unauthorizedTopics()
-
invalidTopics
public java.util.Set<java.lang.String> invalidTopics()
-
internalTopics
public java.util.Set<java.lang.String> internalTopics()
-
isBootstrapConfigured
public boolean isBootstrapConfigured()
-
clusterResource
public ClusterResource clusterResource()
-
controller
public Node controller()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-