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

Inherits:
Object
  • Object
show all
Defined in:
lib/event/event_base.rb

Overview

EventBase is the foundation for creating application-specific events.

Examples:


# SCENARIO: A continuation of the example in EventType.
#
#           An Event class is defined to handle receiving encrypted
#           data from a remote endpoint.

class EncryptedDataEvent < EventBase
  def initialize(message)
    super(EncryptedDataEvent, message,
          Qpid::Proton::Event::ENCRYPTED_RECV)
  end
end

# at another point, when encrypted data is received
msg = Qpid::Proton::Message.new
msg.decode(link.receive(link.pending))
if encrypted?(msg)
  collector.put(EncryptedDataEvent.new(msg)
end

See Also:

Direct Known Subclasses

Event

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, context, type) ⇒ EventBase

Creates a new event with the specific class_name and context of the specified type.

Parameters:

  • class_name (String)

    The name of the class.

  • context (Object)

    The event context.

  • type (EventType)

    The event type.



75
76
77
78
79
# File 'lib/event/event_base.rb', line 75

def initialize(class_name, context, type)
  @class_name = class_name
  @context = context
  @type = type
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the name for the class associated with this event.



60
61
62
# File 'lib/event/event_base.rb', line 60

def class_name
  @class_name
end

#contextObject (readonly)

Returns the associated context object for the event.



63
64
65
# File 'lib/event/event_base.rb', line 63

def context
  @context
end

#typeObject (readonly)

Returns the type of the event.



66
67
68
# File 'lib/event/event_base.rb', line 66

def type
  @type
end

Instance Method Details

#dispatch(handler) ⇒ Object

Invokes the type-specific method on the provided handler.

Parameters:

  • handler (Object)

    The handler to be notified of this event.



85
86
87
# File 'lib/event/event_base.rb', line 85

def dispatch(handler)
  Qpid::Proton.dispatch(handler, @type.method, self)
end