def self.control(name, command)
items = Array(self.watches[name] || self.groups[name]).dup
jobs = []
case command
when "start", "monitor"
items.each { |w| jobs << Thread.new { w.monitor if w.state != :up } }
when "restart"
items.each { |w| jobs << Thread.new { w.move(:restart) } }
when "stop"
items.each { |w| jobs << Thread.new { w.action(:stop); w.unmonitor if w.state != :unmonitored } }
when "unmonitor"
items.each { |w| jobs << Thread.new { w.unmonitor if w.state != :unmonitored } }
when "remove"
items.each { |w| self.unwatch(w) }
else
raise InvalidCommandError.new
end
jobs.each { |j| j.join }
items.map { |x| x.name }
end