Class: Kazoo::Topic
- Inherits:
-
Object
- Object
- Kazoo::Topic
- Defined in:
- lib/kazoo/topic.rb
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#partitions ⇒ Object
Returns the value of attribute partitions.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(cluster, name, partitions: nil) ⇒ Topic
constructor
A new instance of Topic.
- #inspect ⇒ Object
- #partition(*args) ⇒ Object
- #replication_factor ⇒ Object
- #under_replicated? ⇒ Boolean
Constructor Details
#initialize(cluster, name, partitions: nil) ⇒ Topic
Returns a new instance of Topic.
7 8 9 |
# File 'lib/kazoo/topic.rb', line 7 def initialize(cluster, name, partitions: nil) @cluster, @name, @partitions = cluster, name, partitions end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
4 5 6 |
# File 'lib/kazoo/topic.rb', line 4 def cluster @cluster end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/kazoo/topic.rb', line 4 def name @name end |
#partitions ⇒ Object
Returns the value of attribute partitions.
5 6 7 |
# File 'lib/kazoo/topic.rb', line 5 def partitions @partitions end |
Class Method Details
.from_json(cluster, name, json) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/kazoo/topic.rb', line 11 def self.from_json(cluster, name, json) topic = new(cluster, name) topic.partitions = json.fetch('partitions').map do |(id, replicas)| topic.partition(id.to_i, replicas: replicas.map { |b| cluster.brokers[b] }) end.sort_by(&:id) return topic end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
36 37 38 |
# File 'lib/kazoo/topic.rb', line 36 def eql?(other) other.kind_of?(Kazoo::Topic) && cluster == other.cluster && name == other.name end |
#hash ⇒ Object
42 43 44 |
# File 'lib/kazoo/topic.rb', line 42 def hash [cluster, name].hash end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/kazoo/topic.rb', line 32 def inspect "#<Kazoo::Topic #{name}>" end |
#partition(*args) ⇒ Object
20 21 22 |
# File 'lib/kazoo/topic.rb', line 20 def partition(*args) Kazoo::Partition.new(self, *args) end |
#replication_factor ⇒ Object
24 25 26 |
# File 'lib/kazoo/topic.rb', line 24 def replication_factor partitions.map(&:replication_factor).min end |
#under_replicated? ⇒ Boolean
28 29 30 |
# File 'lib/kazoo/topic.rb', line 28 def under_replicated? partitions.any?(:under_replicated?) end |