class Qpid::Proton::Connection

A Connection has at most one Qpid::Proton::Transport instance.

Constants

PROTON_METHOD_PREFIX

@private

Attributes

overrides[RW]
session_policy[RW]

Public Class Methods

new(impl = Cproton.pn_connection) click to toggle source

Constructs a new instance of Connection.

You do not need to provide the underlying C struct, as this is automatically generated as needed. The argument is a convenience for returning existing Connection objects.

@param impl [pn_connection_t] The pn_connection_t struct.

Calls superclass method
# File lib/core/connection.rb, line 71
def initialize(impl = Cproton.pn_connection)
  super()
  @impl = impl
  @offered_capabilities = nil
  @desired_capabilities = nil
  @properties = nil
  @overrides = nil
  @collector = nil
  @session_policy = nil
  self.class.store_instance(self, :pn_connection_attachments)
end
wrap(impl) click to toggle source

@private

# File lib/core/connection.rb, line 57
def self.wrap(impl)
  return nil if impl.nil?

  self.fetch_instance(impl, :pn_connection_attachments) || Connection.new(impl)
end

Public Instance Methods

_local_condition() click to toggle source

@private

# File lib/core/connection.rb, line 326
def _local_condition
  Cproton.pn_connection_condition(@impl)
end
_remote_condition() click to toggle source

@private

# File lib/core/connection.rb, line 331
def _remote_condition
  Cproton.pn_connection_remote_condition(@impl)
end
close() click to toggle source

Closes the connection.

Once this operation has completed, the #LOCAL_CLOSED state flag will be set.

# File lib/core/connection.rb, line 224
def close
  self._update_condition
  Cproton.pn_connection_close(@impl)
end
collect(collector) click to toggle source

Associates the connection with an event collector.

By doing this, key changes in the endpoint's state are reported to the connector via Event objects that can be inspected and processed.

Note that, by registering a collector, the user is requesting that an indefinite number of events be queued up on its behalf. This means that, unless the application eventual processes these events, the storage requirements for keeping them will grow without bound. So be careful and do not register a collector with a connection unless the application will process the events.

@param collector [Event::Collector] The event collector.

# File lib/core/connection.rb, line 121
def collect(collector)
  if collector.nil?
    Cproton.pn_connection_collect(@impl, nil)
  else
    Cproton.pn_connection_collect(@impl, collector.impl)
  end
  @collector = collector
end
connection() click to toggle source

This method is used when working within the context of an event.

@return [Connection] The connection itself.

# File lib/core/connection.rb, line 95
def connection
  self
end
container() click to toggle source
# File lib/core/connection.rb, line 151
def container
  Cproton.pn_connection_get_container(@impl)
end
container=(name) click to toggle source
# File lib/core/connection.rb, line 147
def container=(name)
  Cproton.pn_connection_set_container(@impl, name)
end
error() click to toggle source

Returns the code for a connection error.

@return [Integer] The error code.

# File lib/core/connection.rb, line 321
def error
  Cproton.pn_error_code(Cproton.pn_connection_error(@impl))
end
open() click to toggle source

Opens the connection.

# File lib/core/connection.rb, line 209
def open
  object_to_data(@offered_capabilities,
                 Cproton.pn_connection_offered_capabilities(@impl))
  object_to_data(@desired_capabilities,
                 Cproton.pn_connection_desired_capabilities(@impl))
  object_to_data(@properties,
                 Cproton.pn_connection_properties(@impl))
  Cproton.pn_connection_open(@impl)
end
overrides?() click to toggle source
# File lib/core/connection.rb, line 83
def overrides?
  !@overrides.nil?
end
remote_container() click to toggle source

Get the AMQP container name advertised by the remote connection endpoint.

This will return nil until the REMOTE_ACTIVE state is reached.

Any non-nil container returned by this operation will be valid until the connection is unbound from a transport, or freed, whichever happens sooner.

@return [String] The remote connection's AMQP container name.

@see container

# File lib/core/connection.rb, line 143
def remote_container
  Cproton.pn_connection_remote_container(@impl)
