Class: Qpid::Proton::Event::Event

Inherits:
EventBase
  • Object
show all
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.

Instance Attribute Summary

Attributes inherited from EventBase

#class_name, #context, #type

Instance Method Summary collapse

Instance Method Details

#connectionConnection?

Returns the Connection for this event.

Returns:



247
248
249
# File 'lib/event/event.rb', line 247

def connection
  Qpid::Proton::Connection.wrap(Cproton.pn_event_connection(@impl))
end

#containerObject



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

#deliveryDelivery?

Returns the Delivery associated with this event.

Returns:



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.

Examples:


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

Parameters:

  • handler (Object)

    An object which implements either the event’s handler method or else responds to :handlers with an array of other handlers.



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

Returns the Link for this event.

Returns:

  • (Link, nil)

    The link.



263
264
265
# File 'lib/event/event.rb', line 263

def link
  Qpid::Proton::Link.wrap(Cproton.pn_event_link(@impl))
end

#messageQpid::Proton::Message

Returns the message.

Returns:



305
306
307
# File 'lib/event/event.rb', line 305

def message
  @message
end

#message=(message) ⇒ Object

Sets the message.

Parameters:



297
298
299
# File 'lib/event/event.rb', line 297

def message=(message)
  @message = message
end

#reactorReactor?

Returns the reactor for this event.

Returns:



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

#receiverReceiver?

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

Returns:



281
282
283
# File 'lib/event/event.rb', line 281

def receiver
  return self.link if !self.link.nil? && self.link.receiver?
end

#senderSender?

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

Returns:

  • (Sender, nil)

    The sender.



272
273
274
# File 'lib/event/event.rb', line 272

def sender
  return self.link if !self.link.nil? && self.link.sender?
end

#sessionSession?

Returns the Session for this event.

Returns:



255
256
257
# File 'lib/event/event.rb', line 255

def session
  Qpid::Proton::Session.wrap(Cproton.pn_event_session(@impl))
end

#transportTransport?

Returns the transport for this event.

Returns:



239
240
241
# File 'lib/event/event.rb', line 239

def transport
  Qpid::Proton::Transport.wrap(Cproton.pn_event_transport(@impl))
end