<commit_before>module Celluloid
  class ActorSystem
    extend Forwardable

    def initialize
      @group = Celluloid.group_class.new
      @registry = Internals::Registry.new
    end
    attr_reader :registry

    # Launch default services
    # FIXME: We should set up the supervision hierarchy here
    def start
      within do
        Celluloid::Notifications::Fanout.supervise_as :notifications_fanout
        Celluloid::IncidentReporter.supervise_as :default_incident_reporter, STDERR
      end
      true
    end

    def within
      old = Thread.current[:celluloid_actor_system]
      Thread.current[:celluloid_actor_system] = self
      yield
    ensure
      Thread.current[:celluloid_actor_system] = old
    end

    def get_thread
      @group.get {
        Thread.current[:celluloid_actor_system] = self
        yield
      }
    end

    def stack_dump
      Internals::StackDump.new(@group)
    end

    def_delegators "@registry", :[], :get, :[]=, :set, :delete

    def registered
      @registry.names
    end

    def clear_registry
      @registry.clear
    end

    def running
      actors = []
      @group.each do |t|
        next unless t.role == :actor
        actors << t.actor.behavior_proxy if t.actor && t.actor.respond_to?(:behavior_proxy)
      end
      actors
    end

    def running?
      @group.active?
    end

    # Shut down all running actors
    def shutdown
      actors = running
      Timeout.timeout(shutdown_timeout) do
        Internals::Logger.debug "Terminating #{actors.size} #{(actors.size > 1) ? 'actors' : 'actor'}..." if actors.size > 0

        # Actors cannot self-terminate, you must do it for them
        actors.each do |actor|
          begin
            actor.terminate!
          rescue DeadActorError
          end
        end

        actors.each do |actor|
          begin
            Actor.join(actor)
          rescue DeadActorError
          end
        end
      end
    rescue Timeout::Error<commit_msg>break up running() to avoid JRuby failure<commit_after>module Celluloid
  class ActorSystem
    extend Forwardable

    def initialize
      @group = Celluloid.group_class.new
      @registry = Internals::Registry.new
    end
    attr_reader :registry

    # Launch default services
    # FIXME: We should set up the supervision hierarchy here
    def start
      within do
        Celluloid::Notifications::Fanout.supervise_as :notifications_fanout
        Celluloid::IncidentReporter.supervise_as :default_incident_reporter, STDERR
      end
      true
    end

    def within
      old = Thread.current[:celluloid_actor_system]
      Thread.current[:celluloid_actor_system] = self
      yield
    ensure
      Thread.current[:celluloid_actor_system] = old
    end

    def get_thread
      @group.get {
        Thread.current[:celluloid_actor_system] = self
        yield
      }
    end

    def stack_dump
      Internals::StackDump.new(@group)
    end

    def_delegators "@registry", :[], :get, :[]=, :set, :delete

    def registered
      @registry.names
    end

    def clear_registry
      @registry.clear
    end

    def running
      actors = []
      @group.each do |t|
        next unless t.role == :actor
        actor = t.actor

        # NOTE - these are in separate statements, since on JRuby t.actor may
        # become nil befor .behavior_proxy() is called
        next unless actor
        next unless actor.respond_to?(:behavior_proxy)
        proxy = actor.behavior_proxy
        actors << proxy
      end
      actors
    end

    def running?
      @group.active?
    end

    # Shut down all running actors
    def shutdown
      actors = running
      Timeout.timeout(shutdown_timeout) do
        Internals::Logger.debug "Terminating #{actors.size} #{(actors.size > 1) ? 'actors' : 'actor'}..." if actors.size > 0

        # Actors cannot self-terminate, you must do it for them
        actors.each do |actor|
          begin
            actor.terminate!
          rescue DeadActorError
          end
        end

        actors.each do |actor|
          begin
            Actor.join(actor)
          rescue DeadActorError
          end
        end
      end
    rescue Timeout::Error
{'fraction_non_alphanumeric': 0.07582260371959942, 'fraction_numerical': 0.0009537434430138292, 'mean_word_length': 2.0777696258253853, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4013602', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1185, 'n_words': 325}