Class: PoolParty::Ruberl::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



6
7
8
9
# File 'lib/poolparty/helpers/ruberl.rb', line 6

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

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/poolparty/helpers/ruberl.rb', line 5

def host
  @host
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/poolparty/helpers/ruberl.rb', line 5

def port
  @port
end

Instance Method Details

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



26
27
28
29
30
# File 'lib/poolparty/helpers/ruberl.rb', line 26

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

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



19
20
21
22
23
24
25
# File 'lib/poolparty/helpers/ruberl.rb', line 19

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



10
11
12
13
14
15
16
17
18
# File 'lib/poolparty/helpers/ruberl.rb', line 10

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