Class: Artoo::Master
Overview
The Artoo::Master class is a registered supervisor class to keep track of all the running robots
Instance Attribute Summary collapse
-
#robots ⇒ Object
readonly
Returns the value of attribute robots.
Class Method Summary collapse
- .add_command(name, behaviour) ⇒ Object
- .assign(bots = []) ⇒ Object
- .command(name, params) ⇒ Object
- .commands ⇒ Object
- .continue_work ⇒ Object
- .current ⇒ Object
- .pause_work ⇒ Object
- .robot(name) ⇒ Object
- .robot?(name) ⇒ Boolean
- .robots ⇒ Object
- .start_work ⇒ Object
- .stop_work ⇒ Object
Instance Method Summary collapse
-
#add_command(name, behaviour) ⇒ Object
add command to master.
-
#assign(bots = []) ⇒ Object
Assign robots to Master controller.
-
#command(name, params) ⇒ Object
execute master command.
-
#commands ⇒ Object
return list of master command names.
-
#continue_work ⇒ Object
Continue work for each robot.
-
#initialize(bots = []) ⇒ Master
constructor
Create new master.
-
#pause_work ⇒ Object
Pause work for each robot.
-
#robot(name) ⇒ Robot
Robot.
- #robot?(name) ⇒ Boolean
-
#robot_connection(robot_id, connection_id) ⇒ Device
Robot connection.
-
#robot_connections(name) ⇒ Collection
Robot connections.
-
#robot_device(name, device_id) ⇒ Device
Robot device.
-
#robot_devices(name) ⇒ Collection
Robot devices.
-
#start_work ⇒ Object
Do asynchronous work for each robot.
-
#stop_work ⇒ Object
terminate all robots.
Constructor Details
#initialize(bots = []) ⇒ Master
Create new master
61 62 63 64 65 |
# File 'lib/artoo/master.rb', line 61 def initialize(bots=[]) @robots = [] @commands = [] assign(bots) end |
Instance Attribute Details
#robots ⇒ Object (readonly)
Returns the value of attribute robots.
6 7 8 |
# File 'lib/artoo/master.rb', line 6 def robots @robots end |
Class Method Details
.add_command(name, behaviour) ⇒ Object
49 50 51 |
# File 'lib/artoo/master.rb', line 49 def add_command(name, behaviour) current.add_command(name, behaviour) end |
.assign(bots = []) ⇒ Object
13 14 15 |
# File 'lib/artoo/master.rb', line 13 def assign(bots=[]) current.assign(bots) end |
.command(name, params) ⇒ Object
45 46 47 |
# File 'lib/artoo/master.rb', line 45 def command(name, params) current.command(name, params) end |
.commands ⇒ Object
53 54 55 |
# File 'lib/artoo/master.rb', line 53 def commands current.commands end |
.continue_work ⇒ Object
41 42 43 |
# File 'lib/artoo/master.rb', line 41 def continue_work current.continue_work end |
.current ⇒ Object
9 10 11 |
# File 'lib/artoo/master.rb', line 9 def current Celluloid::Actor[:master] ||= self.new end |
.pause_work ⇒ Object
37 38 39 |
# File 'lib/artoo/master.rb', line 37 def pause_work current.pause_work end |
.robot(name) ⇒ Object
21 22 23 |
# File 'lib/artoo/master.rb', line 21 def robot(name) current.robot(name) end |
.robot?(name) ⇒ Boolean
25 26 27 |
# File 'lib/artoo/master.rb', line 25 def robot?(name) current.robot?(name) end |
.robots ⇒ Object
17 18 19 |
# File 'lib/artoo/master.rb', line 17 def robots current.robots end |
.start_work ⇒ Object
29 30 31 |
# File 'lib/artoo/master.rb', line 29 def start_work current.start_work end |
.stop_work ⇒ Object
33 34 35 |
# File 'lib/artoo/master.rb', line 33 def stop_work current.stop_work end |
Instance Method Details
#add_command(name, behaviour) ⇒ Object
add command to master
153 154 155 |
# File 'lib/artoo/master.rb', line 153 def add_command(name, behaviour) @commands << { name: name.to_sym, behaviour: behaviour } end |
#assign(bots = []) ⇒ Object
Assign robots to Master controller
69 70 71 72 |
# File 'lib/artoo/master.rb', line 69 def assign(bots=[]) robots.concat(bots) bots.each {|r| r.async.work} if Artoo::Robot.is_running? end |
#command(name, params) ⇒ Object
execute master command
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/artoo/master.rb', line 141 def command(name, params) command = @commands.find{ |c| c[:name] == name.to_sym } if command if params.nil? command[:behaviour].call else command[:behaviour].call(params) end end end |
#commands ⇒ Object
return list of master command names
136 137 138 |
# File 'lib/artoo/master.rb', line 136 def commands @commands.map{ |c| c[:name] } end |
#continue_work ⇒ Object
Continue work for each robot
125 126 127 |
# File 'lib/artoo/master.rb', line 125 def continue_work robots.each {|r| r.async.continue_work} end |
#pause_work ⇒ Object
Pause work for each robot
117 118 119 120 121 122 |
# File 'lib/artoo/master.rb', line 117 def pause_work robots.each {|r| Logger.info "pausing #{r.name}" r.async.pause_work } end |
#robot(name) ⇒ Robot
Returns robot.
76 77 78 |
# File 'lib/artoo/master.rb', line 76 def robot(name) robots.find {|r| r.name == name} end |
#robot?(name) ⇒ Boolean
80 81 82 |
# File 'lib/artoo/master.rb', line 80 def robot?(name) robots.find {|r| r.name == name} end |
#robot_connection(robot_id, connection_id) ⇒ Device
Returns robot connection.
106 107 108 |
# File 'lib/artoo/master.rb', line 106 def robot_connection(robot_id, connection_id) robot_connections(robot_id)[connection_id.intern] end |
#robot_connections(name) ⇒ Collection
Returns robot connections.
99 100 101 |
# File 'lib/artoo/master.rb', line 99 def robot_connections(name) robot(name).connections end |
#robot_device(name, device_id) ⇒ Device
Returns robot device.
93 94 95 |
# File 'lib/artoo/master.rb', line 93 def robot_device(name, device_id) robot_devices(name)[device_id.intern] end |
#robot_devices(name) ⇒ Collection
Returns robot devices.
86 87 88 |
# File 'lib/artoo/master.rb', line 86 def robot_devices(name) robot(name).devices end |