class Celluloid::Probe

Constants

EVENTS_BUFFER
NOTIFICATIONS_TOPIC_BASE

Public Class Methods

actor_created(actor) click to toggle source
# File lib/celluloid/probe.rb, line 26
def actor_created(actor)
  trigger_event(:actor_created, actor)
end
actor_died(actor) click to toggle source
# File lib/celluloid/probe.rb, line 34
def actor_died(actor)
  trigger_event(:actor_died, actor)
end
actor_named(actor) click to toggle source
# File lib/celluloid/probe.rb, line 30
def actor_named(actor)
  trigger_event(:actor_named, actor)
end
actors_linked(a, b) click to toggle source
# File lib/celluloid/probe.rb, line 38
def actors_linked(a, b)
  a = find_actor(a)
  b = find_actor(b)
  trigger_event(:actors_linked, a, b)
end
new() click to toggle source
# File lib/celluloid/probe.rb, line 66
def initialize
  async.process_queue
end
run() click to toggle source
# File lib/celluloid/probe.rb, line 17
def run
  # spawn the actor if not found
  supervise_as(:probe_actor) unless Actor[:probe_actor] && Actor[:probe_actor].alive?
end
run_without_supervision() click to toggle source
# File lib/celluloid/probe.rb, line 22
def run_without_supervision
  Actor[:probe_actor] = Celluloid::Probe.new
end

Private Class Methods

find_actor(obj) click to toggle source
# File lib/celluloid/probe.rb, line 57
def find_actor(obj)
  if obj.__send__(:class) == Actor
    obj
  elsif owner = obj.instance_variable_get(OWNER_IVAR)
    owner
  end
end
trigger_event(name, *args) click to toggle source
# File lib/celluloid/probe.rb, line 46
def trigger_event(name, *args)
  # !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
  # rubocop:disable Style/GlobalVars
  return unless $CELLULOID_MONITORING
  # rubocop:enable Style/GlobalVars

  EVENTS_BUFFER << [name, args]
  probe_actor = Actor[:probe_actor]
  probe_actor.async.process_queue if probe_actor
end

Public Instance Methods

dispatch_event(cmd, args) click to toggle source
# File lib/celluloid/probe.rb, line 77
def dispatch_event(cmd, args)
  publish(NOTIFICATIONS_TOPIC_BASE % cmd, args)
end
process_queue() click to toggle source
# File lib/celluloid/probe.rb, line 70
def process_queue
  until EVENTS_BUFFER.empty?
    event = EVENTS_BUFFER.pop
    dispatch_event(*event)
  end
end