Class: Aleph::Armstrong

Inherits:
Base
  • Object
show all
Defined in:
lib/armstrong.rb

Class Method Summary collapse

Methods inherited from Base

delete, get, head, new_uuid, patch, post, put, route

Class Method Details

.run!Object

the kicker. It all gets launched from here. this function makes a new connection object to handle the communication, promises to start the replier, request handler, and their supervisor, gives the replier the connection information, tells the request_handler what routes it should be able to match, then checks that all of the services are running correctly, gives us a launch time, then jumps into our main loop that waits for an incoming message, parses it, and sends it off to be operated on by the request handler. Boom.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/armstrong.rb', line 88

def self.run!
  uuid = new_uuid
  puts "starting Armstrong as mongrel2 service #{uuid}"
  @conn = Connection.new uuid
  @conn.connect
  
  #ensure that all actors are launched. Yea.
  done = Lazy::demand(Lazy::promise do |done|
    Actor.spawn(&Aleph::Base.replier_proc)
    done = Lazy::demand(Lazy::promise do |done|
      Actor.spawn(&Aleph::Base.request_handler_proc)
      done = Lazy::demand(Lazy::promise do |done|
        Actor.spawn(&Aleph::Base.supervisor_proc)
        done = true
      end)
    end)
  end)
  
  Aleph::Base.replier << ConnectionInformation.new(@conn) if done
  
  done = Lazy::demand(Lazy::Promise.new do |done|
    Aleph::Base.request_handler << AddRoutes.new(@routes)
    done = true
  end)

  if Aleph::Base.supervisor && Aleph::Base.request_handler && Aleph::Base.replier && done
    puts "","="*56,"Armstrong has launched on #{Time.now}","="*56, ""
  end
  
  # main loop
  loop do
    req = @conn.receive
    Aleph::Base.request_handler << Request.new(req) if !req.nil?
  end
end