Sha256: fdfc7827d6964d462e194a74c50e5e633a350d3aa1b55bea4b2958750fc9539c

Contents?: true

Size: 1.65 KB

Versions: 10

Compression:

Stored size: 1.65 KB

Contents

# encoding: utf-8
# This file is distributed under Ting Yun's license terms.
require 'ting_yun/agent/threading/agent_thread'
require 'ting_yun/agent/event/event_loop'

module TingYun
  module Agent
    module InstanceMethods
      module StartWorkerThread
        def  start_worker_thread(connection_options={})
          TingYun::Agent.logger.debug "Creating Ruby Agent worker thread."
          @worker_thread = TingYun::Agent::Threading::AgentThread.create('Worker Loop') do
            deferred_work!(connection_options)
          end
        end

        # This is the method that is run in a new thread in order to
        # background the harvesting and sending of data during the
        # normal operation of the agent.
        #
        # Takes connection options that determine how we should
        # connect to the server, and loops endlessly - typically we
        # never return from this method unless we're shutting down
        # the agent
        def deferred_work!(connection_options)
          catch_errors do
            TingYun::Agent.disable_all_tracing do
              connect!(connection_options)
              if connected?
                create_and_run_event_loop
              else
                TingYun::Agent.logger.debug "No connection.  Worker thread ending."
              end
            end
          end
        end

        def create_and_run_event_loop
          @event_loop = TingYun::Agent::Event::EventLoop.new

          @event_loop.on(:report_data) do
            transmit_data
          end
          @event_loop.fire_every(Agent.config[:data_report_period], :report_data)

          @event_loop.run
        end
      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/instance_methods/start_worker_thread.rb
tingyun_rpm-1.1.4.2 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.1.4.1 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.1.4 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.1.3 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.1.2 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.1.1 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.1.0 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.0.7 lib/ting_yun/agent/instance_methods/start_worker_thread.rb
tingyun_rpm-1.0.6 lib/ting_yun/agent/instance_methods/start_worker_thread.rb