Class: Artoo::Master

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/artoo/master.rb

Overview

The Artoo::Master class is a registered supervisor class to keep track of all the running robots

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bots = []) ⇒ Master

Create new master

Parameters:

  • robots (Collection)


44
45
46
47
# File 'lib/artoo/master.rb', line 44

def initialize(bots=[])
  @robots = []
  assign(bots)
end

Instance Attribute Details

#robotsObject (readonly)

Returns the value of attribute robots.



6
7
8
# File 'lib/artoo/master.rb', line 6

def robots
  @robots
end

Class Method Details

.assign(bots = []) ⇒ Object



13
14
15
# File 'lib/artoo/master.rb', line 13

def assign(bots=[])
  current.assign(bots)
end

.continue_workObject



37
38
39
# File 'lib/artoo/master.rb', line 37

def continue_work
  current.continue_work
end

.currentObject



9
10
11
# File 'lib/artoo/master.rb', line 9

def current
  Celluloid::Actor[:master] ||= self.new
end

.pause_workObject



33
34
35
# File 'lib/artoo/master.rb', line 33

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

.robotsObject



17
18
19
# File 'lib/artoo/master.rb', line 17

def robots
  current.robots
end

.start_workObject



25
26
27
# File 'lib/artoo/master.rb', line 25

def start_work
  current.start_work
end

.stop_workObject



29
30
31
# File 'lib/artoo/master.rb', line 29

def stop_work
  current.stop_work
end

Instance Method Details

#assign(bots = []) ⇒ Object

Assign robots to Master controller

Parameters:

  • robots (Collection)


51
52
53
54
# File 'lib/artoo/master.rb', line 51

def assign(bots=[])
  robots.concat(bots)
  bots.each {|r| r.async.work} if Artoo::Robot.is_running?
end

#continue_workObject

Continue work for each robot



105
106
107
# File 'lib/artoo/master.rb', line 105

def continue_work
  robots.each {|r| r.async.continue_work}
end

#pause_workObject

Pause work for each robot



97
98
99
100
101
102
# File 'lib/artoo/master.rb', line 97

def pause_work
  robots.each {|r|
    Logger.info "pausing #{r.name}"
    r.async.pause_work
  }
end

#robot(name) ⇒ Robot

Returns robot.

Parameters:

  • name (String)

Returns:

Raises:



58
59
60
61
62
# File 'lib/artoo/master.rb', line 58

def robot(name)
  r = robots.find {|r| r.name == name}
  raise RobotNotFound if r.nil?
  r
end

#robot_connection(robot_id, connection_id) ⇒ Device

Returns robot connection.

Parameters:

  • robot_id (String)
  • connection_id (String)

Returns:

  • (Device)

    robot connection



86
87
88
# File 'lib/artoo/master.rb', line 86

def robot_connection(robot_id, connection_id)
  robot_connections(robot_id)[connection_id.intern]
end

#robot_connections(name) ⇒ Collection

Returns robot connections.

Parameters:

  • name (String)

Returns:

  • (Collection)

    robot connections



79
80
81
# File 'lib/artoo/master.rb', line 79

def robot_connections(name)
  robot(name).connections
end

#robot_device(name, device_id) ⇒ Device

Returns robot device.

Parameters:

  • name (String)
  • device_id (String)

Returns:



73
74
75
# File 'lib/artoo/master.rb', line 73

def robot_device(name, device_id)
  robot_devices(name)[device_id.intern]
end

#robot_devices(name) ⇒ Collection

Returns robot devices.

Parameters:

  • name (String)

Returns:

  • (Collection)

    robot devices



66
67
68
# File 'lib/artoo/master.rb', line 66

def robot_devices(name)
  robot(name).devices
end

#start_workObject

Do asynchronous work for each robot



91
92
93
94
# File 'lib/artoo/master.rb', line 91

def start_work
  robots.each {|r| r.async.work} unless Artoo::Robot.is_running?
  Artoo::Robot.running!
end

#stop_workObject

terminate all robots



110
111
112
113
# File 'lib/artoo/master.rb', line 110

def stop_work
  robots.each {|r| r.terminate} unless !Artoo::Robot.is_running?
  Artoo::Robot.stopped!
end