Class: Celluloid::Probe

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Notifications
Defined in:
lib/celluloid/probe.rb

Constant Summary collapse

NOTIFICATIONS_TOPIC_BASE =
"celluloid.events.%s"
EVENTS_BUFFER =
Queue.new

Constants included from Celluloid

CPUCounter, Links, Logger, Properties, Registry, StackDump, ThreadHandle, UUID

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Notifications

notifier, publish, #subscribe, #unsubscribe

Methods included from Celluloid

publish

Constructor Details

#initializeProbe

Returns a new instance of Probe.



60
61
62
# File 'lib/celluloid/probe.rb', line 60

def initialize
  async.process_queue
end

Class Method Details

.actor_created(actor) ⇒ Object



23
24
25
# File 'lib/celluloid/probe.rb', line 23

def actor_created(actor)
  trigger_event(:actor_created, actor)
end

.actor_died(actor) ⇒ Object



31
32
33
# File 'lib/celluloid/probe.rb', line 31

def actor_died(actor)
  trigger_event(:actor_died, actor)
end

.actor_named(actor) ⇒ Object



27
28
29
# File 'lib/celluloid/probe.rb', line 27

def actor_named(actor)
  trigger_event(:actor_named, actor)
end

.actors_linked(a, b) ⇒ Object



35
36
37
38
39
# File 'lib/celluloid/probe.rb', line 35

def actors_linked(a, b)
  a = find_actor(a)
  b = find_actor(b)
  trigger_event(:actors_linked, a, b)
end

.runObject



14
15
16
17
# File 'lib/celluloid/probe.rb', line 14

def run
  # spawn the actor if not found
  supervise_as(:probe_actor) unless Actor[:probe_actor] && Actor[:probe_actor].alive?
end

.run_without_supervisionObject



19
20
21
# File 'lib/celluloid/probe.rb', line 19

def run_without_supervision
  Actor[:probe_actor] = Celluloid::Probe.new
end

Instance Method Details

#dispatch_event(cmd, args) ⇒ Object



71
72
73
# File 'lib/celluloid/probe.rb', line 71

def dispatch_event(cmd, args)
  publish(NOTIFICATIONS_TOPIC_BASE % cmd, args)
end

#process_queueObject



64
65
66
67
68
69
# File 'lib/celluloid/probe.rb', line 64

def process_queue
  until EVENTS_BUFFER.empty?
    event = EVENTS_BUFFER.pop
    dispatch_event(*event)
  end
end