Module: DatawireQuarkCore::MyServer
- Included in:
- HTTPSServer, HTTPServer
- Defined in:
- lib/datawire-quark-core.rb
Instance Method Summary collapse
- #add(adapter) ⇒ Object
- #http_response(rq) ⇒ Object
- #initialize(host = "127.0.0.1", port = 3000, events) ⇒ Object
- #local_address ⇒ Object
- #on_connection(connection) ⇒ Object
- #respond(rq, action) ⇒ Object
Instance Method Details
#add(adapter) ⇒ Object
922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'lib/datawire-quark-core.rb', line 922 def add(adapter) old = @paths[adapter.uri.path] if not adapter.nil? @paths[adapter.uri.path] = adapter adapter.source = @events.add(adapter.effective_url) @events.event { adapter.servlet.onServletInit(adapter.effective_url, @events.runtime) } end if not old.nil? # XXX: servlet is not quiesced @events.event(final: adapter.source) { adapter.servlet.onServletFinal(adapter.effective_url) } end end |
#http_response(rq) ⇒ Object
973 974 975 976 977 978 979 |
# File 'lib/datawire-quark-core.rb', line 973 def http_response(rq) rs = rq.rs headers = {} rs.getHeaders.each { |k| headers[k] = rs.getHeader k } response = Reel::Response::new(rs.getCode, headers, rs.getBody) rq.request.respond response end |
#initialize(host = "127.0.0.1", port = 3000, events) ⇒ Object
910 911 912 913 914 915 |
# File 'lib/datawire-quark-core.rb', line 910 def initialize(host = "127.0.0.1", port = 3000, events) super(host, port, &method(:on_connection)) @events = events @paths = {} @log = Logger.new "quark.runtime.server" end |
#local_address ⇒ Object
918 919 920 |
# File 'lib/datawire-quark-core.rb', line 918 def local_address Addrinfo.new(@server.getsockname) end |
#on_connection(connection) ⇒ Object
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
# File 'lib/datawire-quark-core.rb', line 935 def on_connection(connection) connection.each_request do |request| begin rq = IncomingRequest.new(request.url) rq.setBody(request.body) request.headers.each {|key, value| rq.setHeader(key, value)} rq.setMethod(request.method) rq.request = request rq.rs = HTTP::Response.new rq.fut = Celluloid::Condition.new rq.svr = self rq.action = :wait adapter = @paths[request.uri.path] if adapter.nil? rq.fail! 404, "not found\r\n" else adapter.process_request(rq) end if rq.action == :wait rq.fut.wait end adapter.process_response(rq) case rq.action when :http_response http_response(rq) when :detach connection.detach else @log.error "Unknown action #{rq.action} for HTTP request" rq.fail! 500, "quark runtime is confused, unknown http request action\r\n" http_response(rq) end rescue => ex @log.error ex end end end |
#respond(rq, action) ⇒ Object
981 982 983 984 985 986 987 988 |
# File 'lib/datawire-quark-core.rb', line 981 def respond(rq, action) waiting = rq.action == :wait rq.action = action if waiting # condition is race-free only in the context of the originating actor rq.fut.signal end end |