Class: Qpid::Proton::Connection

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/core/connection.rb

Overview

An AMQP connection.

Constant Summary collapse

PROTON_METHOD_PREFIX =
"pn_connection"

Constants inherited from Endpoint

Endpoint::LOCAL_ACTIVE, Endpoint::LOCAL_CLOSED, Endpoint::LOCAL_MASK, Endpoint::LOCAL_UNINIT, Endpoint::REMOTE_ACTIVE, Endpoint::REMOTE_CLOSED, Endpoint::REMOTE_MASK, Endpoint::REMOTE_UNINIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint

#closed?, #local_closed?, #local_open?, #local_uninit?, #open?, #remote_closed?, #remote_open?, #remote_uninit?

Instance Attribute Details

#containerContainer (readonly)

Returns the container managing this connection.

Returns:

  • (Container)

    the container managing this connection



76
77
78
# File 'lib/core/connection.rb', line 76

def container
  @container
end

#work_queueWorkQueue (readonly)

Returns work queue to execute code serialized correctly for this connection.

Returns:

  • (WorkQueue)

    work queue to execute code serialized correctly for this connection



291
292
293
# File 'lib/core/connection.rb', line 291

def work_queue
  @work_queue
end

Instance Method Details

#close(error = nil)

Closes the local end of the connection. The remote end may or may not be closed.

Parameters:

  • error (Condition) (defaults to: nil)

    Optional error condition to send with the close.



174
175
176
177
# File 'lib/core/connection.rb', line 174

def close(error=nil)
  Condition.assign(_local_condition, error)
  Cproton.pn_connection_close(@impl)
end

#connectionConnection

Returns self.

Returns:



65
# File 'lib/core/connection.rb', line 65

def connection() self; end

#container_id

To get the local container ID use #container and Qpid::Proton::Container#id

Returns:

  • AMQP container ID advertised by the remote peer.



72
# File 'lib/core/connection.rb', line 72

def container_id() Cproton.pn_connection_remote_container(@impl); end

#default_sessionSession

Returns the default session for this connection.

Returns:



196
197
198
# File 'lib/core/connection.rb', line 196

def default_session
  @session ||= open_session
end

#desired_capabilitiesArray<Symbol>

Returns desired capabilities provided by the remote peer.

Returns:

  • (Array<Symbol>)

    desired capabilities provided by the remote peer



86
87
88
89
# File 'lib/core/connection.rb', line 86

def desired_capabilities
  # Provide capabilities consistently as an array, even if encoded as a single symbol
  Codec::Data.to_multiple(Cproton.pn_connection_remote_desired_capabilities(@impl))
end

Get the links on this connection.

Overloads:

  • #each_link {|l| ... }

    Yield Parameters:

    • l (Link)

      pass each link to block

  • #each_linkEnumerator

    Returns enumerator over links.

    Returns:

    • (Enumerator)

      enumerator over links



250
251
252
253
254
255
256
257
258
259
# File 'lib/core/connection.rb', line 250

def each_link
  return enum_for(:each_link) unless block_given?
  l = Cproton.pn_link_head(@impl, 0);
  while l
    l2 = l                  #  get next before yield, in case yield closes l and unlinks it
    l = Cproton.pn_link_next(l, 0)
    yield Link.wrap(l2)
  end
  self
end

#each_receiver

Get the Receiver links - see #each_link



268
269
270
271
# File 'lib/core/connection.rb', line 268

def each_receiver()
  return enum_for(:each_receiver) unless block_given?
  each_link.select { |l| yield l if l.receiver? }
end

#each_sender

Get the Sender links - see #each_link



262
263
264
265
# File 'lib/core/connection.rb', line 262

def each_sender()
  return enum_for(:each_sender) unless block_given?
  each_link.select { |l| yield l if l.sender? }
end

#each_session {|s| ... } #each_sessionEnumerator

Get the sessions on this connection.

Overloads:

  • #each_session {|s| ... }

    Yield Parameters:

    • s (Session)

      pass each session to block

  • #each_sessionEnumerator

    Returns enumerator over sessions.

    Returns:

    • (Enumerator)

      enumerator over sessions



229
230
231
232
233
234
235
236
237
# File 'lib/core/connection.rb', line 229

def each_session(&block)
  return enum_for(:each_session) unless block_given?
  s = Cproton.pn_session_head(@impl, 0);
  while s
    yield Session.wrap(s)
    s = Cproton.pn_session_next(s, 0)
  end
  self
end

#error

Deprecated.

use Endpoint#condition



280
281
282
283
# File 'lib/core/connection.rb', line 280

def error
  deprecated __method__, "#condition"
  Cproton.pn_error_code(Cproton.pn_connection_error(@impl))
end

#idle_timeoutNumeric?

Idle-timeout advertised by the remote peer, in seconds.

Returns:

  • (Numeric)

    Idle-timeout advertised by the remote peer, in seconds.

  • (nil)

    if the peer does not advertise an idle time-out



147
148
149
150
151
# File 'lib/core/connection.rb', line 147

def idle_timeout()
  if transport && (t = transport.remote_idle_timeout)
    Rational(t, 1000)       # More precise than Float
  end
end
Deprecated.


240
241
242
243
# File 'lib/core/connection.rb', line 240

def link_head(mask)
  deprecated __method__, "#each_link"
  Link.wrap(Cproton.pn_link_head(@impl, mask))
end

#max_frame_sizeInteger?

Maximum frame size, in bytes, advertised by the remote peer. See :max_frame_size

Returns:

  • (Integer)

    maximum frame size

  • (nil)

    no limit

Raises:



166
167
168
169
170
# File 'lib/core/connection.rb', line 166

