Class: StatsD::Instrument::BatchedUDPSink::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/statsd/instrument/batched_udp_sink.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, buffer_capacity, thread_priority, max_packet_size) ⇒ Dispatcher

Returns a new instance of Dispatcher.



77
78
79
80
81
82
83
84
85
86
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 77

def initialize(host, port, buffer_capacity, thread_priority, max_packet_size)
  @udp_sink = UDPSink.new(host, port)
  @interrupted = false
  @thread_priority = thread_priority
  @max_packet_size = max_packet_size
  @buffer_capacity = buffer_capacity
  @buffer = Buffer.new(buffer_capacity)
  @dispatcher_thread = Thread.new { dispatch }
  @pid = Process.pid
end

Instance Method Details

#<<(datagram) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 88

def <<(datagram)
  if !thread_healthcheck || !@buffer.push_nonblock(datagram)
    # The buffer is full or the thread can't be respaned,
    # we'll send the datagram synchronously
    @udp_sink << datagram
  end

  self
end

#shutdown(wait = 2) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/statsd/instrument/batched_udp_sink.rb', line 98

def shutdown(wait = 2)
  @interrupted = true
  @buffer.close
  if @dispatcher_thread&.alive?
    @dispatcher_thread.join(wait)
  end
  flush(blocking: false)
end