Class: Wamp::Client::Request::Base
- Inherits:
-
Object
- Object
- Wamp::Client::Request::Base
- Defined in:
- lib/wamp/client/request/base.rb
Overview
The request base class is used to abstract all of the requests that will go to the broker/dealer. The model supports a request followed by a response that is either a “success” or an error
Direct Known Subclasses
Instance Attribute Summary collapse
-
#on_success ⇒ Object
readonly
Returns the value of attribute on_success.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#send_message_callback ⇒ Object
readonly
Returns the value of attribute send_message_callback.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#create_request(*args) ⇒ Object
region Override Methods.
- #error(message) ⇒ Object
-
#generate_id ⇒ Object
Generates a new ID for the request according to the specification (Section 5.1.2).
-
#initialize(session, send_message, &on_success) ⇒ Base
constructor
Constructor.
- #process_error(message, lookup) ⇒ Object
- #process_success(message, lookup) ⇒ Object
-
#request(*args, &callback) ⇒ Int
Makes the request to the broker/dealer.
-
#success(message) ⇒ Object
Called when the response was a success.
Constructor Details
#initialize(session, send_message, &on_success) ⇒ Base
Constructor
22 23 24 25 26 27 |
# File 'lib/wamp/client/request/base.rb', line 22 def initialize(session, , &on_success) @requests = {} @session = session @send_message_callback = @on_success = on_success end |
Instance Attribute Details
#on_success ⇒ Object (readonly)
Returns the value of attribute on_success.
15 16 17 |
# File 'lib/wamp/client/request/base.rb', line 15 def on_success @on_success end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
15 16 17 |
# File 'lib/wamp/client/request/base.rb', line 15 def requests @requests end |
#send_message_callback ⇒ Object (readonly)
Returns the value of attribute send_message_callback.
15 16 17 |
# File 'lib/wamp/client/request/base.rb', line 15 def @send_message_callback end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
15 16 17 |
# File 'lib/wamp/client/request/base.rb', line 15 def session @session end |
Instance Method Details
#create_request(*args) ⇒ Object
region Override Methods
104 105 |
# File 'lib/wamp/client/request/base.rb', line 104 def create_request(*args) end |
#error(message) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/wamp/client/request/base.rb', line 81 def error() # Get the request_id request_id = .request_id # Get the lookup lookup = self.requests.delete(request_id) # Parse the result callback, details = self.process_error(, lookup) if callback and details # Add items to details details[:session] = self.session # Create the error error = Response::CallError.() # Call the callback callback.call(nil, error.to_hash, details) if callback end end |
#generate_id ⇒ Object
Generates a new ID for the request according to the specification (Section 5.1.2)
33 34 35 |
# File 'lib/wamp/client/request/base.rb', line 33 def generate_id rand(0..9007199254740992) end |
#process_error(message, lookup) ⇒ Object
110 111 |
# File 'lib/wamp/client/request/base.rb', line 110 def process_error(, lookup) end |
#process_success(message, lookup) ⇒ Object
107 108 |
# File 'lib/wamp/client/request/base.rb', line 107 def process_success(, lookup) end |
#request(*args, &callback) ⇒ Int
Makes the request to the broker/dealer
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/wamp/client/request/base.rb', line 40 def request(*args, &callback) # Generate an ID request_id = self.generate_id # Get the unique lookup/message for the request lookup, = self.create_request(request_id, *args, &callback) # Store in the pending requests self.requests[request_id] = lookup if lookup # Send the message () request_id end |
#success(message) ⇒ Object
Called when the response was a success
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/wamp/client/request/base.rb', line 59 def success() # Get the request_id request_id = .request_id # Get the lookup lookup = self.requests[request_id] # Parse the result callback, result, details, should_keep = self.process_success(, lookup) if callback and details # Add items to details details[:session] = self.session # Call the callback callback.call(result, nil, details) if callback end # Delete if "should_keep" if false self.requests.delete(request_id) unless should_keep end |