Class: Wamp::Client::Manager::Registration
- Inherits:
-
BaseMultiple
- Object
- Base
- BaseMultiple
- Wamp::Client::Manager::Registration
- Defined in:
- lib/wamp/client/manager/registration.rb
Instance Attribute Summary collapse
-
#defers ⇒ Object
readonly
Returns the value of attribute defers.
Attributes inherited from BaseMultiple
Attributes inherited from Base
#send_message_callback, #session
Instance Method Summary collapse
-
#initialize(session, send_message) ⇒ Registration
constructor
Constructor.
-
#interrupt(message) ⇒ Object
Call Interrupt Handler.
-
#invoke(message) ⇒ Object
Processes an incoming call.
-
#yield(request_id, result, options = {}, check_defer = false) ⇒ Object
Processes a yield request.
Methods inherited from BaseMultiple
Constructor Details
#initialize(session, send_message) ⇒ Registration
Constructor
33 34 35 36 |
# File 'lib/wamp/client/manager/registration.rb', line 33 def initialize(session, ) super session, @defers = {} end |
Instance Attribute Details
#defers ⇒ Object (readonly)
Returns the value of attribute defers.
27 28 29 |
# File 'lib/wamp/client/manager/registration.rb', line 27 def defers @defers end |
Instance Method Details
#interrupt(message) ⇒ Object
Call Interrupt Handler
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/wamp/client/manager/registration.rb', line 130 def interrupt() # Get parameters request_id = .invocation_request mode = .[:mode] # Check if we have a pending request defer = self.defers[request_id] if defer registration = self.objects[defer.registration] if registration # If it exists, call the interrupt handler to inform it of the interrupt i_handler = registration.i_handler error = nil if i_handler error = Response.invoke_handler error: true do i_handler.call(request_id, mode) end # Add a default reason if none was supplied error.args << "interrupt" if error.args.count == 0 end # Send the error back to the client send_error(request_id, error) end # Delete the defer self.defers.delete(request_id) end end |
#invoke(message) ⇒ Object
Processes an incoming call
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/wamp/client/manager/registration.rb', line 41 def invoke() # Get the arguments registration_id = .registered_registration request_id = .request args = .call_arguments || [] kwargs = .call_argumentskw || {} # If we have a registration, execute it registration = self.objects[registration_id] if registration # Create the details details = .details || {} details[:request] = request_id details[:procedure] = registration.procedure details[:session] = self handler = registration.handler if handler # Use the invoke wrapper to process the result value = Response.invoke_handler do handler.call(args, kwargs, details) end # If a defer was returned, handle accordingly if value.is_a? Response::CallDefer value.request = request_id value.registration = registration_id # Store the defer self.defers[request_id] = value # On complete, send the result value.on :complete do |defer, result| result = Response::CallResult.ensure(result) self.yield(defer.request, result, {}, true) end # On error, send the error value.on :error do |defer, error| error = Response::CallError.ensure(error) self.yield(defer.request, error, {}, true) end # For progressive, return the progress if value.is_a? Response::ProgressiveCallDefer value.on :progress do |defer, result| result = Response::CallResult.ensure(result) self.yield(defer.request, result, { progress: true }, true) end end # Else it was a normal response else self.yield(request_id, value) end end end end |
#yield(request_id, result, options = {}, check_defer = false) ⇒ Object
Processes a yield request
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/wamp/client/manager/registration.rb', line 104 def yield(request_id, result, ={}, check_defer=false) # Prevent responses for defers that have already completed or had an error if check_defer and not self.defers[request_id] return end # Wrap the result accordingly result = Response::CallResult.ensure(result, allow_error: true) # Send either the error or the response if result.is_a?(Response::CallError) send_error(request_id, result) else yield_msg = Message::Yield.new(request_id, , result.args, result.kwargs) (yield_msg) end # Remove the defer if this was not a progress update if check_defer and not [:progress] self.defers.delete(request_id) end end |