def max_frame_size()
  raise StateError, "connection not bound to transport" unless transport
  max = transport.remote_max_frame
  return max.zero? ? nil : max
end

#max_sessionsInteger?

Session limit advertised by the remote peer. See :max_sessions

Returns:

  • (Integer)

    maximum number of sessions per connection allowed by remote peer.

  • (nil)

    no specific limit is set.

Raises:



156
157
158
159
160
# File 'lib/core/connection.rb', line 156

def max_sessions()
  raise StateError, "connection not bound to transport" unless transport
  max = transport.remote_channel_max
  return max.zero? ? nil : max
end

#offered_capabilitiesArray<Symbol>

Returns offered capabilities provided by the remote peer.

Returns:

  • (Array<Symbol>)

    offered capabilities provided by the remote peer



79
80
81
82
# File 'lib/core/connection.rb', line 79

def offered_capabilities
  # Provide capabilities consistently as an array, even if encoded as a single symbol
  Codec::Data.to_multiple(Cproton.pn_connection_remote_offered_capabilities(@impl))
end

#open(opts = nil)

Open the local end of the connection.

Parameters:

  • opts (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (opts):

  • :handler (MessagingHandler)

    handler for events related to this connection.

  • :user (String)

    User name for authentication

  • :password (String)

    Authentication secret

  • :virtual_host (String)

    Virtual host name

  • :container_id (String) — default: provided by {Container}

    override advertised container-id

  • :properties (Hash<Symbol=>Object>)

    Application-defined properties

  • :offered_capabilities (Array<Symbol>)

    Extensions the endpoint supports

  • :desired_capabilities (Array<Symbol>)

    Extensions the endpoint can use

  • :idle_timeout (Numeric)

    Seconds before closing an idle connection

  • :max_sessions (Integer)

    Limit the number of active sessions

  • :max_frame_size (Integer)

    Limit the size of AMQP frames

  • :sasl_enabled (Boolean) — default: false

    Enable or disable SASL.

  • :sasl_allow_insecure_mechs (Boolean) — default: false

    Allow mechanisms that send secrets in cleartext

  • :sasl_allowed_mechs (String)

    Specify the SASL mechanisms allowed for this connection. The value is a space-separated list of mechanism names. The mechanisms allowed by default are determined by your SASL library and system configuration, with two exceptions: GSSAPI and GSS-SPNEGO are disabled by default. To enable them, you must explicitly add them using this option. Clients must set the allowed mechanisms before the the outgoing connection is attempted. Servers must set them before the listening connection is setup.

  • :ssl_domain (SSLDomain)

    SSL configuration domain.



121
122
123
124
125
# File 'lib/core/connection.rb', line 121

def open(opts=nil)
  return if local_active?
  apply opts if opts
  Cproton.pn_connection_open(@impl)
end

#open_receiver(opts = nil)

Open a on the default_session



216
# File 'lib/core/connection.rb', line 216

def open_receiver(opts=nil) default_session.open_receiver(opts) end

#open_sender(opts = nil)

Open a sender on the default_session



212
# File 'lib/core/connection.rb', line 212

def open_sender(opts=nil) default_session.open_sender(opts) end

#open_session

Open a new session on this connection.



204
205
206
207
208
# File 'lib/core/connection.rb', line 204

def open_session
  s = Session.wrap(Cproton.pn_session(@impl))
  s.open
  return s
end

#overrides?Boolean

Deprecated.

no replacement

Returns:

  • (Boolean)


59
# File 'lib/core/connection.rb', line 59

def overrides?() deprecated __method__; false; end

#propertiesHash

Returns connection-properties provided by the remote peer.

Returns:

  • (Hash)

    connection-properties provided by the remote peer



93
94
95
# File 'lib/core/connection.rb', line 93

def properties
  Codec::Data.to_object(Cproton.pn_connection_remote_properties(@impl))
end

#session_head(mask)

Deprecated.


219
220
221
222
# File 'lib/core/connection.rb', line 219

def  session_head(mask)
  deprecated __method__, "#each_session"
  Session.wrap(Cproton.pn_session_head(@impl, mask))
end

#session_policy?Boolean

Deprecated.

no replacement

Returns:

  • (Boolean)


62
# File 'lib/core/connection.rb', line 62

def session_policy?() deprecated __method__; false; end

#stateInteger

Gets the endpoint current state flags

Returns:

  • (Integer)

    The state flags.

See Also:

  • Endpoint#LOCAL_UNINIT
  • Endpoint#LOCAL_ACTIVE
  • Endpoint#LOCAL_CLOSED
  • Endpoint#LOCAL_MASK


188
189
190
# File 'lib/core/connection.rb', line 188

def state
  Cproton.pn_connection_state(@impl)
end

#transportTransport?

Returns transport bound to this connection, or nil if unbound.

Returns:

  • (Transport, nil)

    transport bound to this connection, or nil if unbound.



68
# File 'lib/core/connection.rb', line 68

def transport() Transport.wrap(Cproton.pn_connection_transport(@impl)); end

#userString

or the authenticated user name (incoming connection)

Returns:

  • (String)

    User name used for authentication (outgoing connection)



54
55
56
# File 'lib/core/connection.rb', line 54

def user()
  Cproton.pn_connection_get_user(impl) or (connection.transport && connection.transport.user)
end

#virtual_hostString

Returns The AMQP hostname for the connection.

Returns:

  • (String)

    The AMQP hostname for the connection.



45
# File 'lib/core/connection.rb', line 45

def virtual_host() Cproton.pn_connection_remote_hostname(@impl); end

#work_head

Deprecated.

use #MessagingHandler to handle work



274
275
276
277
# File 'lib/core/connection.rb', line 274

def work_head
  deprecated __method__
  Delivery.wrap(Cproton.pn_work_head(@impl))
end