org.apache.kafka.common
Class Cluster

java.lang.Object
  extended by org.apache.kafka.common.Cluster

public final class Cluster
extends java.lang.Object

A representation of a subset of the nodes, topics, and partitions in the Kafka cluster.


Constructor Summary
Cluster(java.util.Collection<Node> nodes, java.util.Collection<PartitionInfo> partitions)
          Create a new cluster with the given nodes and partitions
 
Method Summary
static Cluster bootstrap(java.util.List<java.net.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.
 Node leaderFor(TopicPartition topicPartition)
          Get the current leader for the given topic-partition
 java.util.List<Node> nodes()
           
 PartitionInfo partition(TopicPartition topicPartition)
          Get the metadata for the specified partition
 java.util.List<PartitionInfo> partitionsForNode(int nodeId)
          Get the list of partitions whose leader is this node
 java.util.List<PartitionInfo> partitionsForTopic(java.lang.String topic)
          Get the list of partitions for this topic
 java.util.Set<java.lang.String> topics()
          Get all topics.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cluster

public Cluster(java.util.Collection<Node> nodes,
               java.util.Collection<PartitionInfo> partitions)
Create a new cluster with the given nodes and partitions

Parameters:
nodes - The nodes in the cluster
partitions - 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

nodes

public java.util.List<Node> nodes()
Returns:
The known set of nodes

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

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

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object