Class: Graphite::Socket
- Inherits:
-
Object
- Object
- Graphite::Socket
- Defined in:
- lib/graphite/socket.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #close ⇒ Object
-
#connect ⇒ Object
Retained for compatibility.
-
#initialize(host, port, socket_type) ⇒ Socket
constructor
A new instance of Socket.
- #puts(event) ⇒ Object
- #terminated_event(event) ⇒ Object
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
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/graphite/socket.rb', line 5 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/graphite/socket.rb', line 5 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
5 6 7 |
# File 'lib/graphite/socket.rb', line 5 def socket @socket end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/graphite/socket.rb', line 5 def type @type end |
Instance Method Details
#close ⇒ Object
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 |
#connect ⇒ Object
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 |