Class: Ruberl::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruberl/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = "localhost", port = 7050) ⇒ Base

Returns a new instance of Base.



4
5
6
7
# File 'lib/ruberl/base.rb', line 4

def initialize(host="localhost", port=7050)
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/ruberl/base.rb', line 3

def host
  @host
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/ruberl/base.rb', line 3

def port
  @port
end

Instance Method Details

#messenger_cast!(msg = "force_reconfig") ⇒ Object



24
25
26
27
28
# File 'lib/ruberl/base.rb', line 24

def messenger_cast!(msg="force_reconfig")
  with_socket do |sock|
    sock.send(msg, 0)
  end
end

#messenger_send!(msg = "get_current_load cpu") ⇒ Object



17
18
19
20
21
22
23
# File 'lib/ruberl/base.rb', line 17

def messenger_send!(msg="get_current_load cpu")
  with_socket do |sock|
    sock.send(msg, 0)
    @str = sock.recv(2000)      
  end
  @str
end

#with_socket(&block) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ruberl/base.rb', line 8

def with_socket(&block)
  begin
    socket = TCPSocket.open(@host, @port)
    out = yield(socket)
    socket.close
    out
  rescue Exception => e
  end
end