Class: Lumberjack::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/lumberjack/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Socket

Returns a new instance of Socket.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lumberjack/client.rb', line 64

def initialize(opts={})
  @sequence = 0
  @last_ack = 0
  @opts = {
    :port => 0,
    :address => "127.0.0.1",
    :ssl_certificate => nil,
    :ssl => true,
    :json => false,
  }.merge(opts)
  @host = @opts[:address]

  connection_start(opts)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



63
64
65
# File 'lib/lumberjack/client.rb', line 63

def host
  @host
end

#sequenceObject (readonly)

Create a new Lumberjack Socket.

  • options is a hash. Valid options are:

  • :port - the port to listen on

  • :address - the host/address to bind to

  • :ssl - enable/disable ssl support

  • :ssl_certificate - the path to the ssl cert to use.

    If ssl_certificate is not set, a plain tcp connection
    will be used.
    


62
63
64
# File 'lib/lumberjack/client.rb', line 62

def sequence
  @sequence
end

Instance Method Details

#write_sync(elements, opts = {}) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/lumberjack/client.rb', line 121

def write_sync(elements, opts={})
  options = {
    :json => @opts[:json],
  }.merge(opts)

  elements = [elements] if elements.is_a?(Hash)
  send_window_size(elements.size)

  encoder = options[:json] ? JsonEncoder : FrameEncoder
  payload = elements.map { |element| encoder.to_frame(element, inc) }.join
  compress = compress_payload(payload)
  send_payload(compress)

  ack(elements.size)
end