Class: Moleculer::Registry::EventList::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/moleculer/registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(heartbeat_interval) ⇒ Item

Returns a new instance of Item.



92
93
94
95
# File 'lib/moleculer/registry.rb', line 92

def initialize(heartbeat_interval)
  @heartbeat_interval = heartbeat_interval
  @services           = Concurrent::Hash.new
end

Instance Method Details

#add_service(service) ⇒ Object



97
98
99
100
# File 'lib/moleculer/registry.rb', line 97

def add_service(service)
  @services[service.full_name] ||= NodeList.new(@heartbeat_interval)
  @services[service.full_name].add_node(service.node)
end

#fetch_nodesObject



102
103
104
# File 'lib/moleculer/registry.rb', line 102

def fetch_nodes
  @services.values.map(&:fetch_next_node)
end

#lengthObject



113
114
115
# File 'lib/moleculer/registry.rb', line 113

def length
  @services.map(&:length).inject(0) { |s, a| s + a }
end

#remove_node(node_id) ⇒ Object



106
107
108
109
110
111
# File 'lib/moleculer/registry.rb', line 106

def remove_node(node_id)
  @services.each do |k, list|
    list.remove_node(node_id)
    @services.delete(k) if list.length.zero?
  end
end