Browse Source

s/PartitionChooser/Partitioner/

Evan Huus 12 years ago
parent
commit
4aaecc7b0a
3 changed files with 18 additions and 18 deletions
  1. 0 14
      partition_chooser.go
  2. 14 0
      partitioner.go
  3. 4 4
      producer.go

+ 0 - 14
partition_chooser.go

@@ -1,14 +0,0 @@
-package kafka
-
-import "math/rand"
-
-type PartitionChooser interface {
-	ChoosePartition(key Encoder, partitions int) int
-}
-
-type RandomPartitioner struct {
-}
-
-func (p RandomPartitioner) ChoosePartition(key Encoder, partitions int) int {
-	return rand.Intn(partitions)
-}

+ 14 - 0
partitioner.go

@@ -0,0 +1,14 @@
+package kafka
+
+import "math/rand"
+
+type Partitioner interface {
+	Partition(key Encoder, numPartitions int) int
+}
+
+type RandomPartitioner struct {
+}
+
+func (p RandomPartitioner) Partition(key Encoder, numPartitions int) int {
+	return rand.Intn(numPartitions)
+}

+ 4 - 4
producer.go

@@ -3,12 +3,12 @@ package kafka
 type Producer struct {
 	client            *Client
 	topic             string
-	partitioner       PartitionChooser
+	partitioner       Partitioner
 	responseCondition int16
 	responseTimeout   int32
 }
 
-func NewProducer(client *Client, topic string, partitioner PartitionChooser, responseCondition int16, responseTimeout int32) *Producer {
+func NewProducer(client *Client, topic string, partitioner Partitioner, responseCondition int16, responseTimeout int32) *Producer {
 	return &Producer{client, topic, partitioner, responseCondition, responseTimeout}
 }
 
@@ -22,14 +22,14 @@ func (p *Producer) choosePartition(key Encoder) (int32, error) {
 		return -1, err
 	}
 
-	var partitioner PartitionChooser
+	var partitioner Partitioner
 	if key == nil {
 		partitioner = RandomPartitioner{}
 	} else {
 		partitioner = p.partitioner
 	}
 
-	return partitions[partitioner.ChoosePartition(key, len(partitions))], nil
+	return partitions[partitioner.Partition(key, len(partitions))], nil
 }
 
 func (p *Producer) SendMessage(key, value Encoder) (*ProduceResponse, error) {