module Mongo::Monitoring::Global

Provides behaviour around global subscribers.

@since 2.1.0

Public Instance Methods

subscribe(topic, subscriber) click to toggle source

Subscribe a listener to an event topic.

@example Subscribe to the topic.

Monitoring::Global.subscribe(QUERY, subscriber)

@param [ String ] topic The event topic. @param [ Object ] subscriber The subscriber to handle the event.

@since 2.1.0

# File lib/mongo/monitoring.rb, line 99
def subscribe(topic, subscriber)
  subscribers_for(topic).push(subscriber)
end
subscribers() click to toggle source

Get all the global subscribers.

@example Get all the global subscribers.

Monitoring::Global.subscribers

@return [ Hash<String, Object> ] The subscribers.

@since 2.1.0

# File lib/mongo/monitoring.rb, line 111
def subscribers
  @subscribers ||= {}
end

Private Instance Methods

subscribers_for(topic) click to toggle source
# File lib/mongo/monitoring.rb, line 117
def subscribers_for(topic)
  subscribers[topic] ||= []
end