Class: Qpid::Proton::HandlerDriver

Inherits:
ConnectionDriver show all
Defined in:
lib/core/connection_driver.rb

Overview

A ConnectionDriver that feeds raw proton events to a handler.

Direct Known Subclasses

Container::ConnectionTask

Instance Attribute Summary collapse

Attributes inherited from ConnectionDriver

#next_tick

Instance Method Summary collapse

Methods inherited from ConnectionDriver

#can_read?, #can_write?, #close, #close_read, #close_write, #connection, #each_event, #event, #event?, #finished?, #read, #read_closed?, #tick, #to_io, #transport, #write, #write_closed?

Constructor Details

#initialize(io, handler) ⇒ HandlerDriver

Combine an IO with a handler and provide a simplified way to run the driver via #process

Parameters:



177
178
179
180
181
# File 'lib/core/connection_driver.rb', line 177

def initialize(io, handler)
  super(io)
  @handler = handler
  @adapter = Handler::Adapter.adapt(handler)
end

Instance Attribute Details

#handlerMessagingHandler (readonly)

Returns The handler dispatched to by #process.

Returns:



184
185
186
# File 'lib/core/connection_driver.rb', line 184

def handler
  @handler
end

Instance Method Details

#dispatch

Dispatch all available raw proton events from ConnectionDriver#event to #handler



187
188
189
190
191
192
193
194
195
196
# File 'lib/core/connection_driver.rb', line 187

def dispatch()
  each_event do |e|
    case e.method           # Events that affect the driver
    when :on_transport_tail_closed then close_read
    when :on_transport_head_closed then close_write
    when :on_transport_closed then @io.close rescue nil # Allow double-close
    end
    e.dispatch @adapter
  end
end

#process(now = Time.now) ⇒ Time

Parameters:

  • now (Time) (defaults to: Time.now)

    the current time

Returns:

  • (Time)

    Latest time to call #process again for scheduled events, or nil if there are no scheduled events



202
203
204
205
206
207
208
209
210
# File 'lib/core/connection_driver.rb', line 202

def process(now=Time.now)
  read
  dispatch
  next_tick = tick(now)
  dispatch
  write
  dispatch
  return next_tick
end