kafka.common
Class Cluster

java.lang.Object
  extended by 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
 Node nextNode()
          Round-robin over the nodes in this cluster
 java.util.List<Node> nodes()
           
 PartitionInfo partition(TopicPartition topicPartition)
          Get the metadata for the specified partition
 java.util.List<PartitionInfo> partitionsFor(java.lang.String topic)
          Get the list of partitions for this topic
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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

partitionsFor

public java.util.List<PartitionInfo> partitionsFor(java.lang.String topic)
Get the list of partitions for this topic

Parameters:
topic - The topic name
Returns:
A list of partitions

nextNode

public Node nextNode()
Round-robin over the nodes in this cluster