Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring aroundware, Part IV: Deprecated old AsyncAroundware, Resp…

…onseReceiver, MultiReceiver, MongoReceiver. Examples still work with the old aroundwarez.
  • Loading branch information...
commit 88e67488180e6a4ffad3799ac70359994b4ee79b 1 parent 0f6ed2a
Philip (flip) Kromer authored
View
2  examples/auth_and_rate_limit.rb
@@ -6,7 +6,7 @@
require 'em-synchrony/em-http'
require 'yajl/json_gem'
-require 'goliath/synchrony/mongo_receiver' # has the aroundware logic for talking to mongodb
+require 'goliath/deprecated/mongo_receiver' # has the aroundware logic for talking to mongodb
require File.join(File.dirname(__FILE__), 'http_log') # Use the HttpLog as our actual endpoint, but include this in the middleware
# Usage:
View
2  examples/rasterize/rasterize_and_shorten.rb
@@ -4,6 +4,8 @@
require 'goliath'
require 'em-synchrony/em-http'
+require 'goliath/deprecated/async_aroundware'
+require 'goliath/deprecated/response_receiver'
require 'postrank-uri'
#
View
2  goliath.gemspec
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake', '0.8.7'
s.add_development_dependency 'rspec', '>2.0'
s.add_development_dependency 'nokogiri'
- s.add_development_dependency 'em-http-request', '>= 1.0.0.beta.1'
+ s.add_development_dependency 'em-http-request', '= 1.0.0.beta.1'
s.add_development_dependency 'em-mongo', '~> 0.3.6'
s.add_development_dependency 'yajl-ruby'
s.add_development_dependency 'rack-rewrite'
View
21 lib/goliath/rack/async_aroundware.rb → lib/goliath/deprecated/async_aroundware.rb
@@ -1,8 +1,26 @@
module Goliath
module Rack
+ #
+ # Note: This class is deprecated. Instead, use BarrierAroundwareFactory
+ # (orchestrates multiple concurrent requests) or SimpleAroundwareFactory
+ # (like AsyncMiddleware, but with a simpler interface).
+ #
+ # The differences:
+ # * ResponseReceiver/MultiReceiver was a stupid name. The thing that has
+ # pre_ and post_process is the Aroundware, the thing that manufactures
+ # it is an AroundwareFactory.
+ # * An aroundware's pre_process may return a direct response, which is
+ # immediately sent back upstream (no further downstream processing
+ # happens). In the typical case, you will want to add
+ # return Goliath::Connection::AsyncResponse
+ # to your pre_process method.
+ # * ResponseReceiver used to masquerade as callback and middleware. Yuck.
+ # The downstream response is now set via #accept_response, not #call.
+ #
class AsyncAroundware
include Goliath::Rack::Validator
+ #
# Called by the framework to create the middleware.
#
# Any extra args passed to the use statement are sent to each
@@ -71,13 +89,14 @@ def hook_into_callback_chain(env, aroundware)
downstream_callback = Proc.new do |resp|
safely(env){ aroundware.call(resp) }
end
- env['async.callback'] = downstream_callback
# .. but the upstream chain is only invoked when the aroundware completes
invoke_upstream_chain = Proc.new do
new_resp = safely(env){ aroundware.post_process }
async_callback.call(new_resp)
end
+
+ env['async.callback'] = downstream_callback
aroundware.callback(&invoke_upstream_chain)
aroundware.errback(&invoke_upstream_chain)
end
View
10 lib/goliath/synchrony/mongo_receiver.rb → lib/goliath/deprecated/mongo_receiver.rb
@@ -1,8 +1,16 @@
-require 'goliath/synchrony/response_receiver'
+require 'goliath/deprecated/response_receiver'
module Goliath
module Synchrony
#
+ # Note: This class is deprecated. Please instead use BarrierAroundware
+ # (orchestrates multiple concurrent requests) or SimpleAroundware (like
+ # AsyncMiddleware, but with a simpler interface).
+ #
+ # There are more notes on the lib/goliath/deprecated/async_aroundware docs.
+ #
+ # ___________________________________________________________________________
+ #
# Currently, you must provide in the env a method 'mongo' that returns a mongo
# collection or collection proxy (probably by setting it up in the config).
#
View
22 lib/goliath/synchrony/response_receiver.rb → lib/goliath/deprecated/response_receiver.rb
@@ -1,6 +1,13 @@
module Goliath
module Synchrony
+ #
+ # Note: This class is deprecated. Please instead use BarrierAroundware
+ # (orchestrates multiple concurrent requests) or SimpleAroundware (like
+ # AsyncMiddleware, but with a simpler interface).
+ #
+ # There are more notes on the lib/goliath/deprecated/async_aroundware docs.
+ #
module ResponseReceiver
# The request environment, set in the initializer
attr_reader :env
@@ -31,10 +38,10 @@ def downstream_resp=(status_headers_body)
# Invoked by the async_callback chain. Stores the [status, headers, body]
# for post_process'ing
- def call shb
- return shb if shb.first == Goliath::Connection::AsyncResponse.first
- self.downstream_resp = shb
- check_progress
+ def call resp
+ return resp if resp.first == Goliath::Connection::AsyncResponse.first
+ self.downstream_resp = resp
+ check_progress(nil)
end
# Have we received a response?
@@ -53,6 +60,13 @@ def check_progress(fiber)
end
end
+ #
+ # Note: This class is deprecated. Please instead use BarrierAroundware
+ # (orchestrates multiple concurrent requests) or SimpleAroundware (like
+ # AsyncMiddleware, but with a simpler interface).
+ #
+ # There are more notes on the lib/goliath/deprecated/async_aroundware docs.
+ #
class MultiReceiver < EM::Synchrony::Multi
include ResponseReceiver
View
7 lib/goliath/rack.rb
@@ -1,7 +1,8 @@
module Goliath
module Rack
- autoload :AsyncAroundware, 'goliath/rack/async_aroundware'
autoload :AsyncMiddleware, 'goliath/rack/async_middleware'
+ autoload :BarrierAroundware, 'goliath/rack/barrier_aroundware'
+ autoload :BarrierAroundwareFactory, 'goliath/rack/barrier_aroundware_factory'
autoload :Builder, 'goliath/rack/builder'
autoload :DefaultMimeType, 'goliath/rack/default_mime_type'
autoload :DefaultResponseFormat, 'goliath/rack/default_response_format'
@@ -10,9 +11,13 @@ module Rack
autoload :JSONP, 'goliath/rack/jsonp'
autoload :Params, 'goliath/rack/params'
autoload :Render, 'goliath/rack/render'
+ autoload :SimpleAroundware, 'goliath/rack/simple_aroundware'
+ autoload :SimpleAroundwareFactory, 'goliath/rack/simple_aroundware_factory'
autoload :Templates, 'goliath/rack/templates'
autoload :Tracer, 'goliath/rack/tracer'
autoload :Validator, 'goliath/rack/validator'
autoload :Validation, 'goliath/rack/validation'
+ #
+ autoload :AsyncAroundware, 'goliath/deprecated/async_aroundware'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.