Class: Fluent::Counter::Connection

Inherits:
BaseSocket
  • Object
show all
Defined in:
lib/fluent/counter/client.rb

Instance Method Summary collapse

Methods inherited from BaseSocket

#on_read, #packed_write

Constructor Details

#initialize(io, on_message) ⇒ Connection

Returns a new instance of Connection.



199
200
201
202
203
204
# File 'lib/fluent/counter/client.rb', line 199

def initialize(io, on_message)
  super(io)
  @connection = false
  @buffer = ''
  @on_message = on_message
end

Instance Method Details

#on_closeObject



220
221
222
# File 'lib/fluent/counter/client.rb', line 220

def on_close
  @connection = false
end

#on_connectObject



214
215
216
217
218
# File 'lib/fluent/counter/client.rb', line 214

def on_connect
  @connection = true
  write @buffer
  @buffer = ''
end

#on_message(data) ⇒ Object



224
225
226
# File 'lib/fluent/counter/client.rb', line 224

def on_message(data)
  @on_message.call(data)
end

#send_data(data) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/fluent/counter/client.rb', line 206

def send_data(data)
  if @connection
    packed_write data
  else
    @buffer += pack(data)
  end
end