Module: EventMachine::Syslog::ConnectionTCP

Defined in:
lib/em-syslog/connection_tcp.rb

Overview

Our module to pass to EventMachine to create the connection handler

Constant Summary collapse

DEFAULTS =
{:queue_max_size => 500,
 :queue_batch_send => 20,
 :on_hangup => nil,
 :reconnect => true
}

Instance Method Summary collapse

Instance Method Details

#post_initObject

we got our connection, time to start sending any items we have queued up



30
31
32
33
# File 'lib/em-syslog/connection_tcp.rb', line 30

def post_init
  @connected = true
  queue_send_batch
end

#send_msg(msg) ⇒ Object

queue messages if we are not connected.



38
39
40
41
42
43
44
# File 'lib/em-syslog/connection_tcp.rb', line 38

def send_msg( msg)
  if @connected
    send_data( msg)
  else
    queue_push( msg)
  end
end

#setup(host, port, config = {}) ⇒ Object

setup our connection with remote/local information, with a hash config merged against ConnectionTCP::DEFAULTS



16
17
18
19
20
21
22
23
24
25
# File 'lib/em-syslog/connection_tcp.rb', line 16

def setup( host, port, config={})
  config = DEFAULTS.merge( config)
  @host = host
  @port = port
  @do_reconnect = config[:on_hangup]
  @reconnect = config[:reconnect]
  @queue = Array.new
  @connected = false
  true
end

#unbindObject

Do you want to be told when it disconnects and/or do you want to reconnect right away config = true

passing config[:on_hangup] provide a proc.


50
51
52
53
54
# File 'lib/em-syslog/connection_tcp.rb', line 50

def unbind
  @connected = false
  reconnect( @host, @port) if @do_reconnect
  @on_hangup.call unless @on_hangup.nil?
end