Class: Backport::Machine
- Inherits:
- 
      Object
      
        - Object
- Backport::Machine
 
- Defined in:
- lib/backport/machine.rb
Overview
The Backport server controller.
Instance Method Summary collapse
- 
  
    
      #initialize  ⇒ Machine 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Machine. 
- 
  
    
      #prepare(server)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    Add a server to the machine. 
- 
  
    
      #run  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    Run the machine. 
- #servers ⇒ Array<Server::Base>
- 
  
    
      #stop  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    Stop the machine. 
- 
  
    
      #stopped?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    True if the machine is stopped. 
- #update(server) ⇒ Object
Constructor Details
#initialize ⇒ Machine
Returns a new instance of Machine.
| 5 6 7 | # File 'lib/backport/machine.rb', line 5 def initialize @stopped = true end | 
Instance Method Details
#prepare(server) ⇒ void
This method returns an undefined value.
Add a server to the machine. The server will be started when the machine starts. If the machine is already running, the server will be started immediately.
| 43 44 45 46 47 | # File 'lib/backport/machine.rb', line 43 def prepare server server.add_observer self servers.push server server.start unless stopped? end | 
#run ⇒ void
This method returns an undefined value.
Run the machine. If a block is provided, it gets executed before the maching starts its main loop. The main loop blocks program execution until the machine is stopped.
| 14 15 16 17 18 19 20 | # File 'lib/backport/machine.rb', line 14 def run return unless stopped? servers.clear @stopped = false yield if block_given? run_server_thread end | 
#servers ⇒ Array<Server::Base>
| 50 51 52 | # File 'lib/backport/machine.rb', line 50 def servers @servers ||= [] end | 
#stop ⇒ void
This method returns an undefined value.
Stop the machine.
| 25 26 27 28 29 | # File 'lib/backport/machine.rb', line 25 def stop servers.map(&:stop) servers.clear @stopped = true end | 
#stopped? ⇒ Boolean
True if the machine is stopped.
| 33 34 35 | # File 'lib/backport/machine.rb', line 33 def stopped? @stopped ||= false end | 
#update(server) ⇒ Object
| 55 56 57 58 59 60 61 62 | # File 'lib/backport/machine.rb', line 55 def update server if server.stopped? servers.delete server stop if servers.empty? else mutex.synchronize { server.tick } end end |