Sha256: 199d2eb50cef54d9151c6da76ff452c2c20b75e126cd34486ef7232241d3b81a

Contents?: true

Size: 886 Bytes

Versions: 10

Compression:

Stored size: 886 Bytes

Contents

# encoding: utf-8

module TingYun
  module Agent
    class Dispatcher
      attr_accessor :starting_pid

      def initialize(events, after_forker=TingYun::Agent)
        # We intentionally don't set our pid as started at this point.
        # Startup routines must call mark_started when they consider us set!
        @starting_pid = nil
        @after_forker = after_forker

        if events
          events.subscribe(:start_transaction, &method(:on_transaction))
        end
      end

      def on_transaction(*_)
        return unless needs_restart?

        restart_harvest_thread
      end

      def mark_started(pid = Process.pid)
        @starting_pid = pid
      end

      def needs_restart?(pid = Process.pid)
        @starting_pid != pid
      end

      def restart_harvest_thread
        @after_forker.after_fork(:force_reconnect => true)
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tingyun_rpm-1.2.0 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.1.4.2 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.1.4.1 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.1.4 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.1.3 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.1.2 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.1.1 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.1.0 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.0.7 lib/ting_yun/agent/dispatcher.rb
tingyun_rpm-1.0.6 lib/ting_yun/agent/dispatcher.rb