Class: Wamp::Client::Session
- Inherits:
-
Object
- Object
- Wamp::Client::Session
- Defined in:
- lib/wamp/client/session.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#establish ⇒ Object
Returns the value of attribute establish.
-
#options ⇒ Object
Returns the value of attribute options.
-
#registration ⇒ Object
Returns the value of attribute registration.
-
#request ⇒ Object
Returns the value of attribute request.
-
#subscription ⇒ Object
Returns the value of attribute subscription.
-
#transport ⇒ Object
Returns the value of attribute transport.
Instance Method Summary collapse
-
#call(procedure, args = nil, kwargs = nil, options = {}, &callback) ⇒ Call
Publishes and event to a topic.
-
#cancel(call, mode = 'skip') ⇒ Object
Cancels a call.
-
#id ⇒ Object
Returns the ID of the session.
-
#initialize(transport, options = {}) ⇒ Session
constructor
Constructor.
-
#is_open? ⇒ Boolean
Returns ‘true’ if the session is open.
-
#join(realm) ⇒ Object
Joins the WAMP Router.
-
#leave(reason = 'wamp.close.normal', message = 'user initiated') ⇒ Object
Leaves the WAMP Router.
-
#publish(topic, args = nil, kwargs = nil, options = {}, &callback) ⇒ Object
Publishes and event to a topic.
-
#realm ⇒ Object
Returns the realm of the session.
-
#register(procedure, handler, options = nil, interrupt = nil, &callback) ⇒ Object
Register to a procedure.
-
#subscribe(topic, handler, options = {}, &callback) ⇒ Object
Subscribes to a topic.
-
#unregister(registration, &callback) ⇒ Object
Unregisters from a procedure.
-
#unsubscribe(subscription, &callback) ⇒ Object
Unsubscribes from a subscription.
-
#yield(request, result, options = {}, check_defer = false) ⇒ Object
Sends a result for the invocation.
Methods included from Event
Methods included from Check
Constructor Details
#initialize(transport, options = {}) ⇒ Session
Constructor
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 |
# File 'lib/wamp/client/session.rb', line 56 def initialize(transport, ={}) # Parameters self. = || {} # Log the event logger.info("#{self.class.name} created with options") logger.info(" uri: #{[:uri]}") logger.info(" realm: #{[:realm]}") # Create the send message lambda for the request objects = -> m { (m) } # Outstanding Requests self.request = { publish: Request::Publish.new(self, ), subscribe: Request::Subscribe.new(self, ) { |s_id, s| self.subscription.add(s_id, s) }, unsubscribe: Request::Unsubscribe.new(self, ) { |s_id| self.subscription.remove(s_id) }, call: Request::Call.new(self, ), register: Request::Register.new(self, ) { |r_id, r| self.registration.add(r_id, r) }, unregister: Request::Unregister.new(self, ) { |r_id| self.registration.remove(r_id) }, } # Init Subs and Regs in place self.subscription = Manager::Subscription.new(self, ) self.registration = Manager::Registration.new(self, ) self.establish = Manager::Establish.new(self, ) # Setup session callbacks self.callback = {} # Setup Transport self.transport = transport self.transport.on :message do |msg| (msg) end end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
46 47 48 |
# File 'lib/wamp/client/session.rb', line 46 def callback @callback end |
#establish ⇒ Object
Returns the value of attribute establish.
46 47 48 |
# File 'lib/wamp/client/session.rb', line 46 def establish @establish end |
#options ⇒ Object
Returns the value of attribute options.
46 47 48 |
# File 'lib/wamp/client/session.rb', line 46 def @options end |
#registration ⇒ Object
Returns the value of attribute registration.
46 47 48 |
# File 'lib/wamp/client/session.rb', line 46 def registration @registration end |
#request ⇒ Object
Returns the value of attribute request.
46 47 48 |
# File 'lib/wamp/client/session.rb', line 46 def request @request end |
#subscription ⇒ Object
Returns the value of attribute subscription.
46 47 48 |
# File 'lib/wamp/client/session.rb', line 46 def subscription @subscription end |
#transport ⇒ Object
Returns the value of attribute transport.
46 47 48 |
# File 'lib/wamp/client/session.rb', line 46 def transport @transport end |
Instance Method Details
#call(procedure, args = nil, kwargs = nil, options = {}, &callback) ⇒ Call
Publishes and event to a topic
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/wamp/client/session.rb', line 246 def call(procedure, args=nil, kwargs=nil, ={}, &callback) check_open # Check params self.class.check_uri('procedure', procedure) self.class.check_dict('options', ) self.class.check_list('args', args, true) self.class.check_dict('kwargs', kwargs, true) # Make the request request_id = make_request(:call, :request, procedure, args, kwargs, , &callback) # Create the call object call = Request::CallObject.new(self, request_id) # Timeout Logic if [:timeout] and [:timeout] > 0 # Once the timer expires, if the call hasn't completed, cancel it self.transport.add_timer([:timeout]) do call.cancel end end call end |
#cancel(call, mode = 'skip') ⇒ Object
Cancels a call
276 277 278 279 280 281 282 283 284 |
# File 'lib/wamp/client/session.rb', line 276 def cancel(call, mode='skip') check_open # Check params self.class.check_nil('call', call, false) # Cancel the request make_request(:call, :cancel, call.id, mode) end |
#id ⇒ Object
Returns the ID of the session
103 104 105 |
# File 'lib/wamp/client/session.rb', line 103 def id self.establish.id end |
#is_open? ⇒ Boolean
Returns ‘true’ if the session is open
97 98 99 |
# File 'lib/wamp/client/session.rb', line 97 def is_open? self.establish.is_open? end |
#join(realm) ⇒ Object
Joins the WAMP Router
116 117 118 119 120 121 122 123 124 |
# File 'lib/wamp/client/session.rb', line 116 def join(realm) check_closed # Check params self.class.check_uri('realm', realm) # Attempt to join self.establish.join(realm) end |
#leave(reason = 'wamp.close.normal', message = 'user initiated') ⇒ Object
Leaves the WAMP Router
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/wamp/client/session.rb', line 129 def leave(reason='wamp.close.normal', ='user initiated') check_open # Check params self.class.check_uri('reason', reason, true) self.class.check_string('message', , true) # Leave the session self.establish.leave(reason, ) end |
#publish(topic, args = nil, kwargs = nil, options = {}, &callback) ⇒ Object
Publishes and event to a topic
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/wamp/client/session.rb', line 179 def publish(topic, args=nil, kwargs=nil, ={}, &callback) check_open # Check params self.class.check_uri('topic', topic) self.class.check_dict('options', ) self.class.check_list('args', args, true) self.class.check_dict('kwargs', kwargs, true) # Make the request make_request(:publish, :request, topic, args, kwargs, , &callback) end |
#realm ⇒ Object
Returns the realm of the session
109 110 111 |
# File 'lib/wamp/client/session.rb', line 109 def realm self.establish.realm end |
#register(procedure, handler, options = nil, interrupt = nil, &callback) ⇒ Object
Register to a procedure
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/wamp/client/session.rb', line 199 def register(procedure, handler, =nil, interrupt=nil, &callback) check_open ||= {} # Check params self.class.check_uri('procedure', procedure) self.class.check_nil('handler', handler, false) # Make the request make_request(:register, :request, procedure, handler, , interrupt, &callback) end |
#subscribe(topic, handler, options = {}, &callback) ⇒ Object
Subscribes to a topic
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/wamp/client/session.rb', line 146 def subscribe(topic, handler, ={}, &callback) check_open # Check params self.class.check_uri('topic', topic) self.class.check_dict('options', ) self.class.check_nil('handler', handler, false) # Make the request make_request(:subscribe, :request, topic, handler, , &callback) end |
#unregister(registration, &callback) ⇒ Object
Unregisters from a procedure
228 229 230 231 232 233 234 235 236 |
# File 'lib/wamp/client/session.rb', line 228 def unregister(registration, &callback) check_open # Check params self.class.check_nil('registration', registration, false) # Make the request make_request(:unregister, :request, registration, &callback) end |
#unsubscribe(subscription, &callback) ⇒ Object
Unsubscribes from a subscription
162 163 164 165 166 167 168 169 170 |
# File 'lib/wamp/client/session.rb', line 162 def unsubscribe(subscription, &callback) check_open # Check params self.class.check_nil('subscription', subscription, false) # Make the request make_request(:unsubscribe, :request, subscription, &callback) end |
#yield(request, result, options = {}, check_defer = false) ⇒ Object
Sends a result for the invocation
217 218 219 220 221 222 |
# File 'lib/wamp/client/session.rb', line 217 def yield(request, result, ={}, check_defer=false) check_open # Call the registration yield method self.registration.yield(request, result, , check_defer) end |