Class: Datadog::Statsd::Sender
- Inherits:
-
Object
- Object
- Datadog::Statsd::Sender
- Defined in:
- lib/datadog/statsd/sender.rb
Constant Summary collapse
- CLOSEABLE_QUEUES =
Queue.instance_methods.include?(:close)
Instance Method Summary collapse
- #add(message) ⇒ Object
- #flush(sync: false) ⇒ Object
-
#initialize(message_buffer) ⇒ Sender
constructor
A new instance of Sender.
- #rendez_vous ⇒ Object
- #start ⇒ Object
- #stop(join_worker: true) ⇒ Object
Constructor Details
#initialize(message_buffer) ⇒ Sender
Returns a new instance of Sender.
8 9 10 |
# File 'lib/datadog/statsd/sender.rb', line 8 def initialize() @message_buffer = end |
Instance Method Details
#add(message) ⇒ Object
31 32 33 34 35 |
# File 'lib/datadog/statsd/sender.rb', line 31 def add() raise ArgumentError, 'Start sender first' unless << end |
#flush(sync: false) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/datadog/statsd/sender.rb', line 12 def flush(sync: false) raise ArgumentError, 'Start sender first' unless .push(:flush) rendez_vous if sync end |
#rendez_vous ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/datadog/statsd/sender.rb', line 20 def rendez_vous # Initialize and get the thread's sync queue queue = (Thread.current[:statsd_sync_queue] ||= Queue.new) # tell sender-thread to notify us in the current # thread's queue .push(queue) # wait for the sender thread to send a message # once the flush is done queue.pop end |
#start ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/datadog/statsd/sender.rb', line 37 def start raise ArgumentError, 'Sender already started' if # initialize message queue for background thread @message_queue = Queue.new # start background thread @sender_thread = Thread.new(&method(:send_loop)) end |
#stop(join_worker: true) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/datadog/statsd/sender.rb', line 47 def stop(join_worker: true) = @message_queue .close if sender_thread = @sender_thread sender_thread.join if sender_thread && join_worker end |