Class: LogCourier::Client
- Inherits:
-
Object
- Object
- LogCourier::Client
- Defined in:
- lib/log-courier/client.rb
Overview
Implementation of a single client connection
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #publish(event) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/log-courier/client.rb', line 53 def initialize( = {}) @options = { logger: nil, spool_size: 1024, idle_timeout: 5 }.merge!() @logger = @options[:logger] @logger['plugin'] = 'output/courier' require 'log-courier/client_tls' @client = ClientTls.new(@options) # Load the json adapter @json_adapter = MultiJson.adapter.instance @event_queue = EventQueue.new @options[:spool_size] @pending_payloads = {} @first_payload = nil @last_payload = nil # Start the spooler which will collect events into chunks @send_ready = false @send_mutex = Mutex.new @send_cond = ConditionVariable.new @spooler_thread = Thread.new do run_spooler end @pending_ping = false # Start the IO thread @io_control = EventQueue.new 1 @io_thread = Thread.new do run_io end end |
Instance Method Details
#publish(event) ⇒ Object
91 92 93 94 95 |
# File 'lib/log-courier/client.rb', line 91 def publish(event) # Pass the event into the spooler @event_queue << event return end |
#shutdown ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/log-courier/client.rb', line 97 def shutdown # Raise a shutdown signal in the spooler and wait for it @spooler_thread.raise ShutdownSignal @io_thread.raise ShutdownSignal @spooler_thread.join @io_thread.join return end |