Class: KStor::Controller::RequestHandler
- Inherits:
-
Object
- Object
- KStor::Controller::RequestHandler
- Defined in:
- lib/kstor/controller/request_handler.rb
Overview
Top-level request handler.
Dispatches requests to specialized sub-controller.
Class Attribute Summary collapse
-
.controllers ⇒ Object
List of sub-controllers.
Class Method Summary collapse
-
.handles?(type) ⇒ Boolean
True if this controller can handle this request type.
-
.message_types ⇒ Array[String]
All message types handled and produced by this controller.
-
.request_types ⇒ Array[String]
Request types handled by all sub-controllers.
-
.responds?(type) ⇒ Boolean
True if this controller can respond to a client with this type of reponse.
-
.response_types ⇒ Array[String]
Response types that sub-controllers can produce.
Instance Method Summary collapse
-
#handle_request(req) ⇒ KStor::Message::Base
Serve a client.
-
#initialize(store, session_store) ⇒ KStor::Controller::RequestHandler
constructor
Create new request handler controller from data store and session store.
Constructor Details
#initialize(store, session_store) ⇒ KStor::Controller::RequestHandler
Create new request handler controller from data store and session store.
71 72 73 74 75 76 77 |
# File 'lib/kstor/controller/request_handler.rb', line 71 def initialize(store, session_store) @auth = Controller::Authentication.new(store, session_store) @store = store @controllers = self.class.controllers.map do |klass| klass.new(store) end end |
Class Attribute Details
.controllers ⇒ Object
List of sub-controllers.
22 23 24 |
# File 'lib/kstor/controller/request_handler.rb', line 22 def controllers @controllers end |
Class Method Details
.handles?(type) ⇒ Boolean
True if this controller can handle this request type.
50 51 52 |
# File 'lib/kstor/controller/request_handler.rb', line 50 def handles?(type) request_types.include?(type) end |
.message_types ⇒ Array[String]
All message types handled and produced by this controller.
42 43 44 |
# File 'lib/kstor/controller/request_handler.rb', line 42 def request_types + response_types end |
.request_types ⇒ Array[String]
Request types handled by all sub-controllers.
27 28 29 |
# File 'lib/kstor/controller/request_handler.rb', line 27 def request_types @controllers.map(&:request_types).inject([], &:+) end |
.responds?(type) ⇒ Boolean
True if this controller can respond to a client with this type of reponse.
59 60 61 |
# File 'lib/kstor/controller/request_handler.rb', line 59 def responds?(type) response_types.include?(type) end |
Instance Method Details
#handle_request(req) ⇒ KStor::Message::Base
Serve a client.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/kstor/controller/request_handler.rb', line 83 def handle_request(req) user, sid = @auth.authenticate(req) controller = controller_from_request_type(req) resp = @store.transaction { controller.handle_request(user, sid, req) } user.lock finish_response(resp) rescue RbNaClError => e Log.exception(e) Error.for_code('CRYPTO/UNSPECIFIED').response(sid) rescue KStor::MissingMessageArgument => e raise e rescue KStor::Error => e Log.info(e.) e.response(sid) end |