Class: Statt::Motor
- Inherits:
-
Object
- Object
- Statt::Motor
- Defined in:
- lib/statt/motor.rb
Instance Attribute Summary collapse
-
#rc ⇒ Object
Returns the value of attribute rc.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Motor
constructor
A new instance of Motor.
- #shutdown_hub ⇒ Object
- #shutdown_rcs ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Motor
Returns a new instance of Motor.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/statt/motor.rb', line 9 def initialize(={}) = { :hub_host => "localhost", :hub_port => 4444, :rc_options => {:host => "localhost", :port => 5555 } }.merge() = { :host => [:hub_host], :port => [:hub_port] } # Start up Hub server in its own thread. @hub_thread = Thread.new do Thread.current[:hub] = SGrid::Hub.new() Thread.current[:hub].start self.pass end @hub_thread[:hub].wait_until_up_and_running # Start up the RC Servers, each within their own thread. @rc_threads = [] @rc_threads << Thread.new do = [:rc_options] if [:rc_options].is_a?(Hash) Thread.current[:server] = SGrid::RemoteControl.new() Thread.current[:server].start if [:host] == "localhost" elsif [:rc_options].is_a?(Array) .each do |rc_option| Thread.current[:server] = SGrid::RemoteControl.new(rc_option) Thread.current[:server].start if rc_option[:host] == "localhost" end else raise Exception, "there was a problem starting the rc server(s)", caller end self.pass end end |
Instance Attribute Details
#rc ⇒ Object
Returns the value of attribute rc.
7 8 9 |
# File 'lib/statt/motor.rb', line 7 def rc @rc end |
Instance Method Details
#shutdown_hub ⇒ Object
53 54 55 56 |
# File 'lib/statt/motor.rb', line 53 def shutdown_hub @hub_thread[:hub].shutdown puts "." end |
#shutdown_rcs ⇒ Object
58 59 60 61 62 63 |
# File 'lib/statt/motor.rb', line 58 def shutdown_rcs @rc_threads.each do |thr| thr[:server].shutdown puts "." end end |
#stop ⇒ Object
47 48 49 50 51 |
# File 'lib/statt/motor.rb', line 47 def stop Thread.new { shutdown_hub } Thread.new { shutdown_rcs } puts "Shutting down all servers " end |