<commit_before>require 'celluloid'

$CELLULOID_MONITORING = true

module Celluloid
  class Probe
    include Celluloid
    
    def self.queue
      @queue ||= Queue.new
    end
    
    def self.probe
      Actor[:probe_actor] or raise DeadActorError, "probe actor not running"
    end
    
    def initialize
      @listeners = {}
    end
    
    def run
      loop do
        dispatch_event(*self.class.queue.pop)
      end
    end

    
    def on_event(filter = nil, &block)
      @listeners[filter] ||= []
      @listeners[filter] << block
    end
    
    def self.actor_created(actor)
      trigger_event(:actor_created, actor)
    end
    
    def self.actor_named(actor)
      trigger_event(:actor_named, actor)
    end
    
    def self.actor_died(actor)
      trigger_event(:actor_died, actor)
    end
    
    def self.actors_linked(a, b)
      a = find_actor(a)
      b = find_actor(b)
      trigger_event(:actors_linked, a, b)
    end

  private
    def dispatch_event(cmd, args)
      if @listeners.has_key?(nil)
        @listeners[nil].each {|cb| cb.call(cmd, *args) }
      end
      
      if @listeners.has_key?(cmd)
        @listeners[cmd].each {|cb| cb.call(cmd, *args) }
      end
    end
    
    def self.trigger_event(name, *args)
      queue << [name, args]
    end
    
    def self.find_actor(obj)
      if obj.__send__(:class) == Actor
        obj
      elsif owner = obj.instance_variable_get(OWNER_IVAR)
        owner
      end
    end
    
  end
end

Celluloid::Probe.supervise_as(:probe_actor)<commit_msg>use internal notifications system<commit_after>require 'celluloid'

$CELLULOID_MONITORING = true

module Celluloid
  class Probe
    include Celluloid
    include Celluloid::Notifications
    
    NOTIFICATIONS_TOPIC_BASE = 'celluloid.events.%s'
    
    def self.queue
      @queue ||= Queue.new
    end
    
    def self.probe
      Actor[:probe_actor] or raise DeadActorError, "probe actor not running"
    end
    
    def run
      loop do
        dispatch_event(*self.class.queue.pop)
      end
    end

    
    def self.actor_created(actor)
      trigger_event(:actor_created, actor)
    end
    
    def self.actor_named(actor)
      trigger_event(:actor_named, actor)
    end
    
    def self.actor_died(actor)
      trigger_event(:actor_died, actor)
    end
    
    def self.actors_linked(a, b)
      a = find_actor(a)
      b = find_actor(b)
      trigger_event(:actors_linked, a, b)
    end

  private
    def dispatch_event(cmd, args)
      publish(NOTIFICATIONS_TOPIC_BASE % cmd, args)
    end
    
    def self.trigger_event(name, *args)
      queue << [name, args]
    end
    
    def self.find_actor(obj)
      if obj.__send__(:class) == Actor
        obj
      elsif owner = obj.instance_variable_get(OWNER_IVAR)
        owner
      end
    end
    
  end
end

Celluloid::Probe.supervise_as(:probe_actor)
{'fraction_non_alphanumeric': 0.09002093510118632, 'fraction_numerical': 0.0, 'mean_word_length': 2.23954802259887, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5794231', 'n_tokens_mistral': 994, 'n_tokens_neox': 972, 'n_words': 207}