end
remote_desired_capabilities() click to toggle source

Get the AMQP desired capabilities supplied by the remote connection endpoint.

The object returned is valid until the connection is freed. The Data object will be empty until the remote connection is opened, as indicated by the #REMOTE_ACTIVE flag.

@return [Data] The desired capabilities.

# File lib/core/connection.rb, line 190
def remote_desired_capabilities
  data_to_object(Cproton.pn_connection_remote_desired_capabilities(@impl))
end
remote_hostname() click to toggle source

Get the AMQP hostname set by the remote connection endpoint.

This will return nil until the #REMOTE_ACTIVE state is reached.

@return [String] The remote connection's AMQP hostname.

@see hostname

# File lib/core/connection.rb, line 164
def remote_hostname
  Cproton.pn_connection_remote_hostname(@impl)
end
remote_offered_capabilities() click to toggle source

Get the AMQP offered capabilities suppolied by the remote connection endpoint.

This object returned is valid until the connection is freed. The Data object will be empty until the remote connection is opened, as indicated by the #REMOTE_ACTIVE flag.

@return [Data] The offered capabilities.

# File lib/core/connection.rb, line 177
def remote_offered_capabilities
  data_to_object(Cproton.pn_connection_remote_offered_capabilities(@impl))
end
remote_properties() click to toggle source

Get the AMQP connection properties supplie by the remote connection endpoint.

The object returned is valid until the connection is freed. The Data object will be empty until the remote connection is opened, as indicated by the #REMOTE_ACTIVE flag.

@return [Data] The remote properties.

# File lib/core/connection.rb, line 203
def remote_properties
  data_to_object(Cproton.pn_connection_remote_properites(@impl))
end
session() click to toggle source

Returns the session for this connection.

@return [Session] The session.

# File lib/core/connection.rb, line 246
def session
  @session ||= Session.wrap(Cproton.pn_session(@impl))
end
session_head(mask) click to toggle source

Returns the first session from the connection that matches the specified state mask.

Examines the state of each session owned by the connection, and returns the first session that matches the given state mask. If the state mask contains both local and remote flags, then an exact match against those flags is performed. If the state mask contains only local or remote flags, then a match occurs if a*any* of the local or remote flags are set, respectively.

@param mask [Integer] The state mask to be matched.

@return [Session] The first matching session, or nil if none matched.

@see Endpoint#LOCAL_UNINIT @see Endpoint#LOCAL_ACTIVE @see Endpoint#LOCAL_CLOSED @see Endpoint#REMOTE_UNINIT @see Endpoint#REMOTE_ACTIVE @see Endpoint#REMOTE_CLOSED

# File lib/core/connection.rb, line 271
def session_head(mask)
  Session.wrap(Cproton.pn_session_header(@impl, mask))
end
session_policy?() click to toggle source
# File lib/core/connection.rb, line 87
def session_policy?
  !@session_policy.nil?
end
state() click to toggle source

Gets the endpoint current state flags

@see Endpoint#LOCAL_UNINIT @see Endpoint#LOCAL_ACTIVE @see Endpoint#LOCAL_CLOSED @see Endpoint#LOCAL_MASK

@return [Integer] The state flags.

# File lib/core/connection.rb, line 238
def state
  Cproton.pn_connection_state(@impl)
end
transport() click to toggle source

The Transport to which this connection is bound.

@return [Transport] The transport, or nil if the Connection is unbound.

# File lib/core/connection.rb, line 103
def transport
  Transport.wrap(Cproton.pn_connection_transport(@impl))
end
work_head() click to toggle source

Extracts the first delivery on the connection that has pending operations.

A readable delivery indicates message data is waiting to be read. A A writable delivery indcates that message data may be sent. An updated delivery indicates that the delivery's disposition has changed.

A delivery will never be both readable and writable, but it may be both readable or writable and updated.

@return [Delivery] The delivery, or nil if none are available.

@see Delivery#next

# File lib/core/connection.rb, line 313
def work_head
  Delivery.wrap(Cproton.pn_work_head(@impl))
end