Class: NewRelic::Agent::PipeChannelManager::Listener

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/pipe_channel_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListener

Returns a new instance of Listener.



65
66
67
68
69
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 65

def initialize
  @pipes = {}
  @timeout = 360
  @select_timeout = 60
end

Instance Attribute Details

#pipesObject

Returns the value of attribute pipes.



63
64
65
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 63

def pipes
  @pipes
end

#select_timeoutObject

Returns the value of attribute select_timeout.



63
64
65
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 63

def select_timeout
  @select_timeout
end

#threadObject (readonly)

Returns the value of attribute thread.



62
63
64
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 62

def thread
  @thread
end

#timeoutObject

Returns the value of attribute timeout.



63
64
65
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 63

def timeout
  @timeout
end

Instance Method Details

#close_all_pipesObject



113
114
115
116
117
118
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 113

def close_all_pipes
  @pipes.each do |id, pipe|
    pipe.close if pipe
  end
  @pipes = {}
end

#register_pipe(id) ⇒ Object



71
72
73
74
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 71

def register_pipe(id)
  @pipes[id] = Pipe.new
  wake.in << '.'
end

#startObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 76

def start
  return if @started == true
  @started = true
  @thread = NewRelic::Agent::Thread.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.instance.stats_engine \
        .get_stats_no_scope('Supportability/Listeners') \
        .record_data_point((Time.now - now).to_f) if now
      if ready = IO.select(pipes_to_listen_to, [], [], @select_timeout)
        now = Time.now
        pipe = ready[0][0]
        if pipe == wake.out
          pipe.read(1)
        else
          merge_data_from_pipe(pipe)
        end
      end

      break if !should_keep_listening?
    end
  end
  sleep 0.001 # give time for the thread to spawn
end

#started?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 124

def started?
  @started
end

#stopObject



103
104
105
106
107
108
109
110
111
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 103

def stop
  return unless @started == true
  @started = false
  wake.in << '.' unless wake.in.closed?
  @thread.join # make sure we wait for the thread to exit
  close_all_pipes
  @wake.close
  @wake = nil
end

#wakeObject



120
121
122
# File 'lib/new_relic/agent/pipe_channel_manager.rb', line 120

def wake
  @wake ||= Pipe.new
end