Class: LogCourier::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/log-courier/client.rb

Overview

Implementation of a single client connection

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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
# File 'lib/log-courier/client.rb', line 92

def initialize(options = {})
  @options = {
    logger:       nil,
    spool_size:   1024,
    idle_timeout: 5
  }.merge!(options)

  @logger = @options[:logger]
  @logger['plugin'] = 'output/courier'

  require 'log-courier/client_tls'
  @client = ClientTls.new(@options)

  @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



127
128
129
130
131
# File 'lib/log-courier/client.rb', line 127

def publish(event)
  # Pass the event into the spooler
  @event_queue << event
  return
end

#shutdownObject



133
134
135
136
137
138
139
140
# File 'lib/log-courier/client.rb', line 133

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 @pending_payloads.length == 0
end