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



80
81
82
83
84
85
86
87
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
# File 'lib/armstrong.rb', line 80

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