Class: Qpid::Proton::Event::Event
- Includes:
- Util::ClassWrapper, Util::Wrapper
- Defined in:
- lib/event/event.rb
Overview
An Event provides notification of a state change within the protocol engine.
Every event has a type that identifies what sort of state change has occurred, along with a pointer to the object whose state has changed, and also any associated objects.
For more details on working with Event, please refer to Collector.
Constant Summary
Constants included from Util::ClassWrapper
Instance Attribute Summary
Attributes inherited from EventBase
Class Method Summary collapse
-
.wrap(impl, number = nil) ⇒ Object
Creates a Ruby object for the given pn_event_t.
Instance Method Summary collapse
-
#connection ⇒ Connection?
Returns the Connection for this event.
- #container ⇒ Object
-
#delivery ⇒ Delivery?
Returns the Delivery associated with this event.
-
#dispatch(handler, type = nil) ⇒ Object
Notifies the handler(s) of this event.
-
#initialize(impl, number) ⇒ Event
constructor
A new instance of Event.
-
#link ⇒ Link?
Returns the Link for this event.
-
#message ⇒ Qpid::Proton::Message
Returns the message.
-
#message=(message) ⇒ Object
Sets the message.
-
#reactor ⇒ Reactor?
Returns the reactor for this event.
-
#receiver ⇒ Receiver?
Returns the Receiver, or nil if there is no Link, associated with this event if that link is a receiver.
-
#sender ⇒ Sender?
Returns the Sender, or nil if there is no Link, associated with this event if that link is a sender.
-
#session ⇒ Session?
Returns the Session for this event.
- #to_s ⇒ Object
-
#transport ⇒ Transport?
Returns the transport for this event.
Methods included from Util::Wrapper
#impl, #impl=, included, registry
Methods included from Util::ClassWrapper
Constructor Details
#initialize(impl, number) ⇒ Event
Returns a new instance of Event.
165 166 167 168 169 170 171 172 173 |
# File 'lib/event/event.rb', line 165 def initialize(impl, number) @impl = impl class_name = Cproton.pn_class_name(Cproton.pn_event_class(impl)) context = class_wrapper(class_name, Cproton.pn_event_context(impl)) event_type = EventType.by_type(Cproton.pn_event_type(impl)) super(class_name, context, event_type) @type = EventType.by_type(number) self.class.store_instance(self, :pn_event_attachments) end |
Class Method Details
.wrap(impl, number = nil) ⇒ Object
Creates a Ruby object for the given pn_event_t.
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/event/event.rb', line 153 def self.wrap(impl, number = nil) return nil if impl.nil? result = self.fetch_instance(impl, :pn_event_attachments) return result unless result.nil? number = Cproton.pn_event_type(impl) if number.nil? event = Event.new(impl, number) return event.context if event.context.is_a? EventBase return event end |
Instance Method Details
#connection ⇒ Connection?
Returns the Connection for this event.
247 248 249 |
# File 'lib/event/event.rb', line 247 def connection Qpid::Proton::Connection.wrap(Cproton.pn_event_connection(@impl)) end |
#container ⇒ Object
230 231 232 233 |
# File 'lib/event/event.rb', line 230 def container impl = Cproton.pn_event_reactor(@impl) Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl) end |
#delivery ⇒ Delivery?
Returns the Delivery associated with this event.
289 290 291 |
# File 'lib/event/event.rb', line 289 def delivery Qpid::Proton::Delivery.wrap(Cproton.pn_event_delivery(@impl)) end |
#dispatch(handler, type = nil) ⇒ Object
Notifies the handler(s) of this event.
If a handler responds to the event’s method then that method is invoked and passed the event. Otherwise, if the handler defines the on_unhandled
method, then that will be invoked instead.
If the handler defines a handlers
method then that will be invoked and passed the event afterward.
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/event/event.rb', line 207 def dispatch(handler, type = nil) type = @type if type.nil? if handler.is_a?(Qpid::Proton::Handler::WrappedHandler) Cproton.pn_handler_dispatch(handler.impl, @impl, type.number) else result = Qpid::Proton::Event.dispatch(handler, type.method, self) if (result != "DELEGATED") && handler.respond_to?(:handlers) handler.handlers.each do |hndlr| self.dispatch(hndlr) end end end end |
#link ⇒ Link?
Returns the Link for this event.
263 264 265 |
# File 'lib/event/event.rb', line 263 def link Qpid::Proton::Link.wrap(Cproton.pn_event_link(@impl)) end |
#message ⇒ Qpid::Proton::Message
Returns the message.
305 306 307 |
# File 'lib/event/event.rb', line 305 def @message end |
#message=(message) ⇒ Object
Sets the message.
297 298 299 |
# File 'lib/event/event.rb', line 297 def () @message = end |
#reactor ⇒ Reactor?
Returns the reactor for this event.
225 226 227 228 |
# File 'lib/event/event.rb', line 225 def reactor impl = Cproton.pn_event_reactor(@impl) Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl) end |
#receiver ⇒ Receiver?
Returns the Receiver, or nil if there is no Link, associated with this event if that link is a receiver.
281 282 283 |
# File 'lib/event/event.rb', line 281 def receiver return self.link if !self.link.nil? && self.link.receiver? end |
#sender ⇒ Sender?
Returns the Sender, or nil if there is no Link, associated with this event if that link is a sender.
272 273 274 |
# File 'lib/event/event.rb', line 272 def sender return self.link if !self.link.nil? && self.link.sender? end |
#session ⇒ Session?
Returns the Session for this event.
255 256 257 |
# File 'lib/event/event.rb', line 255 def session Qpid::Proton::Session.wrap(Cproton.pn_event_session(@impl)) end |
#to_s ⇒ Object
310 311 312 |
# File 'lib/event/event.rb', line 310 def to_s "#{self.type}(#{self.context})" end |