Class: NewRelic::Agent::PipeChannelManager::Listener
- Inherits:
-
Object
- Object
- NewRelic::Agent::PipeChannelManager::Listener
- Defined in:
- lib/new_relic/agent/pipe_channel_manager.rb
Instance Attribute Summary collapse
-
#pipes ⇒ Object
Returns the value of attribute pipes.
-
#select_timeout ⇒ Object
Returns the value of attribute select_timeout.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #close_all_pipes ⇒ Object
-
#initialize ⇒ Listener
constructor
A new instance of Listener.
- #register_pipe(id) ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
- #stop_listener_thread ⇒ Object
- #wake ⇒ Object
- #wakeup ⇒ Object
Constructor Details
#initialize ⇒ Listener
Returns a new instance of Listener.
101 102 103 104 105 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 101 def initialize @pipes = {} @timeout = 360 @select_timeout = 60 end |
Instance Attribute Details
#pipes ⇒ Object
Returns the value of attribute pipes.
99 100 101 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 99 def pipes @pipes end |
#select_timeout ⇒ Object
Returns the value of attribute select_timeout.
99 100 101 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 99 def select_timeout @select_timeout end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
98 99 100 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 98 def thread @thread end |
#timeout ⇒ Object
Returns the value of attribute timeout.
99 100 101 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 99 def timeout @timeout end |
Instance Method Details
#close_all_pipes ⇒ Object
159 160 161 162 163 164 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 159 def close_all_pipes @pipes.each do |id, pipe| pipe.close if pipe end @pipes = {} end |
#register_pipe(id) ⇒ Object
111 112 113 114 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 111 def register_pipe(id) @pipes[id] = Pipe.new wakeup end |
#start ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 116 def start return if @started == true @started = true @thread = NewRelic::Agent::AgentThread.new('Pipe Channel Manager') do now = nil loop do clean_up_pipes pipes_to_listen_to = @pipes.values.map{|pipe| pipe.out} + [wake.out] NewRelic::Agent.record_metric('Supportability/Listeners', (Time.now - now).to_f) if now if ready = IO.select(pipes_to_listen_to, [], [], @select_timeout) now = Time.now ready_pipes = ready[0] ready_pipes.each do |pipe| merge_data_from_pipe(pipe) unless pipe == wake.out end wake.out.read(1) if ready_pipes.include?(wake.out) end break unless should_keep_listening? end end sleep 0.001 # give time for the thread to spawn end |
#started? ⇒ Boolean
170 171 172 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 170 def started? @started end |
#stop ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 151 def stop return unless @started == true stop_listener_thread close_all_pipes @wake.close @wake = nil end |
#stop_listener_thread ⇒ Object
145 146 147 148 149 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 145 def stop_listener_thread @started = false wakeup @thread.join end |
#wake ⇒ Object
166 167 168 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 166 def wake @wake ||= Pipe.new end |
#wakeup ⇒ Object
107 108 109 |
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 107 def wakeup wake.in << '.' end |