Class: Kazoo::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/kazoo/topic.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#clusterObject (readonly)

Returns the value of attribute cluster.



4
5
6
# File 'lib/kazoo/topic.rb', line 4

def cluster
  @cluster
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/kazoo/topic.rb', line 4

def name
  @name
end

#partitionsObject

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: ==

Returns:

  • (Boolean)


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

#hashObject



42
43
44
# File 'lib/kazoo/topic.rb', line 42

def hash
  [cluster, name].hash
end

#inspectObject



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_factorObject



24
25
26
# File 'lib/kazoo/topic.rb', line 24

def replication_factor
  partitions.map(&:replication_factor).min
end

#under_replicated?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/kazoo/topic.rb', line 28

def under_replicated?
  partitions.any?(:under_replicated?)
end