Class: Logglier::Client::HTTP::DeliveryThread
- Inherits:
-
Thread
- Object
- Thread
- Logglier::Client::HTTP::DeliveryThread
- Defined in:
- lib/logglier/client/http/threaded.rb
Overview
Note:
Uses NetHTTPProxy
Used by the DeliveryThreadManager to hold a queue, deliver messsages from it and to ensure it’s flushed on program exit.
Instance Method Summary collapse
-
#deliver(message) ⇒ Object
Pushes a message onto the internal queue.
-
#exit! ⇒ Object
Signals the queue that we’re exiting.
-
#initialize(input_uri, opts = {}) ⇒ DeliveryThread
constructor
A new instance of DeliveryThread.
Constructor Details
#initialize(input_uri, opts = {}) ⇒ DeliveryThread
Note:
See NetHTTPProxy for further option processing of opts
Note:
registers an at_exit handler that signals exit intent and joins the thread.
Returns a new instance of DeliveryThread.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/logglier/client/http/threaded.rb', line 48 def initialize(input_uri, opts={}) @input_uri = input_uri opts[:read_timeout] = opts[:read_timeout] || 120 opts[:open_timeout] = opts[:open_timeout] || 120 @http = Logglier::Client::HTTP::NetHTTPProxy.new(@input_uri, opts) @queue = Queue.new @exiting = false super do loop do msg = @queue.pop break if msg == :__delivery_thread_exit_signal__ @http.deliver(msg) end end at_exit { exit! join } end |
Instance Method Details
#deliver(message) ⇒ Object
Pushes a message onto the internal queue
80 81 82 |
# File 'lib/logglier/client/http/threaded.rb', line 80 def deliver() @queue.push() end |
#exit! ⇒ Object
Signals the queue that we’re exiting
74 75 76 77 |
# File 'lib/logglier/client/http/threaded.rb', line 74 def exit! @exiting = true @queue.push :__delivery_thread_exit_signal__ end |