Class: DTR::Monitor::MasterMonitor

Inherits:
Object
  • Object
show all
Includes:
Adapter::Follower, Service::Agent
Defined in:
lib/dtr/monitor.rb

Instance Method Summary collapse

Methods included from Service::Agent

#all_agents_info, #new_agent_monitor, #provide_agent_info

Methods included from Service::Rinda

#lookup, #lookup_ring, #start_service, #stop_service

Methods included from Adapter::Follower

#relax, #sleep?, #wakeup?

Instance Method Details

#monitorObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dtr/monitor.rb', line 62

def monitor
  msg, from_host, group = listen
  unless ["127.0.0.1:#{DTR.configuration.rinda_server_port}"].include?(from_host)
    puts "Master process message from #{from_host}: #{msg} for group #{group}"
    ip, port = from_host.split(':')
    with_configuration(ip, port) do
      start_service
      puts "Agents working for #{from_host}: "
      puts all_agents_info.collect{|i| "  #{i.strip}"}.join("\n")
    end
  end
end

#startObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dtr/monitor.rb', line 46

def start
  Process.fork do
    begin
      loop do
        monitor
      end
    rescue Errno::EADDRINUSE
      puts "There is DTR agent started on this machine."
      puts "Shutdown it for monitoring working DTR Master info."
    rescue Interrupt
    ensure
      relax
    end
  end
end

#with_configuration(ip, port) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/dtr/monitor.rb', line 75

def with_configuration(ip, port)
  my_port = DTR.configuration.rinda_server_port
  my_broadcast_list = DTR.configuration.broadcast_list
  DTR.configuration.rinda_server_port = port.to_i
  DTR.configuration.broadcast_list = [ip]
  yield
ensure
  DTR.configuration.broadcast_list = my_broadcast_list
  DTR.configuration.rinda_server_port = my_port
end