Class: Graphite::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/graphite/socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, socket_type) ⇒ Socket

Returns a new instance of Socket.



7
8
9
10
11
12
# File 'lib/graphite/socket.rb', line 7

def initialize(host, port, socket_type)
  @host = host
  @port = port
  @type = socket_type
  @socket = nil
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/graphite/socket.rb', line 5

def host
  @host
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/graphite/socket.rb', line 5

def port
  @port
end

#socketObject

Returns the value of attribute socket.



5
6
7
# File 'lib/graphite/socket.rb', line 5

def socket
  @socket
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/graphite/socket.rb', line 5

def type
  @type
end

Instance Method Details

#closeObject



19
20
21
22
23
# File 'lib/graphite/socket.rb', line 19

def close
  @socket.close if @socket and !@socket.closed?
rescue => e
  warn "#{self.class} - #{e.class} - #{e.message}"
end

#connectObject

Retained for compatibility



40
41
42
# File 'lib/graphite/socket.rb', line 40

def connect
  socket
end

#puts(event) ⇒ Object



14
15
16
17
# File 'lib/graphite/socket.rb', line 14

def puts(event)
  socket.write(terminated_event(event.to_s))
  close if @type == :udp
end

#terminated_event(event) ⇒ Object



35
36
37
# File 'lib/graphite/socket.rb', line 35

def terminated_event(event)
  event =~ /\n$/ ? event : event + "\n"
end