class Qpid::Proton::Event::Event

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.

@see Qpid::Proton::Event The list of predefined events.

Public Class Methods

new(impl, number) click to toggle source

@private

Calls superclass method
# 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
wrap(impl, number = nil) click to toggle source

Creates a Ruby object for the given pn_event_t.

@private

# 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

Public Instance Methods

connection() click to toggle source

Returns the Connection for this event.

@return [Connection, nil] The connection.

# File lib/event/event.rb, line 247
def connection
  Qpid::Proton::Connection.wrap(Cproton.pn_event_connection(@impl))
end
container() click to toggle source
# 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() click to toggle source

Returns the Delivery associated with this event.

@return [Delivery, nil] The delivery.

# File lib/event/event.rb, line 289
def delivery
  Qpid::Proton::Delivery.wrap(Cproton.pn_event_delivery(@impl))
end
dispatch(handler, type = nil) click to toggle source

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.

@example

class FallbackEventHandler

  # since it now defines a handlers method, any event will iterate
  # through them and invoke the +dispatch+ method on each
  attr_accessor handlers

  def initialize
    @handlers = []
  end

  # invoked for any event not otherwise handled
  def on_unhandled(event)
    puts "Unable to invoke #{event.type.method} on #{event.context}."
  end

end

@param handler [Object] An object which implements either the event's

handler method or else responds to :handlers with an array of other
handlers.
# 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
message() click to toggle source

Returns the message.

@return [Qpid::Proton::Message] The message.

# File lib/event/event.rb, line 305
def message
  @message
end
message=(message) click to toggle source

Sets the message.

@param message [Qpid::Proton::Message] The message

# File lib/event/event.rb, line 297
def message=(message)
  @message = message
end
reactor() click to toggle source

Returns the reactor for this event.

@return [Reactor, nil] The reactor.

# 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() click to toggle source

Returns the Receiver, or nil if there is no Link, associated with this event if that link is a receiver.

@return [Receiver, nil] The receiver.

# File lib/event/event.rb, line 281
def receiver
  return self.link if !self.link.nil? && self.link.receiver?
end
sender() click to toggle source

Returns the Sender, or nil if there is no Link, associated with this event if that link is a sender.

@return [Sender, nil] The sender.

# File lib/event/event.rb, line 272
def sender
  return self.link if !self.link.nil? && self.link.sender?
end
session() click to toggle source

Returns the Session for this event.

@return [Session, nil] The session

# File lib/event/event.rb, line 255
def session
  Qpid::Proton::Session.wrap(Cproton.pn_event_session(@impl))
end
to_s() click to toggle source

@private

# File lib/event/event.rb, line 310
def to_s
  "#{self.type}(#{self.context})"
end
transport() click to toggle source

Returns the transport for this event.

@return [Transport, nil] The transport.

# File lib/event/event.rb, line 239
def transport
  Qpid::Proton::Transport.wrap(Cproton.pn_event_transport(@impl))
end