Module: PoolParty::Messenger

Defined in:
lib/poolparty/net/messenger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_dirObject



26
27
28
# File 'lib/poolparty/net/messenger.rb', line 26

def self.append_dir
  ::File.expand_path(::File.join( ::File.dirname(__FILE__), "..", "..", "erlang/messenger" ))
end

.erl_command(hostname, extra = "", min_ports = 7000, max_ports = 7050) ⇒ Object

TODO: Fix cookie setting



20
21
22
23
24
# File 'lib/poolparty/net/messenger.rb', line 20

def self.erl_command(hostname, extra="", min_ports=7000, max_ports=7050)
  command_line_opts = "-cookie -pa #{append_dir}/ebin -kernel inet_dist_listen_min #{min_ports} inet_dist_listen_max #{max_ports} -sname #{hostname}"
  
  "erl #{command_line_opts} #{extra}"
end

.messenger_send!(cmd = "", testing = false) ⇒ Object



45
46
47
48
# File 'lib/poolparty/net/messenger.rb', line 45

def self.messenger_send!(cmd="", testing=false)      
  command = Messenger.erl_command("client#{Time.now.to_i}", "-s pm_client -run pm_client #{cmd} -s erlang halt -noshell")
  testing ? command : %x[#{command}]
end

.startup_remote_messenger(hostname, testing = false) ⇒ Object

Helper methods



51
52
53
54
# File 'lib/poolparty/net/messenger.rb', line 51

def self.startup_remote_messenger(hostname, testing=false)
  # messenger_send!("")
  # testing ? command : %x[#{command}]
end

Instance Method Details

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



39
40
41
42
43
# File 'lib/poolparty/net/messenger.rb', line 39

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

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



30
31
32
33
34
35
36
37
# File 'lib/poolparty/net/messenger.rb', line 30

def messenger_send!(msg="get_current_load cpu", testing=false)
  with_socket(testing) do |sock|
    sock.send(msg, 0)
    @str = sock.recv(2000)
  end
  vputs "Received #{@str} from #{msg}"
  @str
end

#with_socket(testing = false, &block) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/poolparty/net/messenger.rb', line 11

def with_socket(testing=false, &block)
  host = testing ? "localhost" : (master.ip)
  vputs "Pinging #{host} with the messenger"
  socket = TCPSocket.open(host, Default.messenger_client_port)
  out = yield(socket)
  socket.close
  out
end