class Qpid::Proton::Event::Collector

A Collector is used to register interest in events produced by one or more Connection objects.

Events

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

@example

conn = Qpid::Proton::Connection.new
coll = Qpid::Proton::Event::Collector.new
conn.collect(coll)

# transport setup not included here for brevity

loop do

   # wait for an event and then perform the following

   event = collector.peek

   unless event.nil?
     case event.type

     when Qpid::Proton::Event::CONNECTION_REMOTE_CLOSE
       conn = event.context # the context here is the connection
       # the remote connection closed, so only close our side if it's
       # still open
       if !(conn.state & Qpid::Proton::Endpoint::LOCAL_CLOSED)
         conn.close
       end

     when Qpid::proton::Event::SESSION_REMOTE_OPEN
       session = event.session # the context here is the session
       # the remote session is now open, so if the local session is
       # uninitialized, then open it
       if session.state & Qpid::Proton::Endpoint::LOCAL_UNINIT
         session.incoming_capacity = 1000000
         session.open
       end

     end

    # remove the processed event and get the next event
    # the loop will exit when we have no more events to process
    collector.pop
    event = collector.peek

end

Attributes

impl[R]

@private

Public Class Methods

finalize!(impl) click to toggle source

@private

# File lib/event/collector.rb, line 85
def self.finalize!(impl)
  proc {
    Cproton.pn_collector_free(impl)
  }
end
new() click to toggle source

Creates a new Collector.

# File lib/event/collector.rb, line 79
def initialize
  @impl = Cproton.pn_collector
  ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
end

Public Instance Methods

peek() click to toggle source

Access the head event.

This operation will continue to return the same event until it is cleared by using pop. The pointer return by this operation will be valid until ::pn_collector_pop is invoked or free is called, whichever happens sooner.

@return [Event] the head event @return [nil] if there are no events

@see pop @see put

# File lib/event/collector.rb, line 131
def peek
  Event.wrap(Cproton.pn_collector_peek(@impl))
end
pop() click to toggle source

Clear the head event.

@return [Boolean] true if an event was removed

@see release @see peek

# File lib/event/collector.rb, line 142
def pop
  Cproton.pn_collector_pop(@impl)
end
put(context, event_type) click to toggle source

Place a new event on the collector.

This operation will create a new event of the given type and context and return a new Event instance. In some cases an event of a given type can be elided. When this happens, this operation will return nil.

@param context [Object] The event context. @param event_type [EventType] The event type.

@return [Event] the event if it was queued @return [nil] if it was elided

# File lib/event/collector.rb, line 114
def put(context, event_type)
  Cproton.pn_collector_put(@impl, Cproton.pn_rb2void(context), event_type.type_code)
end
release() click to toggle source

Releases the collector.

Once in a released state, a collector will drain any internally queued events, shrink its memory footprint to a minimu, and discard any newly created events.

# File lib/event/collector.rb, line 97
def release
  Cproton.pn_collector_release(@impl)
end