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(force = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/log-courier/client.rb', line 81 def initialize( = {}) @options = { logger: nil, transport: 'tls', spool_size: 1024, idle_timeout: 5, port: nil, addresses: [], min_tls_version: 1.2, disable_handshake: false, }.merge!() @logger = @options[:logger] case @options[:transport] when 'tcp', 'tls' require 'log-courier/client_tcp' @client = ClientTcp.new(@options) else raise 'output/courier: \'transport\' must be tcp or tls' end raise 'output/courier: \'addresses\' must contain at least one address' if @options[:addresses].empty? raise 'output/courier: \'addresses\' only supports a single address at this time' if @options[:addresses].length > 1 @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 # TODO: Make these configurable? @keepalive_timeout = 1800 @network_timeout = 30 # TODO: Make pending payload max configurable? @max_pending_payloads = 100 @retry_payload = nil @received_payloads = Queue.new @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
138 139 140 141 142 |
# File 'lib/log-courier/client.rb', line 138 def publish(event) # Pass the event into the spooler @event_queue << event nil end |
#shutdown(force = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/log-courier/client.rb', line 144 def shutdown(force = false) # rubocop:disable Style/OptionalBooleanParameter if force # Raise a shutdown signal in the spooler and wait for it @spooler_thread.raise ShutdownSignal @spooler_thread.join @io_thread.raise ShutdownSignal else @event_queue.push nil @spooler_thread.join @io_control << ['!', nil] end @io_thread.join @pending_payloads.length.zero? end |