-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Codec
-
-
# +DataError+ is raised when an error occurs while encoding
-
# or decoding data.
-
1
class DataError < Exception; end
-
-
# The +Data+ class provides an interface for decoding, extracting,
-
# creating, and encoding arbitrary AMQP data. A +Data+ object
-
# contains a tree of AMQP values. Leaf nodes in this tree correspond
-
# to scalars in the AMQP type system such as INT or STRING. Interior
-
# nodes in this tree correspond to compound values in the AMQP type
-
# system such as *LIST*,*MAP*, *ARRAY*, or *DESCRIBED*. The root node
-
# of the tree is the +Data+ object itself and can have an arbitrary
-
# number of children.
-
#
-
# A +Data+ object maintains the notion of the current sibling node
-
# and a current parent node. Siblings are ordered within their parent.
-
# Values are accessed and/or added by using the #next, #prev,
-
# #enter, and #exit methods to navigate to the desired location in
-
# the tree and using the supplied variety of mutator and accessor
-
# methods to access or add a value of the desired type.
-
#
-
# The mutator methods will always add a value _after_ the current node
-
# in the tree. If the current node has a next sibling the mutator method
-
# will overwrite the value on this node. If there is no current node
-
# or the current node has no next sibling then one will be added. The
-
# accessor methods always set the added/modified node to the current
-
# node. The accessor methods read the value of the current node and do
-
# not change which node is current.
-
#
-
# The following types of scalar values are supported:
-
#
-
# * NULL
-
# * BOOL
-
# * UBYTE
-
# * BYTE
-
# * USHORT
-
# * SHORT
-
# * UINT
-
# * INT
-
# * CHAR
-
# * ULONG
-
# * LONG
-
# * TIMESTAMP
-
# * FLOAT
-
# * DOUBLE
-
# * DECIMAL32
-
# * DECIMAL64
-
# * DECIMAL128
-
# * UUID
-
# * BINARY
-
# * STRING
-
# * SYMBOL
-
#
-
# The following types of compound values are supported:
-
#
-
# * DESCRIBED
-
# * ARRAY
-
# * LIST
-
# * MAP
-
#
-
1
class Data
-
-
# Creates a new instance with the specified capacity.
-
#
-
# @param capacity [Fixnum, Object] The initial capacity or content.
-
#
-
1
def initialize(capacity = 16)
-
120
if (!capacity.nil?) &&
-
(capacity.is_a?(Fixnum) ||
-
120
capacity.is_a?(Bignum))
-
84
@data = Cproton.pn_data(capacity)
-
84
@free = true
-
else
-
36
@data = capacity
-
36
@free = false
-
end
-
-
# destructor
-
120
ObjectSpace.define_finalizer(self, self.class.finalize!(@data, @free))
-
end
-
-
# @private
-
1
def self.finalize!(data, free)
-
120
proc {
-
78
Cproton.pn_data_free(data) if free
-
}
-
end
-
-
# @private
-
1
def to_s
-
tmp = Cproton.pn_string("")
-
Cproton.pn_inspect(@data, tmp)
-
result = Cproton.pn_string_get(tmp)
-
Cproton.pn_free(tmp)
-
return result
-
end
-
-
# Clears the object.
-
#
-
1
def clear
-
36
Cproton.pn_data_clear(@data)
-
end
-
-
# Clears the current node and sets the parent to the root node.
-
#
-
# Clearing the current node sets it *before* the first node, calling
-
# #next will advance to the first node.
-
#
-
1
def rewind
-
2
Cproton.pn_data_rewind(@data)
-
end
-
-
# Advances the current node to its next sibling and returns its types.
-
#
-
# If there is no next sibling the current node remains unchanged
-
# and nil is returned.
-
#
-
1
def next
-
330
Cproton.pn_data_next(@data)
-
end
-
-
# Advances the current node to its previous sibling and returns its type.
-
#
-
# If there is no previous sibling then the current node remains unchanged
-
# and nil is return.
-
#
-
1
def prev
-
return Cproton.pn_data_prev(@data) ? type : nil
-
end
-
-
# Sets the parent node to the current node and clears the current node.
-
#
-
# Clearing the current node sets it _before_ the first child.
-
#
-
1
def enter
-
37
Cproton.pn_data_enter(@data)
-
end
-
-
# Sets the current node to the parent node and the parent node to its own
-
# parent.
-
#
-
1
def exit
-
31
Cproton.pn_data_exit(@data)
-
end
-
-
# Returns the numeric type code of the current node.
-
#
-
# @return [Fixnum] The current node type.
-
# @return [nil] If there is no current node.
-
#
-
1
def type_code
-
160
dtype = Cproton.pn_data_type(@data)
-
160
return (dtype == -1) ? nil : dtype
-
end
-
-
# Return the type object for the current node
-
#
-
# @param [Fixnum] The object type.
-
#
-
# @see #type_code
-
#
-
1
def type
-
160
Mapping.for_code(type_code)
-
end
-
-
# Returns a representation of the data encoded in AMQP format.
-
#
-
# @return [String] The context of the Data as an AMQP data string.
-
#
-
# @example
-
#
-
# @data.string = "This is a test."
-
# @encoded = @data.encode
-
#
-
# # @encoded now contains the text "This is a test." encoded for
-
# # AMQP transport.
-
#
-
1
def encode
-
buffer = "\0"*1024
-
loop do
-
cd = Cproton.pn_data_encode(@data, buffer, buffer.length)
-
if cd == Cproton::PN_OVERFLOW
-
buffer *= 2
-
elsif cd >= 0
-
return buffer[0...cd]
-
else
-
check(cd)
-
end
-
end
-
end
-
-
# Decodes the first value from supplied AMQP data and returns the number
-
# of bytes consumed.
-
#
-
# @param encoded [String] The encoded data.
-
#
-
# @example
-
#
-
# # SCENARIO: A string of encoded data, @encoded, contains the text
-
# # of "This is a test." and is passed to an instance of Data
-
# # for decoding.
-
#
-
# @data.decode(@encoded)
-
# @data.string #=> "This is a test."
-
#
-
1
def decode(encoded)
-
check(Cproton.pn_data_decode(@data, encoded, encoded.length))
-
end
-
-
# Puts a list value.
-
#
-
# Elements may be filled by entering the list node and putting element
-
# values.
-
#
-
# @example
-
#
-
# data = Qpid::Proton::Codec::Data.new
-
# data.put_list
-
# data.enter
-
# data.int = 1
-
# data.int = 2
-
# data.int = 3
-
# data.exit
-
#
-
1
def put_list
-
2
check(Cproton.pn_data_put_list(@data))
-
end
-
-
# If the current node is a list, this returns the number of elements.
-
# Otherwise, it returns zero.
-
#
-
# List elements can be accessed by entering the list.
-
#
-
# @example
-
#
-
# count = @data.list
-
# @data.enter
-
# (0...count).each
-
# type = @data.next
-
# puts "Value: #{@data.string}" if type == STRING
-
# # ... process other node types
-
# end
-
1
def list
-
1
Cproton.pn_data_get_list(@data)
-
end
-
-
# Puts a map value.
-
#
-
# Elements may be filled by entering the map node and putting alternating
-
# key/value pairs.
-
#
-
# @example
-
#
-
# data = Qpid::Proton::Codec::Data.new
-
# data.put_map
-
# data.enter
-
# data.string = "key"
-
# data.string = "value"
-
# data.exit
-
#
-
1
def put_map
-
20
check(Cproton.pn_data_put_map(@data))
-
end
-
-
# If the current node is a map, this returns the number of child
-
# elements. Otherwise, it returns zero.
-
#
-
# Key/value pairs can be accessed by entering the map.
-
#
-
# @example
-
#
-
# count = @data.map
-
# @data.enter
-
# (0...count).each do
-
# type = @data.next
-
# puts "Key=#{@data.string}" if type == STRING
-
# # ... process other key types
-
# type = @data.next
-
# puts "Value=#{@data.string}" if type == STRING
-
# # ... process other value types
-
# end
-
# @data.exit
-
1
def map
-
1
Cproton.pn_data_get_map(@data)
-
end
-
-
# @private
-
1
def get_map
-
::Hash.proton_data_get(self)
-
end
-
-
# Puts an array value.
-
#
-
# Elements may be filled by entering the array node and putting the
-
# element values. The values must all be of the specified array element
-
# type.
-
#
-
# If an array is *described* then the first child value of the array
-
# is the descriptor and may be of any type.
-
#
-
# @param described [Boolean] True if the array is described.
-
# @param element_type [Fixnum] The AMQP type for each element of the array.
-
#
-
# @example
-
#
-
# # create an array of integer values
-
# data = Qpid::Proton::Codec::Data.new
-
# data.put_array(false, INT)
-
# data.enter
-
# data.int = 1
-
# data.int = 2
-
# data.int = 3
-
# data.exit
-
#
-
# # create a described array of double values
-
# data.put_array(true, DOUBLE)
-
# data.enter
-
# data.symbol = "array-descriptor"
-
# data.double = 1.1
-
# data.double = 1.2
-
# data.double = 1.3
-
# data.exit
-
#
-
1
def put_array(described, element_type)
-
5
check(Cproton.pn_data_put_array(@data, described, element_type.code))
-
end
-
-
# If the current node is an array, returns a tuple of the element count, a
-
# boolean indicating whether the array is described, and the type of each
-
# element. Otherwise it returns +(0, false, nil).
-
#
-
# Array data can be accessed by entering the array.
-
#
-
# @example
-
#
-
# # get the details of thecurrent array
-
# count, described, array_type = @data.array
-
#
-
# # enter the node
-
# data.enter
-
#
-
# # get the next node
-
# data.next
-
# puts "Descriptor: #{data.symbol}" if described
-
# (0...count).each do
-
# @data.next
-
# puts "Element: #{@data.string}"
-
# end
-
1
def array
-
3
count = Cproton.pn_data_get_array(@data)
-
3
described = Cproton.pn_data_is_array_described(@data)
-
3
array_type = Cproton.pn_data_get_array_type(@data)
-
3
return nil if array_type == -1
-
3
[count, described, Mapping.for_code(array_type) ]
-
end
-
-
# @private
-
1
def get_array
-
::Array.proton_get(self)
-
end
-
-
# Puts a described value.
-
#
-
# A described node has two children, the descriptor and the value.
-
# These are specified by entering the node and putting the
-
# desired values.
-
#
-
# @example
-
#
-
# data = Qpid::Proton::Codec::Data.new
-
# data.put_described
-
# data.enter
-
# data.symbol = "value-descriptor"
-
# data.string = "the value"
-
# data.exit
-
#
-
1
def put_described
-
1
check(Cproton.pn_data_put_described(@data))
-
end
-
-
# @private
-
1
def get_described
-
raise TypeError, "not a described type" unless self.described?
-
self.enter
-
self.next
-
type = self.type
-
descriptor = type.get(self)
-
self.next
-
type = self.type
-
value = type.get(self)
-
self.exit
-
Qpid::Proton::Types::Described.new(descriptor, value)
-
end
-
-
# Checks if the current node is a described value.
-
#
-
# The described and value may be accessed by entering the described value.
-
#
-
# @example
-
#
-
# if @data.described?
-
# @data.enter
-
# puts "The symbol is #{@data.symbol}"
-
# puts "The value is #{@data.string}"
-
# end
-
1
def described?
-
1
Cproton.pn_data_is_described(@data)
-
end
-
-
# Puts a null value.
-
#
-
1
def null
-
1
check(Cproton.pn_data_put_null(@data))
-
end
-
-
# Utility method for Qpid::Proton::Codec::Mapping
-
#
-
# @private
-
#
-
1
def null=(value)
-
null
-
end
-
-
# Puts an arbitrary object type.
-
#
-
# The Data instance will determine which AMQP type is appropriate and will
-
# use that to encode the object.
-
#
-
# @param object [Object] The value.
-
#
-
1
def object=(object)
-
Mapping.for_class(object.class).put(self, object)
-
end
-
-
# Gets the current node, based on how it was encoded.
-
#
-
# @return [Object] The current node.
-
#
-
1
def object
-
type = self.type
-
return nil if type.nil?
-
type.get(data)
-
end
-
-
# Checks if the current node is null.
-
#
-
# @return [Boolean] True if the node is null.
-
#
-
1
def null?
-
1
Cproton.pn_data_is_null(@data)
-
end
-
-
# Puts a boolean value.
-
#
-
# @param value [Boolean] The boolean value.
-
#
-
1
def bool=(value)
-
2
check(Cproton.pn_data_put_bool(@data, value))
-
end
-
-
# If the current node is a boolean, then it returns the value. Otherwise,
-
# it returns false.
-
#
-
# @return [Boolean] The boolean value.
-
#
-
1
def bool
-
2
Cproton.pn_data_get_bool(@data)
-
end
-
-
# Puts an unsigned byte value.
-
#
-
# @param value [Fixnum] The unsigned byte value.
-
#
-
1
def ubyte=(value)
-
3
check(Cproton.pn_data_put_ubyte(@data, value))
-
end
-
-
# If the current node is an unsigned byte, returns its value. Otherwise,
-
# it returns 0.
-
#
-
# @return [Fixnum] The unsigned byte value.
-
#
-
1
def ubyte
-
1
Cproton.pn_data_get_ubyte(@data)
-
end
-
-
# Puts a byte value.
-
#
-
# @param value [Fixnum] The byte value.
-
#
-
1
def byte=(value)
-
2
check(Cproton.pn_data_put_byte(@data, value))
-
end
-
-
# If the current node is an byte, returns its value. Otherwise,
-
# it returns 0.
-
#
-
# @return [Fixnum] The byte value.
-
#
-
1
def byte
-
2
Cproton.pn_data_get_byte(@data)
-
end
-
-
# Puts an unsigned short value.
-
#
-
# @param value [Fixnum] The unsigned short value
-
#
-
1
def ushort=(value)
-
4
check(Cproton.pn_data_put_ushort(@data, value))
-
end
-
-
# If the current node is an unsigned short, returns its value. Otherwise,
-
# it returns 0.
-
#
-
# @return [Fixnum] The unsigned short value.
-
#
-
1
def ushort
-
2
Cproton.pn_data_get_ushort(@data)
-
end
-
-
# Puts a short value.
-
#
-
# @param value [Fixnum] The short value.
-
#
-
1
def short=(value)
-
4
check(Cproton.pn_data_put_short(@data, value))
-
end
-
-
# If the current node is a short, returns its value. Otherwise,
-
# returns a 0.
-
#
-
# @return [Fixnum] The short value.
-
#
-
1
def short
-
3
Cproton.pn_data_get_short(@data)
-
end
-
-
# Puts an unsigned integer value.
-
#
-
# @param value [Fixnum] the unsigned integer value
-
#
-
1
def uint=(value)
-
4
raise TypeError if value.nil?
-
3
raise RangeError, "invalid uint: #{value}" if value < 0
-
2
check(Cproton.pn_data_put_uint(@data, value))
-
end
-
-
# If the current node is an unsigned int, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Fixnum] The unsigned integer value.
-
#
-
1
def uint
-
2
Cproton.pn_data_get_uint(@data)
-
end
-
-
# Puts an integer value.
-
#
-
# ==== Options
-
#
-
# * value - the integer value
-
1
def int=(value)
-
74
check(Cproton.pn_data_put_int(@data, value))
-
end
-
-
# If the current node is an integer, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Fixnum] The integer value.
-
#
-
1
def int
-
72
Cproton.pn_data_get_int(@data)
-
end
-
-
# Puts a character value.
-
#
-
# @param value [Fixnum] The character value.
-
#
-
1
def char=(value)
-
2
check(Cproton.pn_data_put_char(@data, value))
-
end
-
-
# If the current node is a character, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Fixnum] The character value.
-
#
-
1
def char
-
1
Cproton.pn_data_get_char(@data)
-
end
-
-
# Puts an unsigned long value.
-
#
-
# @param value [Fixnum] The unsigned long value.
-
#
-
1
def ulong=(value)
-
4
raise TypeError if value.nil?
-
3
raise RangeError, "invalid ulong: #{value}" if value < 0
-
2
check(Cproton.pn_data_put_ulong(@data, value))
-
end
-
-
# If the current node is an unsigned long, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Fixnum] The unsigned long value.
-
#
-
1
def ulong
-
2
Cproton.pn_data_get_ulong(@data)
-
end
-
-
# Puts a long value.
-
#
-
# @param value [Fixnum] The long value.
-
#
-
1
def long=(value)
-
5
check(Cproton.pn_data_put_long(@data, value))
-
end
-
-
# If the current node is a long, returns its value. Otherwise, returns 0.
-
#
-
# @return [Fixnum] The long value.
-
1
def long
-
4
Cproton.pn_data_get_long(@data)
-
end
-
-
# Puts a timestamp value.
-
#
-
# @param value [Fixnum] The timestamp value.
-
#
-
1
def timestamp=(value)
-
4
value = value.to_i if (!value.nil? && value.is_a?(Time))
-
4
check(Cproton.pn_data_put_timestamp(@data, value))
-
end
-
-
# If the current node is a timestamp, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Fixnum] The timestamp value.
-
#
-
1
def timestamp
-
3
Cproton.pn_data_get_timestamp(@data)
-
end
-
-
# Puts a float value.
-
#
-
# @param value [Float] The floating point value.
-
#
-
1
def float=(value)
-
4
check(Cproton.pn_data_put_float(@data, value))
-
end
-
-
# If the current node is a float, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Float] The floating point value.
-
#
-
1
def float
-
3
Cproton.pn_data_get_float(@data)
-
end
-
-
# Puts a double value.
-
#
-
# @param value [Float] The double precision floating point value.
-
#
-
1
def double=(value)
-
6
check(Cproton.pn_data_put_double(@data, value))
-
end
-
-
# If the current node is a double, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Float] The double precision floating point value.
-
#
-
1
def double
-
5
Cproton.pn_data_get_double(@data)
-
end
-
-
# Puts a decimal32 value.
-
#
-
# @param value [Fixnum] The decimal32 value.
-
#
-
1
def decimal32=(value)
-
3
check(Cproton.pn_data_put_decimal32(@data, value))
-
end
-
-
# If the current node is a decimal32, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Fixnum] The decimal32 value.
-
#
-
1
def decimal32
-
2
Cproton.pn_data_get_decimal32(@data)
-
end
-
-
# Puts a decimal64 value.
-
#
-
# @param value [Fixnum] The decimal64 value.
-
#
-
1
def decimal64=(value)
-
3
check(Cproton.pn_data_put_decimal64(@data, value))
-
end
-
-
# If the current node is a decimal64, returns its value. Otherwise,
-
# it returns 0.
-
#
-
# @return [Fixnum] The decimal64 value.
-
#
-
1
def decimal64
-
2
Cproton.pn_data_get_decimal64(@data)
-
end
-
-
# Puts a decimal128 value.
-
#
-
# @param value [Fixnum] The decimal128 value.
-
#
-
1
def decimal128=(value)
-
3
raise TypeError, "invalid decimal128 value: #{value}" if value.nil?
-
2
value = value.to_s(16).rjust(32, "0")
-
2
bytes = []
-
34
value.scan(/(..)/) {|v| bytes << v[0].to_i(16)}
-
2
check(Cproton.pn_data_put_decimal128(@data, bytes))
-
end
-
-
# If the current node is a decimal128, returns its value. Otherwise,
-
# returns 0.
-
#
-
# @return [Fixnum] The decimal128 value.
-
#
-
1
def decimal128
-
2
value = ""
-
34
Cproton.pn_data_get_decimal128(@data).each{|val| value += ("%02x" % val)}
-
2
value.to_i(16)
-
end
-
-
# Puts a +UUID+ value.
-
#
-
# The UUID is expected to be in the format of a string or else a 128-bit
-
# integer value.
-
#
-
# @param value [String, Numeric] A string or numeric representation of the UUID.
-
#
-
# @example
-
#
-
# # set a uuid value from a string value
-
# require 'securerandom'
-
# @data.uuid = SecureRandom.uuid
-
#
-
# # or
-
# @data.uuid = "fd0289a5-8eec-4a08-9283-81d02c9d2fff"
-
#
-
# # set a uuid value from a 128-bit value
-
# @data.uuid = 0 # sets to 00000000-0000-0000-0000-000000000000
-
#
-
1
def uuid=(value)
-
91
raise ::ArgumentError, "invalid uuid: #{value}" if value.nil?
-
-
# if the uuid that was submitted was numeric value, then translated
-
# it into a hex string, otherwise assume it was a string represtation
-
# and attempt to decode it
-
90
if value.is_a? Numeric
-
1
value = "%032x" % value
-
else
-
89
raise ::ArgumentError, "invalid uuid: #{value}" if !valid_uuid?(value)
-
-
88
value = (value[0, 8] +
-
value[9, 4] +
-
value[14, 4] +
-
value[19, 4] +
-
88
value[24, 12])
-
end
-
89
bytes = []
-
1513
value.scan(/(..)/) {|v| bytes << v[0].to_i(16)}
-
89
check(Cproton.pn_data_put_uuid(@data, bytes))
-
end
-
-
# If the current value is a +UUID+, returns its value. Otherwise,
-
# it returns nil.
-
#
-
# @return [String] The string representation of the UUID.
-
#
-
1
def uuid
-
89
value = ""
-
1513
Cproton.pn_data_get_uuid(@data).each{|val| value += ("%02x" % val)}
-
89
value.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-")
-
end
-
-
# Puts a binary value.
-
#
-
# A binary string is encoded as an ASCII 8-bit string value. This is in
-
# contranst to other strings, which are treated as UTF-8 encoded.
-
#
-
# @param value [String] An arbitrary string value.
-
#
-
# @see #string=
-
#
-
1
def binary=(value)
-
2
check(Cproton.pn_data_put_binary(@data, value))
-
end
-
-
# If the current node is binary, returns its value. Otherwise, it returns
-
# an empty string ("").
-
#
-
# @return [String] The binary string.
-
#
-
# @see #string
-
#
-
1
def binary
-
2
Qpid::Proton::Types::BinaryString.new(Cproton.pn_data_get_binary(@data))
-
end
-
-
# Puts a UTF-8 encoded string value.
-
#
-
# *NOTE:* A nil value is stored as an empty string rather than as a nil.
-
#
-
# @param value [String] The UTF-8 encoded string value.
-
#
-
# @see #binary=
-
#
-
1
def string=(value)
-
179
check(Cproton.pn_data_put_string(@data, value))
-
end
-
-
# If the current node is a string, returns its value. Otherwise, it
-
# returns an empty string ("").
-
#
-
# @return [String] The UTF-8 encoded string.
-
#
-
# @see #binary
-
#
-
1
def string
-
168
Qpid::Proton::Types::UTFString.new(Cproton.pn_data_get_string(@data))
-
end
-
-
# Puts a symbolic value.
-
#
-
# @param value [String] The symbolic string value.
-
#
-
1
def symbol=(value)
-
5
check(Cproton.pn_data_put_symbol(@data, value))
-
end
-
-
# If the current node is a symbol, returns its value. Otherwise, it
-
# returns an empty string ("").
-
#
-
# @return [String] The symbolic string value.
-
#
-
1
def symbol
-
5
Cproton.pn_data_get_symbol(@data)
-
end
-
-
# Get the current value as a single object.
-
#
-
# @return [Object] The current node's object.
-
#
-
# @see #type_code
-
# @see #type
-
#
-
1
def get
-
type.get(self);
-
end
-
-
# Puts a new value with the given type into the current node.
-
#
-
# @param value [Object] The value.
-
# @param type_code [Mapping] The value's type.
-
#
-
# @private
-
#
-
1
def put(value, type_code);
-
type_code.put(self, value);
-
end
-
-
1
private
-
-
1
def valid_uuid?(value)
-
# ensure that the UUID is in the right format
-
# xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
-
89
value =~ /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/
-
end
-
-
# @private
-
1
def check(err)
-
412
if err < 0
-
raise DataError, "[#{err}]: #{Cproton.pn_data_error(@data)}"
-
else
-
412
return err
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Codec
-
-
# Maps between Proton types and their Ruby native language counterparts.
-
#
-
# @private
-
1
class Mapping
-
-
1
attr_reader :code
-
1
attr_reader :put_method
-
1
attr_reader :get_method
-
-
# Creates a new mapping.
-
#
-
# ==== Arguments
-
#
-
# * code - the AMQP code for this type
-
# * name - the AMQP name for this type
-
# * klasses - the Ruby classes for this type
-
# * getter - overrides the get method for the type
-
1
def initialize(code, name, klasses = nil, getter = nil)
-
-
25
@debug = (name == "bool")
-
-
25
@code = code
-
25
@name = name
-
-
25
@@by_preferred ||= {}
-
25
@@by_code ||= {}
-
25
@@by_code["#{code}"] = self
-
25
@@by_name ||= {}
-
25
@@by_name[name] = self
-
25
@@by_class ||= {}
-
-
25
unless klasses.nil?
-
9
klasses.each do |klass|
-
15
raise "entry exists for #{klass}" if @@by_class.keys.include? klass
-
15
@@by_class[klass] = self unless klass.nil?
-
end
-
end
-
-
25
@put_method = (name + "=").intern
-
-
25
if getter.nil?
-
19
@get_method = name.intern
-
else
-
6
@get_method = getter.intern
-
end
-
end
-
-
1
def to_s; @name; end
-
-
1
def put(data, value)
-
146
data.__send__(@put_method, value)
-
end
-
-
1
def get(data)
-
153
data.__send__(@get_method)
-
end
-
-
1
def self.for_class(klass) # :nodoc:
-
39
@@by_class[klass]
-
end
-
-
1
def self.for_code(code)
-
163
@@by_code["#{code}"]
-
end
-
-
end
-
-
1
NULL = Mapping.new(Cproton::PN_NULL, "null", [NilClass], "nil?")
-
1
BOOL = Mapping.new(Cproton::PN_BOOL, "bool", [TrueClass, FalseClass], "bool")
-
1
UBYTE = Mapping.new(Cproton::PN_UBYTE, "ubyte")
-
1
BYTE = Mapping.new(Cproton::PN_BYTE, "byte")
-
1
USHORT = Mapping.new(Cproton::PN_USHORT, "ushort")
-
1
SHORT = Mapping.new(Cproton::PN_SHORT, "short")
-
1
UINT = Mapping.new(Cproton::PN_UINT, "uint")
-
1
INT = Mapping.new(Cproton::PN_INT, "int")
-
1
CHAR = Mapping.new(Cproton::PN_CHAR, "char")
-
1
ULONG = Mapping.new(Cproton::PN_ULONG, "ulong")
-
1
LONG = Mapping.new(Cproton::PN_LONG, "long", [Fixnum, Bignum])
-
1
TIMESTAMP = Mapping.new(Cproton::PN_TIMESTAMP, "timestamp", [Date, Time])
-
1
FLOAT = Mapping.new(Cproton::PN_FLOAT, "float")
-
1
DOUBLE = Mapping.new(Cproton::PN_DOUBLE, "double", [Float])
-
1
DECIMAL32 = Mapping.new(Cproton::PN_DECIMAL32, "decimal32")
-
1
DECIMAL64 = Mapping.new(Cproton::PN_DECIMAL64, "decimal64")
-
1
DECIMAL128 = Mapping.new(Cproton::PN_DECIMAL128, "decimal128")
-
1
UUID = Mapping.new(Cproton::PN_UUID, "uuid")
-
1
BINARY = Mapping.new(Cproton::PN_BINARY, "binary")
-
1
STRING = Mapping.new(Cproton::PN_STRING, "string", [String, Symbol,
-
Qpid::Proton::Types::UTFString,
-
Qpid::Proton::Types::BinaryString])
-
-
# @private
-
1
class << STRING
-
1
def put(data, value)
-
# if we have a symbol then convert it to a string
-
17
value = value.to_s if value.is_a?(Symbol)
-
-
17
isutf = false
-
-
17
if value.is_a?(Qpid::Proton::Types::UTFString)
-
isutf = true
-
else
-
# For Ruby 1.8 we will just treat all strings as binary.
-
# For Ruby 1.9+ we can check the encoding first to see what it is
-
17
if RUBY_VERSION >= "1.9"
-
# If the string is ASCII-8BIT then treat is as binary. Otherwise,
-
# try to convert it to UTF-8 and, if successful, send as that.
-
if value.encoding != Encoding::ASCII_8BIT &&
-
17
value.encode(Encoding::UTF_8).valid_encoding?
-
17
isutf = true
-
end
-
end
-
end
-
-
17
data.string = value if isutf
-
17
data.binary = value if !isutf
-
-
end
-
end
-
-
1
SYMBOL = Mapping.new(Cproton::PN_SYMBOL, "symbol")
-
1
DESCRIBED = Mapping.new(Cproton::PN_DESCRIBED, "described", [Qpid::Proton::Types::Described], "get_described")
-
1
ARRAY = Mapping.new(Cproton::PN_ARRAY, "array", nil, "get_array")
-
1
LIST = Mapping.new(Cproton::PN_LIST, "list", [::Array], "get_array")
-
1
MAP = Mapping.new(Cproton::PN_MAP, "map", [::Hash], "get_map")
-
-
# @private
-
1
class << MAP
-
1
def put(data, map, options = {})
-
18
data.put_map
-
18
data.enter
-
18
map.each_pair do |key, value|
-
if options[:keys] == :SYMBOL
-
SYMBOL.put(data, key)
-
else
-
Mapping.for_class(key.class).put(data, key)
-
end
-
-
if value.nil?
-
data.null
-
else
-
Mapping.for_class(value.class).put(data, value)
-
end
-
end
-
18
data.exit
-
end
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
1
class BaseHandler
-
-
# Override to process unhandled events.
-
#
-
1
def on_unhandled(method, *args)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# A Connection option has at most one Qpid::Proton::Transport instance.
-
#
-
1
class Connection < Endpoint
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_connection"
-
-
# @!attribute hostname
-
#
-
# @return [String] The AMQP hostname for the connection.
-
#
-
1
proton_accessor :hostname
-
-
# @private
-
1
proton_reader :attachments
-
-
1
attr_accessor :overrides
-
1
attr_accessor :session_policy
-
-
# @private
-
1
include Util::Wrapper
-
-
# @private
-
1
def self.wrap(impl)
-
return nil if impl.nil?
-
-
self.fetch_instance(impl, :pn_connection_attachments) || Connection.new(impl)
-
end
-
-
# 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.
-
#
-
1
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
-
-
1
def overrides?
-
!@overrides.nil?
-
end
-
-
1
def session_policy?
-
!@session_policy.nil?
-
end
-
-
# This method is used when working within the context of an event.
-
#
-
# @return [Connection] The connection itself.
-
#
-
1
def connection
-
self
-
end
-
-
# The Transport to which this connection is bound.
-
#
-
# @return [Transport] The transport, or nil if the Connection is unbound.
-
#
-
1
def transport
-
Transport.wrap(Cproton.pn_connection_transport(@impl))
-
end
-
-
# 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.
-
#
-
1
def collect(collector)
-
if collector.nil?
-
Cproton.pn_connection_collect(@impl, nil)
-
else
-
Cproton.pn_connection_collect(@impl, collector.impl)
-
end
-
@collector = collector
-
end
-
-
# 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
-
#
-
1
def remote_container
-
Cproton.pn_connection_remote_container(@impl)
-
end
-
-
1
def container=(name)
-
Cproton.pn_connection_set_container(@impl, name)
-
end
-
-
1
def container
-
Cproton.pn_connection_get_container(@impl)
-
end
-
-
# 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
-
#
-
1
def remote_hostname
-
Cproton.pn_connection_remote_hostname(@impl)
-
end
-
-
# 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.
-
#
-
1
def remote_offered_capabilities
-
data_to_object(Cproton.pn_connection_remote_offered_capabilities(@impl))
-
end
-
-
# 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.
-
#
-
1
def remote_desired_capabilities
-
data_to_object(Cproton.pn_connection_remote_desired_capabilities(@impl))
-
end
-
-
# 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.
-
#
-
1
def remote_properties
-
data_to_object(Cproton.pn_connection_remote_properites(@impl))
-
end
-
-
# Opens the connection.
-
#
-
1
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
-
-
# Closes the connection.
-
#
-
# Once this operation has completed, the #LOCAL_CLOSED state flag will be
-
# set.
-
#
-
1
def close
-
self._update_condition
-
Cproton.pn_connection_close(@impl)
-
end
-
-
# Gets the endpoint current state flags
-
#
-
# @see Endpoint#LOCAL_UNINIT
-
# @see Endpoint#LOCAL_ACTIVE
-
# @see Endpoint#LOCAL_CLOSED
-
# @see Endpoint#LOCAL_MASK
-
#
-
# @return [Fixnum] The state flags.
-
#
-
1
def state
-
Cproton.pn_connection_state(@impl)
-
end
-
-
# Returns the session for this connection.
-
#
-
# @return [Session] The session.
-
#
-
1
def session
-
@session ||= Session.wrap(Cproton.pn_session(@impl))
-
end
-
-
# 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 [Fixnum] 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
-
#
-
1
def session_head(mask)
-
Session.wrap(Cproton.pn_session_header(@impl, mask))
-
end
-
-
# Returns the first link that matches the given state mask.
-
#
-
# Examines the state of each link owned by the connection and returns the
-
# first 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 *any* of the local ore remote flags are set,
-
# respectively.
-
#
-
# @param mask [Fixnum] The state mask to be matched.
-
#
-
# @return [Link] The first matching link, 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
-
#
-
1
def link_head(mask)
-
Link.wrap(Cproton.pn_link_head(@impl, mask))
-
end
-
-
# 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
-
#
-
1
def work_head
-
Delivery.wrap(Cproton.pn_work_head(@impl))
-
end
-
-
# Returns the code for a connection error.
-
#
-
# @return [Fixnum] The error code.
-
#
-
1
def error
-
Cproton.pn_error_code(Cproton.pn_connection_error(@impl))
-
end
-
-
# @private
-
1
def _local_condition
-
Cproton.pn_connection_condition(@impl)
-
end
-
-
# @private
-
1
def _remote_condition
-
Cproton.pn_connection_remote_condition(@impl)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# A Delivery maintains detail on the delivery of data to an endpoint.
-
#
-
# A Delivery has a single parent Qpid::Proton::Link
-
#
-
# @example
-
#
-
# # SCENARIO: An event comes in notifying that data has been delivered to
-
# # the local endpoint. A Delivery object can be used to check
-
# # the details of the delivery.
-
#
-
# delivery = @event.delivery
-
# if delivery.readable? && !delivery.partial?
-
# # decode the incoming message
-
# msg = Qpid::Proton::Message.new
-
# msg.decode(link.receive(delivery.pending))
-
# end
-
#
-
1
class Delivery
-
-
# @private
-
1
include Util::Wrapper
-
-
# @private
-
1
def self.wrap(impl) # :nodoc:
-
return nil if impl.nil?
-
self.fetch_instance(impl, :pn_delivery_attachments) || Delivery.new(impl)
-
end
-
-
# @private
-
1
def initialize(impl)
-
@impl = impl
-
@local = Disposition.new(Cproton.pn_delivery_local(impl), true)
-
@remote = Disposition.new(Cproton.pn_delivery_remote(impl), false)
-
self.class.store_instance(self, :pn_delivery_attachments)
-
end
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_delivery"
-
-
# @!attribute [r] tag
-
#
-
# @return [String] The tag for the delivery.
-
#
-
1
proton_caller :tag
-
-
# @!attribute [r] writable?
-
#
-
# A delivery is considered writable if it is the current delivery on an
-
# outgoing link, and the link has positive credit.
-
#
-
# @return [Boolean] Returns if a delivery is writable.
-
#
-
1
proton_caller :writable?
-
-
# @!attribute [r] readable?
-
#
-
# A delivery is considered readable if it is the current delivery on an
-
# incoming link.
-
#
-
# @return [Boolean] Returns if a delivery is readable.
-
#
-
1
proton_caller :readable?
-
# @!attribute [r] updated?
-
#
-
# A delivery is considered updated whenever the peer communicates a new
-
# disposition for the dlievery. Once a delivery becomes updated, it will
-
# remain so until cleared.
-
#
-
# @return [Boolean] Returns if a delivery is updated.
-
#
-
# @see #clear
-
#
-
1
proton_caller :updated?
-
-
# @!method clear
-
#
-
# Clear the updated flag for a delivery.
-
#
-
1
proton_caller :clear
-
-
# @!attribute [r] pending
-
#
-
# @return [Fixnum] Return the amount of pending message data for the
-
# delivery.
-
#
-
1
proton_caller :pending
-
-
# @!attribute [r] partial?
-
#
-
# @return [Boolean] Returns if the delivery has only partial message data.
-
#
-
1
proton_caller :partial?
-
-
# @!attribute [r] settled?
-
#
-
# @return [Boolean] Returns if the delivery is remotely settled.
-
#
-
1
proton_caller :settled?
-
-
-
# @!method settle
-
#
-
# Settles a delivery.
-
#
-
# A settled delivery can never be used again.
-
#
-
1
proton_caller :settle
-
-
# @!method dump
-
#
-
# Utility function for printing details of a delivery.
-
#
-
1
proton_caller :dump
-
-
# @!attribute [r] buffered?
-
#
-
# A delivery that is buffered has not yet been written to the wire.
-
#
-
# Note that returning false does not imply that a delivery was definitely
-
# written to the wire. If false is returned, it is not known whether the
-
# delivery was actually written to the wire or not.
-
#
-
# @return [Boolean] Returns if the delivery is buffered.
-
#
-
1
proton_caller :buffered?
-
-
1
include Util::Engine
-
-
1
def update(state)
-
impl = @local.impl
-
object_to_data(@local.data, Cproton.pn_disposition_data(impl))
-
object_to_data(@local.annotations, Cproton.pn_disposition_annotations(impl))
-
object_to_data(@local.condition, Cproton.pn_disposition_condition(impl))
-
Cproton.pn_delivery_update(@impl, state)
-
end
-
-
# Returns the local disposition state for the delivery.
-
#
-
# @return [Disposition] The local disposition state.
-
#
-
1
def local_state
-
Cproton.pn_delivery_local_state(@impl)
-
end
-
-
# Returns the remote disposition state for the delivery.
-
#
-
# @return [Disposition] The remote disposition state.
-
#
-
1
def remote_state
-
Cproton.pn_delivery_remote_state(@impl)
-
end
-
-
# Returns the next delivery on the connection that has pending operations.
-
#
-
# @return [Delivery, nil] The next delivery, or nil if there are none.
-
#
-
# @see Connection#work_head
-
#
-
1
def work_next
-
Delivery.wrap(Cproton.pn_work_next(@impl))
-
end
-
-
# Returns the parent link.
-
#
-
# @return [Link] The parent link.
-
#
-
1
def link
-
Link.wrap(Cproton.pn_delivery_link(@impl))
-
end
-
-
# Returns the parent session.
-
#
-
# @return [Session] The session.
-
#
-
1
def session
-
self.link.session
-
end
-
-
# Returns the parent connection.
-
#
-
# @return [Connection] The connection.
-
#
-
1
def connection
-
self.session.connection
-
end
-
-
# Returns the parent transport.
-
#
-
# @return [Transport] The transport.
-
#
-
1
def transport
-
self.connection.transport
-
end
-
-
# @private
-
1
def local_received?
-
self.local_state == Disposition::RECEIVED
-
end
-
-
# @private
-
1
def remote_received?
-
self.remote_state == Disposition::RECEIVED
-
end
-
-
# @private
-
1
def local_accepted?
-
self.local_state == Disposition::ACCEPTED
-
end
-
-
# @private
-
1
def remote_accepted?
-
self.remote_state == Disposition::ACCEPTED
-
end
-
-
# @private
-
1
def local_rejected?
-
self.local_state == Disposition::REJECTED
-
end
-
-
# @private
-
1
def remote_rejected?
-
self.remote_state == Disposition::REJECTED
-
end
-
-
# @private
-
1
def local_released?
-
self.local_state == Disposition::RELEASED
-
end
-
-
# @private
-
1
def remote_released?
-
self.remote_state == Disposition::RELEASED
-
end
-
-
# @private
-
1
def local_modified?
-
self.local_state == Disposition::MODIFIED
-
end
-
-
# @private
-
1
def remote_modified?
-
self.remote_state == Disposition::MODIFIED
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# Disposition records the current state and/or final outcome of a transfer.
-
#
-
# Every delivery contains both a local and a remote disposition. The local
-
# disposition holds the local state of the delivery, and the remote
-
# disposition holds the *last known* remote state of the delivery.
-
#
-
1
class Disposition
-
-
1
include Util::Constants
-
-
# Indicates the delivery was received.
-
1
self.add_constant(:RECEIVED, Cproton::PN_RECEIVED)
-
# Indicates the delivery was accepted.
-
1
self.add_constant(:ACCEPTED, Cproton::PN_ACCEPTED)
-
# Indicates the delivery was rejected.
-
1
self.add_constant(:REJECTED, Cproton::PN_REJECTED)
-
# Indicates the delivery was released.
-
1
self.add_constant(:RELEASED, Cproton::PN_RELEASED)
-
# Indicates the delivery was modified.
-
1
self.add_constant(:MODIFIED, Cproton::PN_MODIFIED)
-
-
# @private
-
1
include Util::Engine
-
-
1
attr_reader :impl
-
-
# @private
-
1
def initialize(impl, local)
-
@impl = impl
-
@local = local
-
@data = nil
-
@condition = nil
-
@annotations = nil
-
end
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_disposition"
-
-
# @!attribute section_number
-
#
-
# @return [Fixnum] The section number of the disposition.
-
#
-
1
proton_accessor :section_number
-
-
# @!attribute section_offset
-
#
-
# @return [Fixnum] The section offset of the disposition.
-
#
-
1
proton_accessor :section_offset
-
-
# @!attribute failed?
-
#
-
# @return [Boolean] The failed flag.
-
#
-
1
proton_accessor :failed, :is_or_get => :is
-
-
# @!attribute undeliverable?
-
#
-
# @return [Boolean] The undeliverable flag.
-
#
-
1
proton_accessor :undeliverable, :is_or_get => :is
-
-
# Sets the data for the disposition.
-
#
-
# @param data [Codec::Data] The data.
-
#
-
# @raise [AttributeError] If the disposition is remote.
-
#
-
1
def data=(data)
-
raise AttributeError.new("data attribute is read-only") unless @local
-
@data = data
-
end
-
-
# Returns the data for the disposition.
-
#
-
# @return [Codec::Data] The data.
-
#
-
1
def data
-
if @local
-
@data
-
else
-
data_to_object(Cproton.pn_disposition_data(@impl))
-
end
-
end
-
-
# Sets the annotations for the disposition.
-
#
-
# @param annotations [Codec::Data] The annotations.
-
#
-
# @raise [AttributeError] If the disposition is remote.
-
#
-
1
def annotations=(annotations)
-
raise AttributeError.new("annotations attribute is read-only") unless @local
-
@annotations = annotations
-
end
-
-
# Returns the annotations for the disposition.
-
#
-
# @return [Codec::Data] The annotations.
-
#
-
1
def annotations
-
if @local
-
@annotations
-
else
-
data_to_object(Cproton.pn_disposition_annotations(@impl))
-
end
-
end
-
-
# Sets the condition for the disposition.
-
#
-
# @param condition [Codec::Data] The condition.
-
#
-
# @raise [AttributeError] If the disposition is remote.
-
#
-
1
def condition=(condition)
-
raise AttributeError.new("condition attribute is read-only") unless @local
-
@condition = condition
-
end
-
-
# Returns the condition of the disposition.
-
#
-
# @return [Codec::Data] The condition of the disposition.
-
#
-
1
def condition
-
if @local
-
@condition
-
else
-
condition_to_object(Cproton.pn_disposition_condition(@impl))
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# The base for both Sender and Receiver, providing common functionality
-
# between both ends.
-
#
-
# A Link has a single parent Qpid::Proton::Session instance.
-
#
-
1
class Link < Endpoint
-
-
# The sender will send all deliveries initially unsettled.
-
1
SND_UNSETTLED = Cproton::PN_SND_UNSETTLED
-
# The sender will send all deliveries settled to the receiver.
-
1
SND_SETTLED = Cproton::PN_SND_SETTLED
-
# The sender may send a mixture of settled and unsettled deliveries.
-
1
SND_MIXED = Cproton::PN_SND_MIXED
-
-
# The receiver will settle deliveries regardless of what the sender does.
-
1
RCV_FIRST = Cproton::PN_RCV_FIRST
-
# The receiver will only settle deliveries after the sender settles.
-
1
RCV_SECOND = Cproton::PN_RCV_SECOND
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_link"
-
-
# @!attribute [r] state
-
#
-
# Returns the endpoint state flags.
-
#
-
1
proton_caller :state
-
-
# @!method open
-
#
-
# Opens the link. Once this operation has completed, the state flag will be
-
# set.
-
#
-
# @see Endpoint::LOCAL_ACTIVE
-
1
proton_caller :open
-
-
# @!method close
-
#
-
# Closes the link.
-
#
-
# Once this operation has completed, the state flag will be set.
-
# This may be called without first calling #open, which is the equivalent to
-
# calling #open and then #close.
-
#
-
# @see Endpoint::LOCAL_CLOSED
-
1
proton_caller :close
-
-
# @!method detach
-
#
-
# Detaches the link.
-
1
proton_caller :detach
-
-
# Advance the current delivery to the next on the link.
-
#
-
# For sending links, this operation is used to finish sending message data
-
# for the current outgoing delivery and move on to the next outgoing
-
# delivery (if any).
-
#
-
# For receiving links, this operatoin is used to finish accessing message
-
# data from the current incoming delivery and move on to the next incoming
-
# delivery (if any).
-
#
-
# @return [Boolean] True if the current delivery was changed.
-
#
-
# @see #current
-
#
-
1
proton_caller :advance
-
-
1
proton_caller :unsettled
-
-
# @!attribute [r] credit
-
#
-
# Returns the credit balance for a link.
-
#
-
# Links use a credit based flow control scheme. Every receiver maintains a
-
# credit balance that corresponds to the number of deliveries that the
-
# receiver can accept at any given moment.
-
#
-
# As more capacity becomes available at the receiver, it adds credit to this
-
# balance and communicates the new balance to the sender. Whenever a
-
# delivery is sent/received, the credit balance maintained by the link is
-
# decremented by one.
-
#
-
# Once the credit balance at the sender reaches zero, the sender must pause
-
# sending until more credit is obtained from the receiver.
-
#
-
# NOte that a sending link may still be used to send deliveries eve if
-
# credit reaches zero. However those deliveries will end up being buffer by
-
# the link until enough credit is obtained from the receiver to send them
-
# over the wire. In this case the balance reported will go negative.
-
#
-
# @return [Fixnum] The credit balance.
-
#
-
# @see #flow
-
#
-
1
proton_caller :credit
-
-
# @!attribute [r] remote_credit
-
#
-
# Returns the remote view of the credit.
-
#
-
# The remote view of the credit for a link differs from the local view of
-
# credit for a link by the number of queued deliveries. In other words,
-
# remote credit is defined as credit - queued.
-
#
-
# @see #queued
-
# @see #credit
-
#
-
# @return [Fixnum] The remove view of the credit.
-
#
-
1
proton_caller :remote_credit
-
-
# @!attribute [r] available
-
#
-
# Returns the available deliveries hint for a link.
-
#
-
# The available count for a link provides a hint as to the number of
-
# deliveries that might be able to be sent if sufficient credit were issued
-
# by the receiving link endpoint.
-
#
-
# @return [Fixnum] The available deliveries hint.
-
#
-
# @see Sender#offered
-
#
-
1
proton_caller :available
-
-
# @!attribute [r] queued
-
#
-
# Returns the number of queued deliveries for a link.
-
#
-
# Links may queue deliveries for a number of reasons. For example, there may
-
# be insufficient credit to send them to the receiver, or they simply may
-
# not have yet had a chance to be written to the wire.
-
#
-
# @return [Fixnum] The number of queued deliveries.
-
#
-
# @see #credit
-
#
-
1
proton_caller :queued
-
-
# @!attribute [r] name
-
#
-
# Returns the name of the link.
-
#
-
# @return [String] The name.
-
#
-
1
proton_caller :name
-
-
# @!attribute [r] sender?
-
#
-
# Returns if the link is a sender.
-
#
-
# @return [Boolean] True if the link is a sender.
-
#
-
1
proton_reader :sender, :is_or_get => :is
-
-
# @!attribute [r] receiver?
-
#
-
# Returns if the link is a receiver.
-
#
-
# @return [Boolean] True if the link is a receiver.
-
#
-
1
proton_reader :receiver, :is_or_get => :is
-
-
# @private
-
1
proton_reader :attachments
-
-
# Drains excess credit.
-
#
-
# When a link is in drain mode, the sender must use all excess credit
-
# immediately and release any excess credit back to the receiver if there
-
# are no deliveries available to send.
-
#
-
# When invoked on a Sender that is in drain mode, this operation will
-
# release all excess credit back to the receiver and return the number of
-
# credits released back to the sender. If the link is not in drain mode,
-
# this operation is a noop.
-
#
-
# When invoked on a Receiver, this operation will return and reset the
-
# number of credits the sender has released back to it.
-
#
-
# @return [Fixnum] The number of credits drained.
-
#
-
1
proton_caller :drained
-
-
# @private
-
1
include Util::Wrapper
-
-
# @private
-
1
def self.wrap(impl)
-
return nil if impl.nil?
-
-
result = self.fetch_instance(impl, :pn_link_attachments)
-
return result unless result.nil?
-
if Cproton.pn_link_is_sender(impl)
-
return Sender.new(impl)
-
elsif Cproton.pn_link_is_receiver(impl)
-
return Receiver.new(impl)
-
end
-
end
-
-
# @private
-
1
def initialize(impl)
-
@impl = impl
-
self.class.store_instance(self, :pn_link_attachments)
-
end
-
-
# Returns additional error information.
-
#
-
# Whenever a link operation fails (i.e., returns an error code) additional
-
# error details can be obtained from this method. Ther error object that is
-
# returned may also be used to clear the error condition.
-
#
-
# @return [Error] The error.
-
#
-
1
def error
-
Cproton.pn_link_error(@impl)
-
end
-
-
# Returns the next link that matches the given state mask.
-
#
-
# @param state_mask [Fixnum] The state mask.
-
#
-
# @return [Sender, Receiver] The next link.
-
#
-
1
def next(state_mask)
-
return Link.wrap(Cproton.pn_link_next(@impl, state_mask))
-
end
-
-
# Returns the locally defined source terminus.
-
#
-
# @return [Terminus] The terminus
-
1
def source
-
Terminus.new(Cproton.pn_link_source(@impl))
-
end
-
-
# Returns the locally defined target terminus.
-
#
-
# @return [Terminus] The terminus.
-
#
-
1
def target
-
Terminus.new(Cproton.pn_link_target(@impl))
-
end
-
-
# Returns a representation of the remotely defined source terminus.
-
#
-
# @return [Terminus] The terminus.
-
#
-
1
def remote_source
-
Terminus.new(Cproton.pn_link_remote_source(@impl))
-
end
-
-
# Returns a representation of the remotely defined target terminus.
-
#
-
# @return [Terminus] The terminus.
-
#
-
1
def remote_target
-
Terminus.new(Cproton.pn_link_remote_target(@impl))
-
end
-
-
# Returns the parent session.
-
#
-
# @return [Session] The session.
-
#
-
1
def session
-
Session.wrap(Cproton.pn_link_session(@impl))
-
end
-
-
# Returns the parent connection.
-
#
-
# @return [Connection] The connection.
-
#
-
1
def connection
-
self.session.connection
-
end
-
-
# Returns the parent delivery.
-
#
-
# @return [Delivery] The delivery.
-
#
-
1
def delivery(tag)
-
Delivery.new(Cproton.pn_delivery(@impl, tag))
-
end
-
-
# Returns the current delivery.
-
#
-
# Each link maintains a sequence of deliveries in the order they were
-
# created, along with a reference to the *current* delivery. All send and
-
# receive operations on a link take place on the *current* delivery. If a
-
# link has no current delivery, the current delivery is automatically
-
# pointed to the *next* delivery created on the link.
-
#
-
# Once initialized, the current delivery remains the same until it is
-
# changed by advancing, or until it is settled.
-
#
-
# @see #next
-
# @see Delivery#settle
-
#
-
# @return [Delivery] The current delivery.
-
#
-
1
def current
-
Delivery.wrap(Cproton.pn_link_current(@impl))
-
end
-
-
# Sets the local sender settle mode.
-
#
-
# @param mode [Fixnum] The settle mode.
-
#
-
# @see #SND_UNSETTLED
-
# @see #SND_SETTLED
-
# @see #SND_MIXED
-
#
-
1
def snd_settle_mode=(mode)
-
Cproton.pn_link_set_snd_settle_mode(@impl, mode)
-
end
-
-
# Returns the local sender settle mode.
-
#
-
# @return [Fixnum] The local sender settle mode.
-
#
-
# @see #snd_settle_mode
-
#
-
1
def snd_settle_mode
-
Cproton.pn_link_snd_settle_mode(@impl)
-
end
-
-
# Sets the local receiver settle mode.
-
#
-
# @param mode [Fixnum] The settle mode.
-
#
-
# @see #RCV_FIRST
-
# @see #RCV_SECOND
-
#
-
1
def rcv_settle_mode=(mode)
-
Cproton.pn_link_set_rcv_settle_mode(@impl, mode)
-
end
-
-
# Returns the local receiver settle mode.
-
#
-
# @return [Fixnum] The local receiver settle mode.
-
#
-
1
def rcv_settle_mode
-
Cproton.pn_link_rcv_settle_mode(@impl)
-
end
-
-
# @private
-
1
def _local_condition
-
Cproton.pn_link_condition(@impl)
-
end
-
-
# @private
-
1
def _remote_condition
-
Cproton.pn_link_remote_condition(@impl)
-
end
-
-
1
def ==(other)
-
other.respond_to?(:impl) &&
-
(Cproton.pni_address_of(other.impl) == Cproton.pni_address_of(@impl))
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# A Message represents an addressable quantity of data.
-
#
-
# ==== Message Body
-
#
-
# The message body can be set using the #body= method. The message will
-
# then attempt to determine how exactly to encode the content.
-
#
-
# ==== Examples
-
#
-
# To create a message for sending:
-
#
-
# # send a simple text message
-
# msg = Qpid::Proton::Message.new
-
# msg.body = "STATE: update"
-
#
-
# # send a binary chunk of data
-
# data = File.binread("/home/qpid/binfile.tar.gz")
-
# msg = Qpid::Proton::Message.new
-
# msg.body = Qpid::Proton::BinaryString.new(data)
-
#
-
1
class Message
-
-
# @private
-
1
def proton_send(sender, tag = nil)
-
dlv = sender.delivery(tag || sender.delivery_tag)
-
encoded = self.encode
-
sender.stream(encoded)
-
sender.advance
-
dlv.settle if sender.snd_settle_mode == Link::SND_SETTLED
-
return dlv
-
end
-
-
# Decodes a message from supplied AMQP data and returns the number
-
# of bytes consumed.
-
#
-
# ==== Options
-
#
-
# * encoded - the encoded data
-
#
-
1
def decode(encoded)
-
check(Cproton.pn_message_decode(@impl, encoded, encoded.length))
-
-
post_decode
-
end
-
-
1
def post_decode # :nodoc:
-
# decode elements from the message
-
@properties = {}
-
props = Codec::Data.new(Cproton::pn_message_properties(@impl))
-
if props.next
-
@properties = props.type.get(props)
-
end
-
@instructions = nil
-
insts = Codec::Data.new(Cproton::pn_message_instructions(@impl))
-
if insts.next
-
@instructions = insts.type.get(insts)
-
end
-
@annotations = nil
-
annts = Codec::Data.new(Cproton::pn_message_annotations(@impl))
-
if annts.next
-
@annotations = annts.type.get(annts)
-
end
-
@body = nil
-
body = Codec::Data.new(Cproton::pn_message_body(@impl))
-
if body.next
-
@body = body.type.get(body)
-
end
-
end
-
-
# Encodes the message.
-
1
def encode
-
pre_encode
-
size = 16
-
loop do
-
error, data = Cproton::pn_message_encode(@impl, size)
-
if error == Qpid::Proton::Error::OVERFLOW
-
size *= 2
-
else
-
check(error)
-
return data
-
end
-
end
-
end
-
-
1
def pre_encode # :nodoc:
-
# encode elements from the message
-
9
props = Codec::Data.new(Cproton::pn_message_properties(@impl))
-
9
props.clear
-
9
Codec::Mapping.for_class(@properties.class).put(props, @properties) unless @properties.empty?
-
9
insts = Codec::Data.new(Cproton::pn_message_instructions(@impl))
-
9
insts.clear
-
9
if !@instructions.nil?
-
9
mapping = Codec::Mapping.for_class(@instructions.class)
-
9
mapping.put(insts, @instructions)
-
end
-
9
annts = Codec::Data.new(Cproton::pn_message_annotations(@impl))
-
9
annts.clear
-
9
if !@annotations.nil?
-
9
mapping = Codec::Mapping.for_class(@annotations.class)
-
9
mapping.put(annts, @annotations, :keys => :SYMBOL)
-
end
-
9
body = Codec::Data.new(Cproton::pn_message_body(@impl))
-
9
body.clear
-
9
if !@body.nil?
-
9
mapping = Codec::Mapping.for_class(@body.class)
-
9
mapping.put(body, @body)
-
end
-
end
-
-
# Creates a new +Message+ instance.
-
1
def initialize
-
97
@impl = Cproton.pn_message
-
97
ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
-
97
@properties = {}
-
97
@instructions = {}
-
97
@annotations = {}
-
97
@body = nil
-
end
-
-
1
def to_s
-
tmp = Cproton.pn_string("")
-
Cproton.pn_inspect(@impl, tmp)
-
result = Cproton.pn_string_get(tmp)
-
Cproton.pn_free(tmp)
-
return result
-
end
-
-
# Invoked by garbage collection to clean up resources used
-
# by the underlying message implementation.
-
1
def self.finalize!(impl) # :nodoc:
-
97
proc {
-
Cproton.pn_message_free(impl)
-
}
-
end
-
-
# Returns the underlying message implementation.
-
1
def impl # :nodoc:
-
9
@impl
-
end
-
-
# Clears the state of the +Message+. This allows a single instance of
-
# +Message+ to be reused.
-
#
-
1
def clear
-
5
Cproton.pn_message_clear(@impl)
-
5
@properties.clear unless @properties.nil?
-
5
@instructions.clear unless @instructions.nil?
-
5
@annotations.clear unless @annotations.nil?
-
5
@body = nil
-
end
-
-
# Returns the most recent error number.
-
#
-
1
def errno
-
Cproton.pn_message_errno(@impl)
-
end
-
-
# Returns the most recent error message.
-
#
-
1
def error
-
Cproton.pn_error_text(Cproton.pn_message_error(@impl))
-
end
-
-
# Returns whether there is currently an error reported.
-
#
-
1
def error?
-
!Cproton.pn_message_errno(@impl).zero?
-
end
-
-
# Sets the durable flag.
-
#
-
# See ::durable for more details on message durability.
-
#
-
# ==== Options
-
#
-
# * state - the durable state
-
#
-
1
def durable=(state)
-
3
raise TypeError.new("state cannot be nil") if state.nil?
-
2
Cproton.pn_message_set_durable(@impl, state)
-
end
-
-
# Returns the durable property.
-
#
-
# The durable property indicates that the emessage should be held durably
-
# by any intermediaries taking responsibility for the message.
-
#
-
# ==== Examples
-
#
-
# msg = Qpid::Proton::Message.new
-
# msg.durable = true
-
#
-
1
def durable
-
2
Cproton.pn_message_is_durable(@impl)
-
end
-
-
# Sets the priority.
-
#
-
# +NOTE:+ Priority values are limited to the range [0,255].
-
#
-
# ==== Options
-
#
-
# * priority - the priority value
-
#
-
1
def priority=(priority)
-
6
raise TypeError.new("invalid priority: #{priority}") if priority.nil? || !([Float, Fixnum].include?(priority.class))
-
4
raise RangeError.new("priority out of range: #{priority}") if ((priority > 255) || (priority < 0))
-
2
Cproton.pn_message_set_priority(@impl, priority.floor)
-
end
-
-
# Returns the priority.
-
#
-
1
def priority
-
2
Cproton.pn_message_get_priority(@impl)
-
end
-
-
# Sets the time-to-live for the message.
-
#
-
# ==== Options
-
#
-
# * time - the time in milliseconds
-
#
-
1
def ttl=(time)
-
5
raise TypeError.new("invalid ttl: #{time}") if time.nil? || !([Float, Fixnum].include?(time.class))
-
3
raise RangeError.new("time out of range: #{time}") if ((time < 0))
-
2
Cproton.pn_message_set_ttl(@impl, time.floor)
-
end
-
-
# Returns the time-to-live, in milliseconds.
-
#
-
1
def ttl
-
2
Cproton.pn_message_get_ttl(@impl)
-
end
-
-
# Sets whether this is the first time the message was acquired.
-
#
-
# See ::first_acquirer? for more details.
-
#
-
# ==== Options
-
#
-
# * state - true if claiming the message
-
#
-
1
def first_acquirer=(state)
-
4
raise TypeError.new("invalid state: #{state}") if state.nil? || !([TrueClass, FalseClass].include?(state.class))
-
2
Cproton.pn_message_set_first_acquirer(@impl, state)
-
end
-
-
# Sets the delivery count for the message.
-
#
-
# See ::delivery_count for more details.
-
#
-
# ==== Options
-
#
-
# * count - the delivery count
-
#
-
1
def delivery_count=(count)
-
5
raise ::ArgumentError.new("invalid count: #{count}") if count.nil? || !([Float, Fixnum].include?(count.class))
-
3
raise RangeError.new("count out of range: #{count}") if count < 0
-
-
2
Cproton.pn_message_set_delivery_count(@impl, count.floor)
-
end
-
-
# Returns the delivery count for the message.
-
#
-
# This is the number of delivery attempts for the given message.
-
#
-
1
def delivery_count
-
2
Cproton.pn_message_get_delivery_count(@impl)
-
end
-
-
# Returns whether this is the first acquirer.
-
#
-
#
-
1
def first_acquirer?
-
2
Cproton.pn_message_is_first_acquirer(@impl)
-
end
-
-
# Sets the message id.
-
#
-
# ==== Options
-
#
-
# * id = the id
-
#
-
1
def id=(id)
-
2
Cproton.pn_message_set_id(@impl, id)
-
end
-
-
# Returns the message id.
-
#
-
1
def id
-
2
Cproton.pn_message_get_id(@impl)
-
end
-
-
# Sets the user id.
-
#
-
# ==== Options
-
#
-
# * id - the user id
-
#
-
1
def user_id=(id)
-
2
Cproton.pn_message_set_user_id(@impl, id)
-
end
-
-
# Returns the user id.
-
#
-
1
def user_id
-
2
Cproton.pn_message_get_user_id(@impl)
-
end
-
-
# Sets the destination address.
-
#
-
# ==== Options
-
#
-
# * address - the address
-
#
-
1
def address=(address)
-
15
Cproton.pn_message_set_address(@impl, address)
-
end
-
-
# Returns the destination address.
-
#
-
1
def address
-
2
Cproton.pn_message_get_address(@impl)
-
end
-
-
# Sets the subject.
-
#
-
# ==== Options
-
#
-
# * subject - the subject
-
#
-
1
def subject=(subject)
-
3
Cproton.pn_message_set_subject(@impl, subject)
-
end
-
-
# Returns the subject
-
#
-
1
def subject
-
4
Cproton.pn_message_get_subject(@impl)
-
end
-
-
# Sets the reply-to address.
-
#
-
# ==== Options
-
#
-
# * address - the reply-to address
-
#
-
1
def reply_to=(address)
-
2
Cproton.pn_message_set_reply_to(@impl, address)
-
end
-
-
# Returns the reply-to address
-
#
-
1
def reply_to
-
2
Cproton.pn_message_get_reply_to(@impl)
-
end
-
-
# Sets the correlation id.
-
#
-
# ==== Options
-
#
-
# * id - the correlation id
-
#
-
1
def correlation_id=(id)
-
2
Cproton.pn_message_set_correlation_id(@impl, id)
-
end
-
-
# Returns the correlation id.
-
#
-
1
def correlation_id
-
2
Cproton.pn_message_get_correlation_id(@impl)
-
end
-
-
# Sets the content type.
-
#
-
# ==== Options
-
#
-
# * content_type - the content type
-
#
-
1
def content_type=(content_type)
-
3
Cproton.pn_message_set_content_type(@impl, content_type)
-
end
-
-
# Returns the content type
-
#
-
1
def content_type
-
3
Cproton.pn_message_get_content_type(@impl)
-
end
-
-
# Sets the message content.
-
#
-
# *WARNING:* This method has been deprecated. Please use #body= instead to
-
# set the content of a message.
-
#
-
# ==== Options
-
#
-
# * content - the content
-
#
-
1
def content=(content)
-
Cproton.pn_message_load(@impl, content)
-
end
-
-
# Returns the message content.
-
#
-
# *WARNING:* This method has been deprecated. Please use #body instead to
-
# retrieve the content of a message.
-
#
-
1
def content
-
size = 16
-
loop do
-
result = Cproton.pn_message_save(@impl, size)
-
error = result[0]
-
data = result[1]
-
if error == Qpid::Proton::Error::OVERFLOW
-
size = size * 2
-
else
-
check(error)
-
return data
-
end
-
end
-
end
-
-
# Sets the content encoding type.
-
#
-
# ==== Options
-
#
-
# * encoding - the content encoding
-
#
-
1
def content_encoding=(encoding)
-
2
Cproton.pn_message_set_content_encoding(@impl, encoding)
-
end
-
-
# Returns the content encoding type.
-
#
-
1
def content_encoding
-
2
Cproton.pn_message_get_content_encoding(@impl)
-
end
-
-
# Sets the expiration time.
-
#
-
# ==== Options
-
#
-
# * time - the expiry time
-
#
-
1
def expires=(time)
-
4
raise TypeError.new("invalid expiry time: #{time}") if time.nil?
-
3
raise ::ArgumentError.new("expiry time cannot be negative: #{time}") if time < 0
-
2
Cproton.pn_message_set_expiry_time(@impl, time)
-
end
-
-
# Returns the expiration time.
-
#
-
1
def expires
-
2
Cproton.pn_message_get_expiry_time(@impl)
-
end
-
-
# Sets the creation time.
-
#
-
# ==== Options
-
#
-
# * time - the creation time
-
#
-
1
def creation_time=(time)
-
4
raise TypeError.new("invalid time: #{time}") if time.nil?
-
3
raise ::ArgumentError.new("time cannot be negative") if time < 0
-
2
Cproton.pn_message_set_creation_time(@impl, time)
-
end
-
-
# Returns the creation time.
-
#
-
1
def creation_time
-
2
Cproton.pn_message_get_creation_time(@impl)
-
end
-
-
# Sets the group id.
-
#
-
# ==== Options
-
#
-
# * id - the group id
-
#
-
1
def group_id=(id)
-
3
Cproton.pn_message_set_group_id(@impl, id)
-
end
-
-
# Returns the group id.
-
#
-
1
def group_id
-
3
Cproton.pn_message_get_group_id(@impl)
-
end
-
-
# Sets the group sequence number.
-
#
-
# ==== Options
-
#
-
# * seq - the sequence number
-
#
-
1
def group_sequence=(seq)
-
4
raise TypeError.new("invalid seq: #{seq}") if seq.nil?
-
3
Cproton.pn_message_set_group_sequence(@impl, seq)
-
end
-
-
# Returns the group sequence number.
-
#
-
1
def group_sequence
-
3
Cproton.pn_message_get_group_sequence(@impl)
-
end
-
-
# Sets the reply-to group id.
-
#
-
# ==== Options
-
#
-
# * id - the id
-
#
-
1
def reply_to_group_id=(id)
-
3
Cproton.pn_message_set_reply_to_group_id(@impl, id)
-
end
-
-
# Returns the reply-to group id.
-
#
-
1
def reply_to_group_id
-
3
Cproton.pn_message_get_reply_to_group_id(@impl)
-
end
-
-
# Returns the list of property names for associated with this message.
-
#
-
# ==== Examples
-
#
-
# msg.properties.each do |name|
-
# end
-
#
-
1
def properties
-
4
@properties
-
end
-
-
# Replaces the entire set of properties with the specified hash.
-
#
-
1
def properties=(properties)
-
1
@properties = properties
-
end
-
-
# Assigns the value given to the named property.
-
#
-
# ==== Arguments
-
#
-
# * name - the property name
-
# * value - the property value
-
#
-
1
def []=(name, value)
-
7
@properties[name] = value
-
end
-
-
# Retrieves the value for the specified property name. If not found, then
-
# it returns nil.
-
#
-
1
def [](name)
-
7
@properties[name]
-
end
-
-
# Deletes the named property.
-
#
-
1
def delete_property(name)
-
1
@properties.delete(name)
-
end
-
-
# Returns the instructions for this message.
-
#
-
1
def instructions
-
15
@instructions
-
end
-
-
# Assigns instructions to this message.
-
#
-
1
def instructions=(instr)
-
6
@instructions = instr
-
end
-
-
# Returns the annotations for this message.
-
#
-
1
def annotations
-
16
@annotations
-
end
-
-
# Assigns annotations to this message.
-
#
-
1
def annotations=(annotations)
-
5
@annotations = annotations
-
end
-
-
# Returns the body property of the message.
-
#
-
1
def body
-
12
@body
-
end
-
-
# Assigns a new value to the body of the message.
-
#
-
1
def body=(body)
-
23
@body = body
-
end
-
-
1
private
-
-
1
def check(err) # :nodoc:
-
if err < 0
-
raise DataError, "[#{err}]: #{Cproton.pn_message_error(@data)}"
-
else
-
return err
-
end
-
end
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# The receiving endpoint.
-
#
-
# @see Sender
-
#
-
1
class Receiver < Link
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_link"
-
-
# @!attribute drain
-
#
-
# The drain mode.
-
#
-
# If a receiver is in drain mode, then the sending endpoint of a link must
-
# immediately use up all available credit on the link. If this is not
-
# possible, the excess credit must be returned by invoking #drained.
-
#
-
# Only the receiving endpoint can set the drain mode.
-
#
-
# @return [Boolean] True if drain mode is set.
-
#
-
1
proton_accessor :drain
-
-
# @!attribute [r] draining?
-
#
-
# Returns if a link is currently draining.
-
#
-
# A link is defined to be draining when drain mode is set to true and
-
# the sender still has excess credit.
-
#
-
# @return [Boolean] True if the receiver is currently draining.
-
#
-
1
proton_caller :draining?
-
-
# Grants credit for incoming deliveries.
-
#
-
# @param n [Fixnum] The amount to increment the link credit.
-
#
-
1
def flow(n)
-
Cproton.pn_link_flow(@impl, n)
-
end
-
-
# Allows receiving up to the specified limit of data from the remote
-
# endpoint.
-
#
-
# Note that large messages can be streamed across the network, so just
-
# because there is no data to read does not imply the message is complete.
-
#
-
# To ensure the entirety of the message data has been read, either call
-
# #receive until nil is returned, or verify that #partial? is false and
-
# Delivery#pending is 0.
-
#
-
# @param limit [Fixnum] The maximum bytes to receive.
-
#
-
# @return [Fixnum, nil] The number of bytes received, or nil if the end of
-
# the stream was reached.t
-
#
-
# @see Deliver#pending To see how much buffer space is needed.
-
#
-
# @raise [LinkError] If an error occurs.
-
#
-
1
def receive(limit)
-
(n, bytes) = Cproton.pn_link_recv(@impl, limit)
-
return nil if n == Qpid::Proton::Error::EOS
-
raise LinkError.new("[#{n}]: #{Cproton.pn_link_error(@impl)}") if n < 0
-
return bytes
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# The SASL layer is responsible for establishing an authenticated and/or
-
# encrypted tunnel over which AMQP frames are passed between peers.
-
#
-
# The peer acting as the SASL client must provide authentication
-
# credentials.
-
#
-
# The peer acting as the SASL server must provide authentication against the
-
# received credentials.
-
#
-
# @example
-
# # SCENARIO: the remote endpoint has not initialized their connection
-
# # then the local endpoint, acting as a SASL server, decides
-
# # to allow an anonymous connection.
-
# #
-
# # The SASL layer locally assumes the role of server and then
-
# # enables anonymous authentication for the remote endpoint.
-
# #
-
# sasl = @transport.sasl
-
# sasl.server
-
# sasl.mechanisms("ANONYMOUS")
-
# sasl.done(Qpid::Proton::SASL::OK)
-
#
-
1
class SASL
-
-
# Negotation has not completed.
-
1
NONE = Cproton::PN_SASL_NONE
-
# Authentication succeeded.
-
1
OK = Cproton::PN_SASL_OK
-
# Authentication failed due to bad credentials.
-
1
AUTH = Cproton::PN_SASL_AUTH
-
-
# Constructs a new instance for the given transport.
-
#
-
# @param transport [Transport] The transport.
-
#
-
# @private A SASL should be fetched only from its Transport
-
#
-
1
def initialize(transport)
-
@impl = Cproton.pn_sasl(transport.impl)
-
end
-
-
# Sets the acceptable SASL mechanisms.
-
#
-
# @param mechanisms [String] The space-delimited set of mechanisms.
-
#
-
# @example Use anonymous SASL authentication.
-
# @sasl.mechanisms("GSSAPI CRAM-MD5 PLAIN")
-
#
-
1
def mechanisms(mechanisms)
-
Cproton.pn_sasl_mechanisms(@impl, mechanisms)
-
end
-
-
# Returns the outcome of the SASL negotiation.
-
#
-
# @return [Fixnum] The outcome.
-
#
-
1
def outcome
-
outcome = Cprotn.pn_sasl_outcome(@impl)
-
return nil if outcome == NONE
-
outcome
-
end
-
-
# Set the condition of the SASL negotiation.
-
#
-
# @param outcome [Fixnum] The outcome.
-
#
-
1
def done(outcome)
-
Cproton.pn_sasl_done(@impl, outcome)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# Selectable enables accessing the underlying file descriptors
-
# for Messenger.
-
#
-
# @private
-
1
class Selectable
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_selectable"
-
-
# Returns the underlying file descriptor.
-
#
-
# This can be used in conjunction with the IO class.
-
#
-
1
def fileno
-
Cproton.pn_selectable_get_fd(@impl)
-
end
-
-
1
proton_reader :reading, :is_or_get => :is
-
-
1
proton_reader :writing, :is_or_get => :is
-
-
1
proton_caller :readable
-
-
1
proton_caller :writable
-
-
1
proton_caller :expired
-
-
1
proton_accessor :registered, :is_or_get => :is
-
-
1
proton_accessor :terminal, :is_or_get => :is
-
-
1
proton_caller :terminate
-
-
1
proton_caller :release
-
-
# @private
-
1
def self.wrap(impl)
-
return nil if impl.nil?
-
-
self.fetch_instance(impl, :pn_selectable_attachments) || Selectable.new(impl)
-
end
-
-
# @private
-
1
include Util::Wrapper
-
-
# @private
-
1
def initialize(impl)
-
@impl = impl
-
self.class.store_instance(self, :pn_selectable_attachments)
-
end
-
-
1
private
-
-
1
DEFAULT = Object.new
-
-
1
public
-
-
1
def fileno(fd = DEFAULT)
-
if fd == DEFAULT
-
Cproton.pn_selectable_get_fd(@impl)
-
elsif fd.nil?
-
Cproton.pn_selectable_set_fd(@impl, Cproton::PN_INVALID_SOCKET)
-
else
-
Cproton.pn_selectable_set_fd(@impl, fd)
-
end
-
end
-
-
1
def reading=(reading)
-
if reading.nil?
-
reading = false
-
elsif reading == "0"
-
reading = false
-
else
-
reading = true
-
end
-
Cproton.pn_selectable_set_reading(@impl, reading ? true : false)
-
end
-
-
1
def writing=(writing)
-
if writing.nil?
-
writing = false
-
elsif writing == "0"
-
writing = false
-
else
-
writing = true
-
end
-
Cproton.pn_selectable_set_writing(@impl, writing ? true : false)
-
end
-
-
1
def deadline
-
tstamp = Cproton.pn_selectable_get_deadline(@impl)
-
return nil if tstamp.nil?
-
mills_to_sec(tstamp)
-
end
-
-
1
def deadline=(deadline)
-
Cproton.pn_selectable_set_deadline(sec_to_millis(deadline))
-
end
-
-
1
def to_io
-
@io ||= IO.new(fileno)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# The sending endpoint.
-
#
-
# @see Receiver
-
#
-
1
class Sender < Link
-
-
# @private
-
1
include Util::ErrorHandler
-
-
# @private
-
1
can_raise_error :stream, :error_class => Qpid::Proton::LinkError
-
-
# Signals the availability of deliveries.
-
#
-
# @param n [Fixnum] The number of deliveries potentially available.
-
#
-
1
def offered(n)
-
Cproton.pn_link_offered(@impl, n)
-
end
-
-
# Sends the specified data to the remote endpoint.
-
#
-
# @param object [Object] The content to send.
-
# @param tag [Object] The tag
-
#
-
# @return [Fixnum] The number of bytes sent.
-
#
-
1
def send(object, tag = nil)
-
if object.respond_to? :proton_send
-
object.proton_send(self, tag)
-
else
-
stream(object)
-
end
-
end
-
-
# Send the specified bytes as part of the current delivery.
-
#
-
# @param bytes [Array] The bytes to send.
-
#
-
# @return n [Fixnum] The number of bytes sent.
-
#
-
1
def stream(bytes)
-
Cproton.pn_link_send(@impl, bytes)
-
end
-
-
1
def delivery_tag
-
@tag_count ||= 0
-
result = @tag_count.succ
-
@tag_count = result
-
return "#{result}"
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# A session is the parent for senders and receivers.
-
#
-
# A Session has a single parent Qpid::Proton::Connection instance.
-
#
-
1
class Session < Endpoint
-
-
# @private
-
1
include Util::Wrapper
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_session"
-
-
# @!attribute incoming_capacity
-
#
-
# The incoming capacity of a session determines how much incoming message
-
# data the session will buffer. Note that if this value is less than the
-
# negotatied frame size of the transport, it will be rounded up to one full
-
# frame.
-
#
-
# @return [Fixnum] The incoing capacity of the session, measured in bytes.
-
#
-
1
proton_accessor :incoming_capacity
-
-
# @private
-
1
proton_reader :attachments
-
-
# @!attribute [r] outgoing_bytes
-
#
-
# @return [Fixnum] The number of outgoing bytes currently being buffered.
-
#
-
1
proton_caller :outgoing_bytes
-
-
# @!attribute [r] incoming_bytes
-
#
-
# @return [Fixnum] The number of incomign bytes currently being buffered.
-
#
-
1
proton_caller :incoming_bytes
-
-
# @!method open
-
# Opens the session.
-
#
-
# Once this operaton has completed, the state flag is updated.
-
#
-
# @see LOCAL_ACTIVE
-
#
-
1
proton_caller :open
-
-
# @!attribute [r] state
-
#
-
# @return [Fixnum] The endpoint state.
-
#
-
1
proton_caller :state
-
-
# @private
-
1
def self.wrap(impl)
-
return nil if impl.nil?
-
self.fetch_instance(impl, :pn_session_attachments) || Session.new(impl)
-
end
-
-
# @private
-
1
def initialize(impl)
-
@impl = impl
-
self.class.store_instance(self, :pn_session_attachments)
-
end
-
-
# Closed the session.
-
#
-
# Once this operation has completed, the state flag will be set. This may be
-
# called without calling #open, in which case it is the equivalence of
-
# calling #open and then close immediately.
-
#
-
1
def close
-
self._update_condition
-
Cproton.pn_session_close(@impl)
-
end
-
-
# Retrieves the next session from a given connection that matches the
-
# specified state mask.
-
#
-
# When uses with Connection#session_head an application can access all of
-
# the session son the connection that match the given state.
-
#
-
# @param state_mask [Fixnum] The state mask to match.
-
#
-
# @return [Session, nil] The next session if one matches, or nil.
-
#
-
1
def next(state_mask)
-
Session.wrap(Cproton.pn_session_next(@impl, state_mask))
-
end
-
-
# Returns the parent connection.
-
#
-
# @return [Connection] The connection.
-
#
-
1
def connection
-
Connection.wrap(Cproton.pn_session_connection(@impl))
-
end
-
-
# Constructs a new sender.
-
#
-
# Each sender between two AMQP containers must be uniquely named. Note that
-
# this uniqueness cannot be enforced at the library level, so some
-
# consideration should be taken in choosing link names.
-
#
-
# @param name [String] The link name.
-
#
-
# @return [Sender, nil] The sender, or nil if an error occurred.
-
#
-
1
def sender(name)
-
Sender.new(Cproton.pn_sender(@impl, name))
-
end
-
-
# Constructs a new receiver.
-
#
-
# Each receiver between two AMQP containers must be uniquely named. Note
-
# that this uniqueness cannot be enforced at the library level, so some
-
# consideration should be taken in choosing link names.
-
#
-
# @param name [String] The link name.
-
#
-
# @return [Receiver, nil] The receiver, or nil if an error occurred.
-
#
-
1
def receiver(name)
-
Receiver.new(Cproton.pn_receiver(@impl, name))
-
end
-
-
# @private
-
1
def _local_condition
-
Cproton.pn_session_condition(@impl)
-
end
-
-
# @private
-
1
def _remote_condition # :nodoc:
-
Cproton.pn_session_remote_condition(@impl)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# The SSL support for Transport.
-
#
-
# A Transport may be configured ot use SLL for encryption and/or
-
# authentication. A Transport can be configured as either the SSL
-
# client or the server. An SSL client is the party that proctively
-
# establishes a connection to an SSL server. An SSL server is the
-
# party that accepts a connection request from the remote SSL client.
-
#
-
# If either the client or the server needs to identify itself with the
-
# remote node, it must have its SSL certificate configured.
-
#
-
# @see SSLDomain#credentials For setting the SSL certificate.
-
#
-
# If either the client or the server needs to verify the identify of the
-
# remote node, it must have its database of trusted CAs configured.
-
#
-
# @see SSLDomain#trusted_ca_db Setting the CA database.
-
#
-
# An SSL server connection may allow the remote client to connect without
-
# SS (i.e., "in the clear").
-
#
-
# @see SSLDomain#allow_unsecured_client Allowing unsecured clients.
-
#
-
# The level of verification required of the remote may be configured.
-
#
-
# @see SSLDomain#peer_authentication Setting peer authentication.
-
#
-
# Support for SSL client session resume is provided as well.
-
#
-
# @see SSLDomain
-
# @see #resume_status
-
#
-
1
class SSL
-
-
# Session resume state is unkonnwn or not supported.
-
1
RESUME_UNKNOWN = Cproton::PN_SSL_RESUME_UNKNOWN
-
# Session renegotiated and not resumed.
-
1
RESUME_NEW = Cproton::PN_SSL_RESUME_NEW
-
# Session resumed from the previous session.
-
1
RESUME_REUSED = Cproton::PN_SSL_RESUME_REUSED
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_ssl"
-
-
# @private
-
1
include Util::ErrorHandler
-
-
1
can_raise_error :peer_hostname=, :error_class => SSLError
-
-
# Returns whether SSL is supported.
-
#
-
# @return [Boolean] True if SSL support is available.
-
#
-
1
def self.present?
-
Cproton.pn_ssl_present
-
end
-
-
# @private
-
1
def self.create(transport, domain, session_details = nil)
-
result = nil
-
# like python, make sure we're not creating a different SSL
-
# object for a transport with an existing SSL object
-
if transport.ssl?
-
transport.instance_eval { result = @ssl }
-
if ((!domain.nil? && (result.domain != domain)) ||
-
(!session_details.nil? && (result.session_details != session_details)))
-
raise SSLException.new("cannot re-configure existing SSL object")
-
end
-
else
-
impl = Cproton.pn_ssl(transport.impl)
-
session_id = nil
-
session_id = session_details.session_id unless session_details.nil?
-
result = SSL.new(impl, domain, session_details, session_id)
-
end
-
return result
-
end
-
-
1
private
-
-
1
def initialize(impl, domain, session_details, session_id)
-
@impl = impl
-
@domain = domain.impl unless domain.nil?
-
@session_details = session_details
-
@session_id = session_id
-
Cproton.pn_ssl_init(@impl, @domain, @session_id)
-
end
-
-
1
public
-
-
# Returns the cipher name that is currently in used.
-
#
-
# Gets the text description of the cipher that is currently active, or
-
# returns nil if SSL is not active. Note that the cipher in use my change
-
# over time due to renegotiation or other changes to the SSL layer.
-
#
-
# @return [String, nil] The cipher name.
-
#
-
1
def cipher_name
-
rc, name = Cproton.pn_ssl_get_cipher_name(@impl, 128)
-
return name if rc
-
nil
-
end
-
-
# Returns the name of the SSL protocol that is currently active, or
-
# returns nil if SSL is nota ctive. Not that the protocol may change over
-
# time due to renegotation.
-
#
-
# @return [String, nil] The protocol name.
-
#
-
1
def protocol_name
-
rc, name = Cproton.pn_ssl_get_protocol_name(@impl, 128)
-
retur name if rc
-
nil
-
end
-
-
# Checks whether or not the state has resumed.
-
#
-
# Used for client session resume. When called on an active session, it
-
# indicates wehther the state has been resumed from a previous session.
-
#
-
# *NOTE:* This is a best-effort service - there is no guarantee that the
-
# remote server will accept the resumed parameters. The remote server may
-
# choose to ignore these parameters, and request a renegotation instead.
-
#
-
1
def resume_status
-
Cproton.pn_ssl_resume_status(@impl)
-
end
-
-
# Gets the peer hostname.
-
#
-
# @return [String] The peer hostname.
-
1
def peer_hostname
-
(error, name) = Cproton.pn_ssl_get_peer_hostname(@impl, 1024)
-
raise SSLError.new if error < 0
-
return name
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# @private
-
1
class SSLSessionDetails
-
-
1
attr_reader :session_id
-
-
1
def initialize(session_id)
-
@session_id = session_id
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# The top-level object that stores the configuration used by one or more
-
# SSL sessions.
-
#
-
# @see SSL
-
#
-
1
class SSLDomain
-
-
# The local connection endpoint is an SSL client.
-
# @private
-
1
MODE_CLIENT = Cproton::PN_SSL_MODE_CLIENT
-
# The local connection endpoint is an SSL server.
-
# @private
-
1
MODE_SERVER = Cproton::PN_SSL_MODE_SERVER
-
-
# Require the peer to provide a valid identifying certificate.
-
1
VERIFY_PEER = Cproton::PN_SSL_VERIFY_PEER
-
# Do no require a certificate nor a cipher authorization.
-
1
ANONYMOUS_PEER = Cproton::PN_SSL_ANONYMOUS_PEER
-
# Require a valid certficate and matching name.
-
1
VERIFY_PEER_NAME = Cproton::PN_SSL_VERIFY_PEER_NAME
-
-
# @private
-
1
include Util::ErrorHandler
-
-
1
can_raise_error :credentials, :error_class => Qpid::Proton::SSLError
-
1
can_raise_error :trusted_ca_db, :error_class => Qpid::Proton::SSLError
-
1
can_raise_error :peer_authentication, :error_class => Qpid::Proton::SSLError
-
1
can_raise_error :allow_unsecured_client, :error_class => Qpid::Proton::SSLError
-
-
# @private
-
1
attr_reader :impl
-
-
# @private
-
1
def initialize(mode)
-
@impl = Cproton.pn_ssl_domain(mode)
-
raise SSLUnavailable.new if @impl.nil?
-
end
-
-
# Set the certificate that identifies the local node to the remote.
-
#
-
# This certificate establishes the identity for thelocal node for all SSL
-
# sessions created from this domain. It will be sent to the remote if the
-
# remote needs to verify the dientify of this node. This may be used for
-
# both SSL servers and SSL clients (if client authentication is required by
-
# the server).
-
#
-
# *NOTE:* This setting affects only those instances of SSL created *after*
-
# this call returns. SSL objects created before invoking this method will
-
# use the domain's previous settings.
-
#
-
# @param cert_file [String] The filename containing the identify
-
# certificate. For OpenSSL users, this is a PEM file. For Windows SChannel
-
# users, this is the PKCS\#12 file or system store.
-
# @param key_file [String] An option key to access the identifying
-
# certificate. For OpenSSL users, this is an optional PEM file containing
-
# the private key used to sign the certificate. For Windows SChannel users,
-
# this is the friendly name of the self-identifying certficate if there are
-
# multiple certfificates in the store.
-
# @param password [String] The password used to sign the key, or *nil* if
-
# the key is not protected.
-
#
-
# @raise [SSLError] If an error occurs.
-
#
-
1
def credentials(cert_file, key_file, password)
-
Cproton.pn_ssl_domain_set_credentials(@impl,
-
cert_file, key_file, password)
-
end
-
-
# Configures the set of trusted CA certificates used by this domain to
-
# verify peers.
-
#
-
# If the local SSL client/server needs to verify the identify of the remote,
-
# it must validate the signature of the remote's certificate. This function
-
# sets the database of trusted CAs that will be used to verify the signature
-
# of the remote's certificate.
-
#
-
# *NOTE:# This setting affects only those SSL instances created *after* this
-
# call returns. SSL objects created before invoking this method will use the
-
# domain's previous setting.
-
#
-
# @param certificate_db [String] The filename for the databse of trusted
-
# CAs, used to authenticate the peer.
-
#
-
# @raise [SSLError] If an error occurs.
-
#
-
1
def trusted_ca_db(certificate_db)
-
Cproton.pn_ssl_domain_set_trusted_ca_db(@impl, certificate_db)
-
end
-
-
# Configures the level of verification used on the peer certificate.
-
#
-
# This method congtrols how the peer's certificate is validated, if at all.
-
# By default, neither servers nor clients attempt to verify their peers
-
# (*ANONYMOUS_PEER*). Once certficates and trusted CAs are configured, peer
-
# verification can be enabled.
-
#
-
# *NOTE:* In order to verify a peer, a trusted CA must be configured.
-
#
-
# *NOTE:* Servers must provide their own certficate when verifying a peer.
-
#
-
# *NOTE:* This setting affects only those SSL instances created after this
-
# call returns. SSL instances created before invoking this method will use
-
# the domain's previous setting.
-
#
-
# @param verify_mode [Fixnum] The level of validation to apply to the peer.
-
# @param trusted_CAs [String] The path to a database of trusted CAs that
-
# the server will advertise to the peer client if the server has been
-
# configured to verify its peer.
-
#
-
# @see VERIFY_PEER
-
# @see ANONYMOUS_PEER
-
# @see VERIFY_PEER_NAME
-
#
-
# @raise [SSLError] If an error occurs.
-
#
-
1
def peer_authentication(verify_mode, trusted_CAs = nil)
-
Cproton.pn_ssl_domain_set_peer_authentication(@impl,
-
verify_mode, trusted_CAs)
-
end
-
-
# Permit a server to accept connection requests from non-SSL clients.
-
#
-
# This configures the server to "sniff" the incomfing client data stream and
-
# dynamically determine whether SSL/TLS is being used. This option is
-
# disabled by default: only clients using SSL/TLS are accepted by default.
-
#
-
# @raise [SSLError] If an error occurs.
-
#
-
1
def allow_unsecured_client
-
Cproton.pn_ssl_domain_allow_unsecured_client(@impl);
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# Represents an endpoint for an AMQP connection..
-
#
-
# An AMQP terminus acts as either a source or a target for messages,
-
# but never as both. Every Link is associated iwth both a source and
-
# a target Terminus that is negotiated during link establishment.
-
#
-
# A terminus is composed of an AMQP address along with a number of
-
# other properties defining the quality of service and behavior of
-
# the Link.
-
#
-
1
class Terminus
-
-
# Indicates a non-existent source or target terminus.
-
1
UNSPECIFIED = Cproton::PN_UNSPECIFIED
-
# Indicates a source for messages.
-
1
SOURCE = Cproton::PN_SOURCE
-
# Indicates a target for messages.
-
1
TARGET = Cproton::PN_TARGET
-
# A special target identifying a transaction coordinator.
-
1
COORDINATOR = Cproton::PN_COORDINATOR
-
-
# The terminus is orphaned when the parent link is closed.
-
1
EXPIRE_WITH_LINK = Cproton::PN_EXPIRE_WITH_LINK
-
# The terminus is orphaned whent he parent sessio is closed.
-
1
EXPIRE_WITH_SESSION = Cproton::PN_EXPIRE_WITH_SESSION
-
# The terminus is orphaned when the parent connection is closed.
-
1
EXPIRE_WITH_CONNECTION = Cproton::PN_EXPIRE_WITH_CONNECTION
-
# The terminus is never considered orphaned.
-
1
EXPIRE_NEVER = Cproton::PN_EXPIRE_NEVER
-
-
# Indicates a non-durable Terminus.
-
1
NONDURABLE = Cproton::PN_NONDURABLE
-
# Indicates a Terminus with durably held configuration, but
-
# not the delivery state.
-
1
CONFIGURATION = Cproton::PN_CONFIGURATION
-
# Indicates a Terminus with both durably held configuration and
-
# durably held delivery states.
-
1
DELIVERIES = Cproton::PN_DELIVERIES
-
-
# The behavior is defined by the nod.e
-
1
DIST_MODE_UNSPECIFIED = Cproton::PN_DIST_MODE_UNSPECIFIED
-
# The receiver gets all messages.
-
1
DIST_MODE_COPY = Cproton::PN_DIST_MODE_COPY
-
# The receives compete for messages.
-
1
DIST_MODE_MOVE = Cproton::PN_DIST_MODE_MOVE
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_terminus"
-
-
# @!attribute type
-
#
-
# @return [Fixnum] The terminus type.
-
#
-
# @see SOURCE
-
# @see TARGET
-
# @see COORDINATOR
-
#
-
1
proton_accessor :type
-
-
# @!attribute address
-
#
-
# @return [String] The terminus address.
-
#
-
1
proton_accessor :address
-
-
# @!attribute durability
-
#
-
# @return [Fixnum] The durability mode of the terminus.
-
#
-
# @see NONDURABLE
-
# @see CONFIGURATION
-
# @see DELIVERIES
-
#
-
1
proton_accessor :durability
-
-
# @!attribute expiry_policy
-
#
-
# @return [Fixnum] The expiry policy.
-
#
-
# @see EXPIRE_WITH_LINK
-
# @see EXPIRE_WITH_SESSION
-
# @see EXPIRE_WITH_CONNECTION
-
# @see EXPIRE_NEVER
-
#
-
1
proton_accessor :expiry_policy
-
-
# @!attribute timeout
-
#
-
# @return [Fixnum] The timeout period.
-
#
-
1
proton_accessor :timeout
-
-
# @!attribute dynamic?
-
#
-
# @return [Boolean] True if the terminus is dynamic.
-
#
-
1
proton_accessor :dynamic, :is_or_get => :is
-
-
# @!attribute distribution_mode
-
#
-
# @return [Fixnum] The distribution mode.
-
#
-
# @see DIST_MODE_UNSPECIFIED
-
# @see DIST_MODE_COPY
-
# @see DIST_MODE_MOVE
-
#
-
1
proton_accessor :distribution_mode
-
-
# @private
-
1
include Util::ErrorHandler
-
-
1
can_raise_error [:type=, :address=, :durability=, :expiry_policy=,
-
:timeout=, :dynamic=, :distribution_mode=, :copy],
-
:error_class => Qpid::Proton::LinkError
-
-
# @private
-
1
attr_reader :impl
-
-
# @private
-
1
def initialize(impl)
-
@impl = impl
-
end
-
-
# Access and modify the AMQP properties data for the Terminus.
-
#
-
# This operation will return an instance of Data that is valid until the
-
# Terminus is freed due to its parent being freed. Any data contained in
-
# the object will be sent as the AMQP properties for the parent Terminus
-
# instance.
-
#
-
# NOTE: this MUST take the form of a symbol keyed map to be valid.
-
#
-
# @return [Data] The terminus properties.
-
#
-
1
def properties
-
Data.new(Cproton.pn_terminus_properties(@impl))
-
end
-
-
# Access and modify the AMQP capabilities data for the Terminus.
-
#
-
# This operation will return an instance of Data that is valid until the
-
# Terminus is freed due to its parent being freed. Any data contained in
-
# the object will be sent as the AMQP properties for the parent Terminus
-
# instance.
-
#
-
# NOTE: this MUST take the form of a symbol keyed map to be valid.
-
#
-
# @return [Data] The terminus capabilities.
-
#
-
1
def capabilities
-
Data.new(Cproton.pn_terminus_capabilities(@impl))
-
end
-
-
# Access and modify the AMQP outcomes for the Terminus.
-
#
-
# This operaiton will return an instance of Data that is valid until the
-
# Terminus is freed due to its parent being freed. Any data contained in
-
# the object will be sent as the AMQP properties for the parent Terminus
-
# instance.
-
#
-
# NOTE: this MUST take the form of a symbol keyed map to be valid.
-
#
-
# @return [Data] The terminus outcomes.
-
#
-
1
def outcomes
-
Data.new(Cproton.pn_terminus_outcomes(@impl))
-
end
-
-
# Access and modify the AMQP filter set for the Terminus.
-
#
-
# This operation will return an instance of Data that is valid until the
-
# Terminus is freed due to its parent being freed. Any data contained in
-
# the object will be sent as the AMQP properties for the parent Terminus
-
# instance.
-
#
-
# NOTE: this MUST take the form of a symbol keyed map to be valid.
-
#
-
# @return [Data] The terminus filter.
-
#
-
1
def filter
-
Data.new(Cproton.pn_terminus_filter(@impl))
-
end
-
-
# Copy another Terminus into this instance.
-
#
-
# @param source [Terminus] The source instance.
-
#
-
1
def copy(source)
-
Cproton.pn_terminus_copy(@impl,source.impl)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
# A transport is used by a connection to interface with the network.
-
#
-
# A transport is associated with, at most, one Connection.
-
#
-
# == Client And Server Mode
-
#
-
# Initially, a transport is configured to be a client tranpsort. It can be
-
# configured to act as a server when it is created.
-
#
-
# A client transport initiates outgoing connections.
-
#
-
# A client transport must be configured with the protocol layers to use and
-
# cannot configure itself automatically.
-
#
-
# A server transport accepts incoming connections. It can automatically
-
# configure itself to include the various protocol layers depending on the
-
# incoming protocol headers.
-
#
-
# == Tracing Data
-
#
-
# Data can be traced into and out of the transport programmatically by setting
-
# the #trace level to one of the defined trace values (TRACE_RAW, TRACE_FRM or
-
# TRACE_DRV). Tracing can also be turned off programmatically by setting the
-
# #trace level to TRACE_OFF.
-
#
-
# @example
-
#
-
# # turns on frame tracing
-
# @transport.trace = Qpid::Proton::Transport::TRACE_FRM
-
#
-
# # ... do something where the frames are of interest, such as debugging
-
#
-
# # turn tracing off again
-
# @transport.trace = Qpid::Proton::Transport::TRACE_NONE
-
#
-
# Tracing can also be enabled from the command line by defining the similarly
-
# named environment variable before starting a Proton application:
-
#
-
# @example
-
#
-
# # enable tracing from the command line
-
# PN_TRACE_FRM=1 ruby my_proton_app.rb
-
#
-
1
class Transport
-
-
# @private
-
1
include Util::Engine
-
-
# Turn logging off entirely.
-
1
TRACE_OFF = Cproton::PN_TRACE_OFF
-
# Log raw binary data into/out of the transport.
-
1
TRACE_RAW = Cproton::PN_TRACE_RAW
-
# Log frames into/out of the transport.
-
1
TRACE_FRM = Cproton::PN_TRACE_FRM
-
# Log driver related events; i.e., initialization, end of stream, etc.
-
1
TRACE_DRV = Cproton::PN_TRACE_DRV
-
-
# @private
-
1
CLIENT = 1
-
# @private
-
1
SERVER = 2
-
-
# @private
-
1
include Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_transport"
-
-
# @!attribute channel_max
-
#
-
# @return [Fixnum] The maximum allowed channel.
-
#
-
1
proton_accessor :channel_max
-
-
# @!attribute [r] remote_channel_max
-
#
-
# @return [Fixnum] The maximum allowed channel of a transport's remote peer.
-
#
-
1
proton_caller :remote_channel_max
-
-
# @!attribute max_frame_size
-
#
-
# @return [Fixnum] The maximum frame size.
-
#
-
1
proton_accessor :max_frame_size
-
-
# @!attribute [r] remote_max_frame_size
-
#
-
# @return [Fixnum] The maximum frame size of the transport's remote peer.
-
#
-
1
proton_reader :remote_max_frame_size
-
-
# @!attribute idle_timeout
-
#
-
# @return [Fixnum] The idle timeout.
-
#
-
1
proton_accessor :idle_timeout
-
-
# @!attribute [r] remote_idle_timeout
-
#
-
# @return [Fixnum] The idle timeout for the transport's remote peer.
-
#
-
1
proton_accessor :remote_idle_timeout
-
-
# @!attribute [r] capacity
-
#
-
# If the engine is in an exception state such as encountering an error
-
# condition or reaching the end of stream state, a negative value will
-
# be returned indicating the condition.
-
#
-
# If an error is indicated, further deteails can be obtained from
-
# #error.
-
#
-
# Calls to #process may alter the value of this value. See #process for
-
# more details
-
#
-
# @return [Fixnum] The amount of free space for input following the
-
# transport's tail pointer.
-
#
-
1
proton_caller :capacity
-
-
# @!attribute [r] head
-
#
-
# This referneces queued output data. It reports the bytes of output data.
-
#
-
# Calls to #pop may alter this attribute, and any data it references.
-
#
-
# @return [String] The transport's head pointer.
-
#
-
1
proton_caller :head
-
-
# @!attribute [r] tail
-
#
-
# The amount of free space following this data is reported by #capacity.
-
#
-
# Calls to #process may alter the value of this attribute.
-
#
-
# @return [String] The transport's tail pointer.
-
#
-
1
proton_caller :tail
-
-
# @!attribute [r] pending
-
#
-
# If the ending is in an exceptional state, such as encountering an error
-
# condition or reachign the end of the stream state, a negative value will
-
# be returned indicating the condition.
-
#
-
# If an error is indicated, further details can be obtained from #error.
-
#
-
# Calls to #pop may alter the value of this pointer as well.
-
#
-
# @return [Fixnum] The number of pending output bytes following the header
-
# pointer.
-
#
-
# @raise [TransportError] If any error other than an end of stream occurs.
-
#
-
1
proton_caller :pending
-
-
# @!attribute [r] closed?
-
#
-
# A transport is defined to be closed when both the tail and the head are
-
# closed. In other words, when both #capacity < 0 and #pending < 0.
-
#
-
# @return [Boolean] Returns true if the tranpsort is closed.
-
#
-
1
proton_caller :closed?
-
-
# @!attribute [r] frames_output
-
#
-
# @return [Fixnum] The number of frames output by a transport.
-
#
-
1
proton_reader :frames_output
-
-
# @!attribute [r] frames_input
-
#
-
# @return [Fixnum] The number of frames input by a transport.
-
#
-
1
proton_reader :frames_input
-
-
# @private
-
1
include Util::ErrorHandler
-
-
1
can_raise_error :process, :error_class => TransportError
-
1
can_raise_error :close_tail, :error_class => TransportError
-
1
can_raise_error :pending, :error_class => TransportError, :below => Error::EOS
-
1
can_raise_error :close_head, :error_class => TransportError
-
-
# @private
-
1
include Util::Wrapper
-
-
# @private
-
1
def self.wrap(impl)
-
return nil if impl.nil?
-
-
self.fetch_instance(impl, :pn_transport_attachments) || Transport.new(nil, impl)
-
end
-
-
# Creates a new transport instance.
-
#
-
# @param mode [Fixnum] The transport mode, either CLIENT or SERVER
-
# @param impl [pn_transport_t] Should not be used.
-
#
-
# @raise [TransportError] If the mode is invalid.
-
#
-
1
def initialize(mode = nil, impl = Cproton.pn_transport)
-
@impl = impl
-
if mode == SERVER
-
Cproton.pn_transport_set_server(@impl)
-
elsif (!mode.nil? && mode != CLIENT)
-
raise TransportError.new("cannot create transport for mode: #{mode}")
-
end
-
self.class.store_instance(self, :pn_transport_attachments)
-
end
-
-
# Returns whether the transport has any buffered data.
-
#
-
# @return [Boolean] True if the transport has no buffered data.
-
#
-
1
def quiesced?
-
Cproton.pn_transport_quiesced(@impl)
-
end
-
-
# Returns additional information about the condition of the transport.
-
#
-
# When a TRANSPORT_ERROR event occurs, this operaiton can be used to
-
# access the details of the error condition.
-
#
-
# The object returned is valid until the Transport is discarded.
-
#
-
1
def condition
-
condition_to_object Cproton.pn_transport_condition(@impl)
-
end
-
-
# Binds to the given connection.
-
#
-
# @param connection [Connection] The connection.
-
#
-
1
def bind(connection)
-
Cproton.pn_transport_bind(@impl, connection.impl)
-
end
-
-
# Unbinds from the previous connection.
-
#
-
1
def unbind
-
Cproton.pn_transport_unbind(@impl)
-
end
-
-
# Updates the transports trace flags.
-
#
-
# @param level [Fixnum] The trace level.
-
#
-
# @see TRACE_OFF
-
# @see TRACE_RAW
-
# @see TRACE_FRM
-
# @see TRACE_DRV
-
#
-
1
def trace(level)
-
Cproton.pn_transport_trace(@impl, level)
-
end
-
-
# Return the AMQP connection associated with the transport.
-
#
-
# @return [Connection, nil] The bound connection, or nil.
-
#
-
1
def connection
-
Connection.wrap(Cproton.pn_transport_connection(@impl))
-
end
-
-
# Log a message to the transport's logging mechanism.
-
#
-
# This can be using in a debugging scenario as the message will be
-
# prepended with the transport's identifier.
-
#
-
# @param message [String] The message to be logged.
-
#
-
1
def log(message)
-
Cproton.pn_transport_log(@impl, message)
-
end
-
-
# Pushes the supplied bytes into the tail of the transport.
-
#
-
# @param data [String] The bytes to be pushed.
-
#
-
# @return [Fixnum] The number of bytes pushed.
-
#
-
1
def push(data)
-
Cproton.pn_transport_push(@impl, data, data.length)
-
end
-
-
# Process input data following the tail pointer.
-
#
-
# Calling this function will cause the transport to consume the specified
-
# number of bytes of input occupying the free space following the tail
-
# pointer. It may also change the value for #tail, as well as the amount of
-
# free space reported by #capacity.
-
#
-
# @param size [Fixnum] The number of bytes to process.
-
#
-
# @raise [TransportError] If an error occurs.
-
#
-
1
def process(size)
-
Cproton.pn_transport_process(@impl, size)
-
end
-
-
# Indicate that the input has reached EOS (end of stream).
-
#
-
# This tells the transport that no more input will be forthcoming.
-
#
-
# @raise [TransportError] If an error occurs.
-
#
-
1
def close_tail
-
Cproton.pn_transport_close_tail(@impl)
-
end
-
-
# Returns the specified number of bytes from the transport's buffers.
-
#
-
# @param size [Fixnum] The number of bytes to return.
-
#
-
# @return [String] The data peeked.
-
#
-
# @raise [TransportError] If an error occurs.
-
#
-
1
def peek(size)
-
cd, out = Cproton.pn_transport_peek(@impl, size)
-
return nil if cd == Qpid::Proton::Error::EOS
-
raise TransportError.new if cd < -1
-
out
-
end
-
-
# Removes the specified number of bytes from the pending output queue
-
# following the transport's head pointer.
-
#
-
# @param size [Fixnum] The number of bytes to remove.
-
#
-
1
def pop(size)
-
Cproton.pn_transport_pop(@impl, size)
-
end
-
-
# Indicate that the output has closed.
-
#
-
# Tells the transport that no more output will be popped.
-
#
-
# @raise [TransportError] If an error occurs.
-
#
-
1
def close_head
-
Cproton.pn_transport_close_head(@impl)
-
end
-
-
# Process any pending transport timer events.
-
#
-
# This method should be called after all pending input has been
-
# processed by the transport (see #input), and before generating
-
# output (see #output).
-
#
-
# It returns the deadline for the next pending timer event, if any
-
# art present.
-
#
-
# @param now [Time] The timestamp.
-
#
-
# @return [Fixnum] If non-zero, the expiration time of the next pending
-
# timer event for the transport. The caller must invoke #tick again at
-
# least once at or before this deadline occurs.
-
#
-
1
def tick(now)
-
Cproton.pn_transport_tick(@impl, now)
-
end
-
-
1
def sasl
-
SASL.new(self)
-
end
-
-
# Creates, or returns an existing, SSL object for the transport.
-
#
-
# @param domain [SSLDomain] The SSL domain.
-
# @param session_details [SSLDetails] The SSL session details.
-
#
-
# @return [SSL] The SSL object.
-
#
-
1
def ssl(domain = nil, session_details = nil)
-
@ssl ||= SSL.create(self, domain, session_details) if @ssl.nil?
-
end
-
-
# @private
-
1
def ssl?
-
!@ssl.nil?
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
1
class URL
-
-
1
attr_reader :scheme
-
1
attr_reader :username
-
1
attr_reader :password
-
1
attr_reader :host
-
1
attr_reader :port
-
1
attr_reader :path
-
-
1
def initialize(url = nil, options = {})
-
options[:defaults] = true
-
-
if url
-
@url = Cproton.pn_url_parse(url)
-
if @url.nil?
-
raise ::ArgumentError.new("invalid url: #{url}")
-
end
-
else
-
@url = Cproton.pn_url
-
end
-
@scheme = Cproton.pn_url_get_scheme(@url)
-
@username = Cproton.pn_url_get_username(@url)
-
@password = Cproton.pn_url_get_password(@url)
-
@host = Cproton.pn_url_get_host(@url)
-
@port = Cproton.pn_url_get_port(@url)
-
@path = Cproton.pn_url_get_path(@url)
-
defaults
-
end
-
-
1
def port=(port)
-
if port.nil?
-
Cproton.pn_url_set_port(@url, nil)
-
else
-
Cproton.pn_url_set_port(@url, port)
-
end
-
end
-
-
1
def port
-
Cproton.pn_url_get_port(@url).to_i
-
end
-
-
1
def to_s
-
"#{@scheme}://#{@username.nil? ? '' : @username}#{@password.nil? ? '' : '@' + @password + ':'}#{@host}:#{@port}/#{@path}"
-
end
-
-
1
private
-
-
1
def defaults
-
@scheme = @scheme || "ampq"
-
@host = @host || "0.0.0.0"
-
@port = @port || 5672
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Event
-
-
# 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
-
#
-
1
class Collector
-
-
# @private
-
1
attr_reader :impl
-
-
# Creates a new Collector.
-
#
-
1
def initialize
-
@impl = Cproton.pn_collector
-
ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
-
end
-
-
# @private
-
1
def self.finalize!(impl)
-
proc {
-
Cproton.pn_collector_free(impl)
-
}
-
end
-
-
# 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.
-
#
-
1
def release
-
Cproton.pn_collector_release(@impl)
-
end
-
-
# 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
-
#
-
1
def put(context, event_type)
-
Cproton.pn_collector_put(@impl, Cproton.pn_rb2void(context), event_type.type_code)
-
end
-
-
# 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
-
#
-
1
def peek
-
Event.wrap(Cproton.pn_collector_peek(@impl))
-
end
-
-
# Clear the head event.
-
#
-
# @return [Boolean] true if an event was removed
-
#
-
# @see #release
-
# @see #peek
-
#
-
1
def pop
-
Cproton.pn_collector_pop(@impl)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton
-
-
1
module Event
-
-
# @private
-
1
def self.event_type(const_name, method_name = nil) # :nodoc:
-
41
unless Cproton.const_defined?(const_name)
-
raise RuntimeError.new("no such constant: #{const_name}")
-
end
-
-
41
const_value = Cproton.const_get(const_name)
-
41
method_name = "on_#{const_name.to_s[3..-1]}".downcase if method_name.nil?
-
-
41
EventType.new(const_value, method_name)
-
end
-
-
# Defined as a programming convenience. No even of this type will ever
-
# be generated.
-
1
NONE = event_type(:PN_EVENT_NONE)
-
-
# A reactor has been started.
-
1
REACTOR_INIT = event_type(:PN_REACTOR_INIT)
-
# A reactor has no more events to process.
-
1
REACTOR_QUIESCED = event_type(:PN_REACTOR_QUIESCED)
-
# A reactor has been stopred.
-
1
REACTOR_FINAL = event_type(:PN_REACTOR_FINAL)
-
-
# A timer event has occurred.
-
1
TIMER_TASK = event_type(:PN_TIMER_TASK)
-
-
# A connection has been created. This is the first even that will ever
-
# be issued for a connection.
-
1
CONNECTION_INIT = event_type(:PN_CONNECTION_INIT)
-
# A conneciton has been bound toa transport.
-
1
CONNECTION_BOUND = event_type(:PN_CONNECTION_BOUND)
-
# A connection has been unbound from its transport.
-
1
CONNECTION_UNBOUND = event_type(:PN_CONNECTION_UNBOUND)
-
# A local connection endpoint has been opened.
-
1
CONNECTION_LOCAL_OPEN = event_type(:PN_CONNECTION_LOCAL_OPEN)
-
# A local connection endpoint has been closed.
-
1
CONNECTION_LOCAL_CLOSE = event_type(:PN_CONNECTION_LOCAL_CLOSE)
-
# A remote endpoint has opened its connection.
-
1
CONNECTION_REMOTE_OPEN = event_type(:PN_CONNECTION_REMOTE_OPEN)
-
# A remote endpoint has closed its connection.
-
1
CONNECTION_REMOTE_CLOSE = event_type(:PN_CONNECTION_REMOTE_CLOSE)
-
# A connection has been freed and any outstanding processing has been
-
# completed. This is the final event htat will ever be issued for a
-
# connection
-
1
CONNECTION_FINAL = event_type(:PN_CONNECTION_FINAL)
-
-
# A session has been created. This is the first event that will ever be
-
# issues for a session.
-
1
SESSION_INIT = event_type(:PN_SESSION_INIT)
-
# A local session endpoint has been opened.
-
1
SESSION_LOCAL_OPEN = event_type(:PN_SESSION_LOCAL_OPEN)
-
# A local session endpoint has been closed.
-
1
SESSION_LOCAL_CLOSE = event_type(:PN_SESSION_LOCAL_CLOSE)
-
# A remote endpoint has opened its session.
-
1
SESSION_REMOTE_OPEN = event_type(:PN_SESSION_REMOTE_OPEN)
-
# A remote endpoint has closed its session.
-
1
SESSION_REMOTE_CLOSE = event_type(:PN_SESSION_REMOTE_CLOSE)
-
# A session has been freed and any outstanding processing has been
-
# completed. This is the final event that will ever be issued for a
-
# session
-
1
SESSION_FINAL = event_type(:PN_SESSION_FINAL)
-
-
# A link has been created. This is the first event that will ever be
-
# issued for a link.
-
1
LINK_INIT = event_type(:PN_LINK_INIT)
-
# A local link endpoint has been opened.
-
1
LINK_LOCAL_OPEN = event_type(:PN_LINK_LOCAL_OPEN)
-
# A local link endpoint has been closed.
-
1
LINK_LOCAL_CLOSE = event_type(:PN_LINK_LOCAL_CLOSE)
-
# A local link endpoint has been detached.
-
1
LINK_LOCAL_DETACH = event_type(:PN_LINK_LOCAL_DETACH)
-
# A remote endpoint has opened its link.
-
1
LINK_REMOTE_OPEN = event_type(:PN_LINK_REMOTE_OPEN)
-
# A remote endpoint has closed its link.
-
1
LINK_REMOTE_CLOSE = event_type(:PN_LINK_REMOTE_CLOSE)
-
# A remote endpoint has detached its link.
-
1
LINK_REMOTE_DETACH = event_type(:PN_LINK_REMOTE_DETACH)
-
# The flow control state for a link has changed.
-
1
LINK_FLOW = event_type(:PN_LINK_FLOW)
-
# A link has been freed and any outstanding processing has been completed.
-
# This is the final event htat will ever be issued for a link.
-
1
LINK_FINAL = event_type(:PN_LINK_FINAL)
-
-
# A delivery has been created or updated.
-
1
DELIVERY = event_type(:PN_DELIVERY)
-
-
# A transport has new data to read and/or write.
-
1
TRANSPORT = event_type(:PN_TRANSPORT)
-
# Indicates that a transport error has occurred.
-
# @see Transport#condition To access the details of the error.
-
1
TRANSPORT_ERROR = event_type(:PN_TRANSPORT_ERROR)
-
# Indicates that the head of a transport has been closed. This means the
-
# transport will never produce more bytes for output to the network.
-
1
TRANSPORT_HEAD_CLOSED = event_type(:PN_TRANSPORT_HEAD_CLOSED)
-
# Indicates that the trail of a transport has been closed. This means the
-
# transport will never be able to process more bytes from the network.
-
1
TRANSPORT_TAIL_CLOSED = event_type(:PN_TRANSPORT_TAIL_CLOSED)
-
# Indicates that both the head and tail of a transport are closed.
-
1
TRANSPORT_CLOSED = event_type(:PN_TRANSPORT_CLOSED)
-
-
1
SELECTABLE_INIT = event_type(:PN_SELECTABLE_INIT)
-
1
SELECTABLE_UPDATED = event_type(:PN_SELECTABLE_UPDATED)
-
1
SELECTABLE_READABLE = event_type(:PN_SELECTABLE_READABLE)
-
1
SELECTABLE_WRITABLE = event_type(:PN_SELECTABLE_WRITABLE)
-
1
SELECTABLE_EXPIRED = event_type(:PN_SELECTABLE_EXPIRED)
-
1
SELECTABLE_ERROR = event_type(:PN_SELECTABLE_ERROR)
-
1
SELECTABLE_FINAL = event_type(:PN_SELECTABLE_FINAL)
-
-
# An Event provides notification of a state change within the protocol
-
# engine.
-
#
-
# Every event has a type that identifies what sort of state change has
-
# occurred, along with a pointer to the object whose state has changed,
-
# and also any associated objects.
-
#
-
# For more details on working with Event, please refer to Collector.
-
#
-
# @see Qpid::Proton::Event The list of predefined events.
-
#
-
1
class Event < EventBase
-
-
# @private
-
1
include Qpid::Proton::Util::ClassWrapper
-
# @private
-
1
include Qpid::Proton::Util::Wrapper
-
-
# Creates a Ruby object for the given pn_event_t.
-
#
-
# @private
-
1
def self.wrap(impl, number = nil)
-
return nil if impl.nil?
-
-
result = self.fetch_instance(impl, :pn_event_attachments)
-
return result unless result.nil?
-
number = Cproton.pn_event_type(impl) if number.nil?
-
event = Event.new(impl, number)
-
return event.context if event.context.is_a? EventBase
-
return event
-
end
-
-
# @private
-
1
def initialize(impl, number)
-
@impl = impl
-
class_name = Cproton.pn_class_name(Cproton.pn_event_class(impl))
-
context = class_wrapper(class_name, Cproton.pn_event_context(impl))
-
event_type = EventType.by_type(Cproton.pn_event_type(impl))
-
super(class_name, context, event_type)
-
@type = EventType.by_type(number)
-
self.class.store_instance(self, :pn_event_attachments)
-
end
-
-
# Notifies the handler(s) of this event.
-
#
-
# If a handler responds to the event's method then that method is invoked
-
# and passed the event. Otherwise, if the handler defines the
-
# +on_unhandled+ method, then that will be invoked instead.
-
#
-
# If the handler defines a +handlers+ method then that will be invoked and
-
# passed the event afterward.
-
#
-
# @example
-
#
-
# class FallbackEventHandler
-
#
-
# # since it now defines a handlers method, any event will iterate
-
# # through them and invoke the +dispatch+ method on each
-
# attr_accessor handlers
-
#
-
# def initialize
-
# @handlers = []
-
# end
-
#
-
# # invoked for any event not otherwise handled
-
# def on_unhandled(event)
-
# puts "Unable to invoke #{event.type.method} on #{event.context}."
-
# end
-
#
-
# end
-
#
-
# @param handler [Object] An object which implements either the event's
-
# handler method or else responds to :handlers with an array of other
-
# handlers.
-
#
-
1
def dispatch(handler, type = nil)
-
type = @type if type.nil?
-
if handler.is_a?(Qpid::Proton::Handler::WrappedHandler)
-
Cproton.pn_handler_dispatch(handler.impl, @impl, type.number)
-
else
-
result = Qpid::Proton::Event.dispatch(handler, type.method, self)
-
if (result != "DELEGATED") && handler.respond_to?(:handlers)
-
handler.handlers.each do |hndlr|
-
self.dispatch(hndlr)
-
end
-
end
-
end
-
end
-
-
# Returns the reactor for this event.
-
#
-
# @return [Reactor, nil] The reactor.
-
#
-
1
def reactor
-
impl = Cproton.pn_event_reactor(@impl)
-
Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl)
-
end
-
-
1
def container
-
impl = Cproton.pn_event_reactor(@impl)
-
Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl)
-
end
-
-
# Returns the transport for this event.
-
#
-
# @return [Transport, nil] The transport.
-
#
-
1
def transport
-
Qpid::Proton::Transport.wrap(Cproton.pn_event_transport(@impl))
-
end
-
-
# Returns the Connection for this event.
-
#
-
# @return [Connection, nil] The connection.
-
#
-
1
def connection
-
Qpid::Proton::Connection.wrap(Cproton.pn_event_connection(@impl))
-
end
-
-
# Returns the Session for this event.
-
#
-
# @return [Session, nil] The session
-
#
-
1
def session
-
Qpid::Proton::Session.wrap(Cproton.pn_event_session(@impl))
-
end
-
-
# Returns the Link for this event.
-
#
-
# @return [Link, nil] The link.
-
#
-
1
def link
-
Qpid::Proton::Link.wrap(Cproton.pn_event_link(@impl))
-
end
-
-
# Returns the Sender, or nil if there is no Link, associated with this
-
# event if that link is a sender.
-
#
-
# @return [Sender, nil] The sender.
-
#
-
1
def sender
-
return self.link if !self.link.nil? && self.link.sender?
-
end
-
-
# Returns the Receiver, or nil if there is no Link, associated with this
-
# event if that link is a receiver.
-
#
-
# @return [Receiver, nil] The receiver.
-
#
-
1
def receiver
-
return self.link if !self.link.nil? && self.link.receiver?
-
end
-
-
# Returns the Delivery associated with this event.
-
#
-
# @return [Delivery, nil] The delivery.
-
#
-
1
def delivery
-
Qpid::Proton::Delivery.wrap(Cproton.pn_event_delivery(@impl))
-
end
-
-
# Sets the message.
-
#
-
# @param message [Qpid::Proton::Message] The message
-
#
-
1
def message=(message)
-
@message = message
-
end
-
-
# Returns the message.
-
#
-
# @return [Qpid::Proton::Message] The message.
-
#
-
1
def message
-
@message
-
end
-
-
# @private
-
1
def to_s
-
"#{self.type}(#{self.context})"
-
end
-
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Event
-
-
# @private
-
1
def self.dispatch(handler, method, *args)
-
args = args.last unless args.nil?
-
if handler.respond_to? method.to_sym
-
return handler.__send__(method, args)
-
elsif handler.respond_to? :on_unhandled
-
return handler.__send__(:on_unhandled, method, args)
-
end
-
end
-
-
# EventBase is the foundation for creating application-specific events.
-
#
-
# @example
-
#
-
# # 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 EventType The EventType class for how ENCRYPTED_RECV was defined.
-
#
-
1
class EventBase
-
-
# Returns the name for the class associated with this event.
-
1
attr_reader :class_name
-
-
# Returns the associated context object for the event.
-
1
attr_reader :context
-
-
# Returns the type of the event.
-
1
attr_reader :type
-
-
# Creates a new event with the specific class_name and context of the
-
# specified type.
-
#
-
# @param class_name [String] The name of the class.
-
# @param context [Object] The event context.
-
# @param type [EventType] The event type.
-
#
-
1
def initialize(class_name, context, type)
-
@class_name = class_name
-
@context = context
-
@type = type
-
end
-
-
# Invokes the type-specific method on the provided handler.
-
#
-
# @param handler [Object] The handler to be notified of this event.
-
#
-
1
def dispatch(handler)
-
Qpid::Proton.dispatch(handler, @type.method, self)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Event
-
-
# Manages the association between an Event and the method which should
-
# process on the context object associated with an occurance of the event.
-
#
-
# Each type is identified by a unique #type value.
-
#
-
# @example
-
#
-
# # SCENARIO: A part of an application handles extracting and decrypting
-
# # data received from a remote endpoint.
-
# #
-
# # An EventType is created to notify handlers that such a
-
# # situation has occurred.
-
#
-
# ENCRYPTED_RECV = 10000 # the unique constant value for the event
-
#
-
# # create a new event type which, when it occurs, invokes a method
-
# # named :on_encrypted_data when a handler is notified of its occurrance
-
# Qpid::Proton::Event::ENCRYPTED_RECV =
-
# Qpid::Proton::Event::EventType.new(ENCRYPTED_RECV, :on_encrypted_data)
-
#
-
# @see EventBase EventBase for the rest of this example.
-
# @see Qpid::Proton::Event::Event The Event class for more details on events.
-
#
-
1
class EventType
-
-
# The method to invoke on any potential handler.
-
1
attr_reader :method
-
1
attr_reader :number
-
-
1
def initialize(number, method)
-
41
@number = number
-
41
@name = Cproton.pn_event_type_name(@number)
-
41
@method = method
-
41
@@types ||= {}
-
41
@@types[number] = self
-
end
-
-
# @private
-
1
def to_s
-
@name
-
end
-
-
# @private
-
1
def self.by_type(type) # :nodoc:
-
@@types[type]
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
# Mixing that provides methods for acknowledging a delivery.
-
#
-
1
module Acking
-
-
# Accept the receivered message.
-
#
-
# @param delivery [Qpid::Proton::Delivery] The delivery.
-
#
-
1
def accept(delivery)
-
self.settle(delivery, Qpid::Proton::Delivery::ACCEPTED)
-
end
-
-
# Rejects a received message that is considered invalid or unprocessable.
-
#
-
# @param delivery [Qpid::Proton::Delivery] The delivery.
-
#
-
1
def reject(delivery)
-
self.settle(delivery, Qpid::Proton::Delivery::REJECTED)
-
end
-
-
# Releases a received message, making it available at the source for any
-
# other interested receiver.
-
#
-
# @param delivery [Qpid::Proton::Delivery] The delivery
-
# @param delivered [Boolean] True if this was considered a delivery
-
# attempt.
-
#
-
1
def release(delivery, delivered = true)
-
if delivered
-
self.settle(delivery, Qpid::Proton::Delivery::MODIFIED)
-
else
-
self.settle(delivery, Qpid::Proton::Delivery::RELEASED)
-
end
-
end
-
-
# Settles the specified delivery. Updates the delivery state if a state
-
# is specified.
-
#
-
# @param delivery [Qpid::Proton::Delivery] The delivery.
-
# @param state [Fixnum] The delivery state.
-
#
-
1
def settle(delivery, state = nil)
-
delivery.update(state) unless state.nil?
-
delivery.settle
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
# @private
-
1
class CAdaptor
-
-
1
def initialize(handler, on_error = nil)
-
@handler = handler
-
@on_error = on_error
-
end
-
-
1
def dispatch(cevent, ctype)
-
event = Qpid::Proton::Event::Event.wrap(cevent, ctype)
-
# TODO add a variable to enable this programmatically
-
# print "EVENT: #{event} going to #{@handler}\n"
-
event.dispatch(@handler)
-
end
-
-
1
def exception(error)
-
if @on_error.nil?
-
raise error
-
else
-
@on_error.call(error)
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
# @private
-
1
class CFlowController < Qpid::Proton::Handler::WrappedHandler
-
-
1
include Qpid::Proton::Util::Wrapper
-
-
1
def initialize(window = 1024)
-
super(Cproton.pn_flowcontroller(window))
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
# A utility that exposes endpoint events; i.e., the open/close of a link,
-
# session or connection, in a more intuitive manner.
-
#
-
# A XXX_opened method will be called when both local and remote peers have
-
# opened the link, session or connection. This can be used to confirm a
-
# locally initiated action for example.
-
#
-
# A XXX_opening method will be called when the remote peer has requested
-
# an open that was not initiated locally. By default this will simply open
-
# locally, which then trigtgers the XXX_opened called.
-
#
-
# The same applies to close.
-
#
-
1
class EndpointStateHandler < Qpid::Proton::BaseHandler
-
-
1
def initialize(peer_close_is_error = false, delegate = nil)
-
@delegate = delegate
-
@peer_close_is_error = peer_close_is_error
-
end
-
-
1
def self.print_error(endpoint, endpoint_type)
-
if !endpoint.remote_condition.nil?
-
elsif self.local_endpoint?(endpoint) && endpoint.remote_closed?
-
logging.error("#{endpoint_type} closed by peer")
-
end
-
end
-
-
1
def on_link_remote_close(event)
-
if !event.link.remote_condition.nil?
-
self.on_link_error(event)
-
elsif event.link.local_closed?
-
self.on_link_closed(event)
-
else
-
self.on_link_closing(event)
-
end
-
event.link.close
-
end
-
-
1
def on_session_remote_close(event)
-
if !event.session.remote_condition.nil?
-
self.on_session_error(event)
-
elsif event.session.local_closed?
-
self.on_session_closed(event)
-
else
-
self.on_session_closing(event)
-
end
-
event.session.close
-
end
-
-
1
def on_connection_remote_close(event)
-
if !event.connection.remote_condition.nil?
-
self.on_connection_error(event)
-
elsif event.connection.local_closed?
-
self.on_connection_closed(event)
-
else
-
self.on_connection_closing(event)
-
end
-
event.connection.close
-
end
-
-
1
def on_connection_local_open(event)
-
self.on_connection_opened(event) if event.connection.remote_active?
-
end
-
-
1
def on_connection_remote_open(event)
-
if !(event.connection.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
-
self.on_connection_opened(event)
-
elsif event.connection.local_uninit?
-
self.on_connection_opening(event)
-
event.connection.open
-
end
-
end
-
-
1
def on_session_local_open(event)
-
self.on_session_opened(event) if event.session.remote_active?
-
end
-
-
1
def on_session_remote_open(event)
-
if !(event.session.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
-
self.on_session_opened(event)
-
elsif event.session.local_uninit?
-
self.on_session_opening(event)
-
event.session.open
-
end
-
end
-
-
1
def on_link_local_open(event)
-
self.on_link_opened(event) if event.link.remote_active?
-
end
-
-
1
def on_link_remote_open(event)
-
if !(event.link.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
-
self.on_link_opened(event)
-
elsif event.link.local_uninit?
-
self.on_link_opening(event)
-
event.link.open
-
end
-
end
-
-
1
def on_connection_opened(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
-
end
-
-
1
def on_session_opened(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
-
end
-
-
1
def on_link_opened(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_link_opened, event) if !@delegate.nil?
-
end
-
-
1
def on_connection_opening(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_connection_opening, event) if !@delegate.nil?
-
end
-
-
1
def on_session_opening(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_session_opening, event) if !@delegate.nil?
-
end
-
-
1
def on_link_opening(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_link_opening, event) if !@delegate.nil?
-
end
-
-
1
def on_connection_error(event)
-
if !@delegate.nil?
-
Qpid::Proton::Event.dispatch(@delegate, :on_connection_error, event)
-
else
-
self.log_error(event.connection, "connection")
-
end
-
end
-
-
1
def on_session_error(event)
-
if !@delegate.nil?
-
Qpid::Proton::Event.dispatch(@delegate, :on_session_error, event)
-
else
-
self.log_error(event.session, "session")
-
event.connection.close
-
end
-
end
-
-
1
def on_link_error(event)
-
if !@delegate.nil?
-
Qpid::Proton::Event.dispatch(@delegate, :on_link_error, event)
-
else
-
self.log_error(event.link, "link")
-
event.conneciton.close
-
end
-
end
-
-
1
def on_connection_closed(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_connection_closed, event) if !@delegate.nil?
-
end
-
-
1
def on_session_closed(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_session_closed, event) if !@delegate.nil?
-
end
-
-
1
def on_link_closed(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_link_closed, event) if !@delegate.nil?
-
end
-
-
1
def on_connection_closing(event)
-
if !@delegate.nil?
-
Qpid::Proton::Event.dispatch(@delegate, :on_connection_closing, event)
-
elsif @peer_close_is_error
-
self.on_connection_error(event)
-
end
-
end
-
-
1
def on_session_closing(event)
-
if !@delegate.nil?
-
Qpid::Proton::Event.dispatch(@delegate, :on_session_closing, event)
-
elsif @peer_close_is_error
-
self.on_session_error(event)
-
end
-
end
-
-
1
def on_link_closing(event)
-
if !@delegate.nil?
-
Qpid::Proton::Event.dispatch(@delegate, :on_link_closing, event)
-
elsif @peer_close_is_error
-
self.on_link_error(event)
-
end
-
end
-
-
1
def on_transport_tail_closed(event)
-
self.on_transport_closed(event)
-
end
-
-
1
def on_transport_closed(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_disconnected, event) if !@delegate.nil?
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
# A utility for simpler and more intuitive handling of delivery events
-
# related to incoming messages.
-
#
-
1
class IncomingMessageHandler < Qpid::Proton::BaseHandler
-
-
1
include Acking
-
-
1
def initialize(auto_accept = true, delegate = nil)
-
@delegate = delegate
-
@auto_accept = auto_accept
-
end
-
-
1
def on_delivery(event)
-
delivery = event.delivery
-
return unless delivery.link.receiver?
-
if delivery.readable? && !delivery.partial?
-
event.message = Qpid::Proton::Util::Engine.receive_message(delivery)
-
if event.link.local_closed?
-
if @auto_accept
-
delivery.update(Qpid::Proton::Disposition::RELEASED)
-
delivery.settle
-
end
-
else
-
begin
-
self.on_message(event)
-
if @auto_accept
-
delivery.update(Qpid::Proton::Disposition::ACCEPTED)
-
delivery.settle
-
end
-
rescue Qpid::Proton::Reject
-
delivery.update(Qpid::Proton::Disposition::REJECTED)
-
delivery.settle
-
rescue Qpid::Proton::Release
-
delivery.update(Qpid::Proton::Disposition::MODIFIED)
-
delivery.settle
-
end
-
end
-
elsif delivery.updated? && delivery.settled?
-
self.on_settled(event)
-
end
-
end
-
-
1
def on_message(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_message, event) if !@delegate.nil?
-
end
-
-
1
def on_settled(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_settled, event) if !@delegate.nil?
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
# A general purpose handler that simplifies processing events.
-
#
-
# @example
-
#
-
1
class MessagingHandler < Qpid::Proton::BaseHandler
-
-
1
attr_reader :handlers
-
-
# Creates a new instance.
-
#
-
# @param [Fixnum] prefetch
-
# @param [Boolean] auto_accept
-
# @param [Boolean] auto_settle
-
# @param [Boolean] peer_close_is_error
-
#
-
1
def initialize(prefetch = 10, auto_accept = true, auto_settle = true, peer_close_is_error = false)
-
@handlers = Array.new
-
@handlers << CFlowController.new(prefetch) unless prefetch.zero?
-
@handlers << EndpointStateHandler.new(peer_close_is_error, self)
-
@handlers << IncomingMessageHandler.new(auto_accept, self)
-
@handlers << OutgoingMessageHandler.new(auto_settle,self)
-
end
-
-
# Called when the peer closes the connection with an error condition.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_connection_error(event)
-
EndpointStateHandler.print_error(event.connection, "connection")
-
end
-
-
# Called when the peer closes the session with an error condition.
-
#
-
# @param event [Qpid:Proton::Event::Event] The event.
-
#
-
1
def on_session_error(event)
-
EndpointStateHandler.print_error(event.session, "session")
-
event.connection.close
-
end
-
-
# Called when the peer closes the link with an error condition.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_link_error(event)
-
EndpointStateHandler.print_error(event.link, "link")
-
event.connection.close
-
end
-
-
# Called when the event loop starts.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_reactor_init(event)
-
self.on_start(event)
-
end
-
-
# Called when the event loop starts.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_start(event)
-
end
-
-
# Called when the connection is closed.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_connection_closed(event)
-
end
-
-
# Called when the session is closed.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_session_closed(event)
-
end
-
-
# Called when the link is closed.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_link_closed(event)
-
end
-
-
# Called when the peer initiates the closing of the connection.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_connection_closing(event)
-
end
-
-
# Called when the peer initiates the closing of the session.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_session_closing(event)
-
end
-
-
# Called when the peer initiates the closing of the link.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_link_closing(event)
-
end
-
-
# Called when the socket is disconnected.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_disconnected(event)
-
end
-
-
# Called when the sender link has credit and messages can therefore
-
# be transferred.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_sendable(event)
-
end
-
-
# Called when the remote peer accepts an outgoing message.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_accepted(event)
-
end
-
-
# Called when the remote peer rejects an outgoing message.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_rejected(event)
-
end
-
-
# Called when the remote peer releases an outgoing message.
-
#
-
# Note that this may be in response to either the RELEASE or
-
# MODIFIED state as defined by the AMPQ specification.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_released(event)
-
end
-
-
# Called when the remote peer has settled hte outgoing message.
-
#
-
# This is the point at which it should never be retransmitted.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_settled(event)
-
end
-
-
# Called when a message is received.
-
#
-
# The message itself can be obtained as a property on the event. For
-
# the purpose of referring to this message in further actions, such as
-
# explicitly accepting it) the delivery should be used. This is also
-
# obtainable vi a property on the event.
-
#
-
# This method needs to be overridden.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_message(event)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
# A utility for simpler and more intuitive handling of delivery events
-
# related to outgoing messages.
-
#
-
1
class OutgoingMessageHandler < Qpid::Proton::BaseHandler
-
-
1
def initialize(auto_settle = true, delegate = nil)
-
@auto_settle = auto_settle
-
@delegate = delegate
-
end
-
-
1
def on_link_flow(event)
-
self.on_sendable(event) if event.link.sender? && event.link.credit > 0
-
end
-
-
1
def on_delivery(event)
-
delivery = event.delivery
-
if delivery.link.sender? && delivery.updated?
-
if delivery.remote_accepted?
-
self.on_accepted(event)
-
elsif delivery.remote_rejected?
-
self.on_rejected(event)
-
elsif delivery.remote_released? || delivery.remote_modified?
-
self.on_released(event)
-
end
-
self.on_settled(event) if delivery.settled?
-
delivery.settle if @auto_settle
-
end
-
end
-
-
# Called when the sender link has credit and messages and be transferred.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_sendable(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_sendable, event) if !@delegate.nil?
-
end
-
-
# Called when the remote peer accepts a sent message.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_accepted(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_accepted, event) if !@delegate.nil?
-
end
-
-
# Called when the remote peer rejects a sent message.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_rejected(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_rejected, event) if !@delegate.nil?
-
end
-
-
# Called when the remote peer releases an outgoing message.
-
#
-
# Note that this may be in resposnse to either the REELAASE or MODIFIED
-
# state as defined by the AMQP specification.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_released(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_released, event) if !@delegate.nil?
-
end
-
-
# Called when the remote peer has settled the outgoing message.
-
#
-
# This is the point at which it should never be retransmitted.
-
#
-
# @param event [Qpid::Proton::Event::Event] The event.
-
#
-
1
def on_settled(event)
-
Qpid::Proton::Event.dispatch(@delegate, :on_settled, event) if !@delegate.nil?
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Handler
-
-
1
class WrappedHandler
-
-
# @private
-
1
include Qpid::Proton::Util::Wrapper
-
-
1
def self.wrap(impl, on_error = nil)
-
return nil if impl.nil?
-
-
result = self.fetch_instance(impl) || WrappedHandler.new(impl)
-
result.on_error = on_error
-
return result
-
end
-
-
1
include Qpid::Proton::Util::Handler
-
-
1
def initialize(impl_or_constructor)
-
if impl_or_constructor.is_a?(Method)
-
@impl = impl_or_constructor.call
-
else
-
@impl = impl_or_constructor
-
Cproton.pn_incref(@impl)
-
end
-
@on_error = nil
-
self.class.store_instance(self)
-
end
-
-
1
def add(handler)
-
return if handler.nil?
-
-
impl = chandler(handler, self.method(:_on_error))
-
Cproton.pn_handler_add(@impl, impl)
-
Cproton.pn_decref(impl)
-
end
-
-
1
def clear
-
Cproton.pn_handler_clear(@impl)
-
end
-
-
1
def on_error=(on_error)
-
@on_error = on_error
-
end
-
-
1
private
-
-
1
def _on_error(info)
-
if self.has?['on_error']
-
self['on_error'].call(info)
-
else
-
raise info
-
end
-
end
-
-
end
-
-
end
-
#
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#
-
-
1
module Qpid::Proton::Messenger
-
-
# The +Messenger+ class defines a high level interface for
-
# sending and receiving Messages. Every Messenger contains
-
# a single logical queue of incoming messages and a single
-
# logical queue of outgoing messages. These messages in these
-
# queues may be destined for, or originate from, a variety of
-
# addresses.
-
#
-
# The messenger interface is single-threaded. All methods
-
# except one ( #interrupt ) are intended to be used from within
-
# the messenger thread.
-
#
-
# === Sending & Receiving Messages
-
#
-
# The Messenger class works in conjuction with the Message class. The
-
# Message class is a mutable holder of message content.
-
#
-
# The put method copies its Message to the outgoing queue, and may
-
# send queued messages if it can do so without blocking. The send
-
# method blocks until it has sent the requested number of messages,
-
# or until a timeout interrupts the attempt.
-
#
-
# Similarly, the recv method receives messages into the incoming
-
# queue, and may block as it attempts to receive the requested number
-
# of messages, or until timeout is reached. It may receive fewer
-
# than the requested number. The get method pops the
-
# eldest Message off the incoming queue and copies it into the Message
-
# object that you supply. It will not block.
-
#
-
# The blocking attribute allows you to turn off blocking behavior entirely,
-
# in which case send and recv will do whatever they can without
-
# blocking, and then return. You can then look at the number
-
# of incoming and outgoing messages to see how much outstanding work
-
# still remains.
-
#
-
1
class Messenger
-
-
1
include Qpid::Proton::Util::ErrorHandler
-
-
1
can_raise_error [:send, :receive, :password=, :start, :stop,
-
:perform_put, :perform_get, :interrupt,
-
:route, :rewrite, :accept, :reject,
-
:incoming_window=, :outgoing_window=]
-
-
# Creates a new +Messenger+.
-
#
-
# The +name+ parameter is optional. If one is not provided then
-
# a unique name is generated.
-
#
-
# ==== Options
-
#
-
# * name - the name (def. nil)
-
#
-
1
def initialize(name = nil)
-
59
@impl = Cproton.pn_messenger(name)
-
59
@selectables = {}
-
59
ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
-
end
-
-
1
def self.finalize!(impl) # :nodoc:
-
59
proc {
-
Cproton.pn_messenger_free(impl)
-
}
-
end
-
-
# Returns the name.
-
#
-
1
def name
-
2
Cproton.pn_messenger_name(@impl)
-
end
-
-
# This property contains the password for the Messenger.private_key
-
# file, or +nil+ if the file is not encrypted.
-
#
-
# ==== Arguments
-
#
-
# * password - the password
-
#
-
1
def password=(password)
-
Cproton.pn_messenger_set_password(@impl, password)
-
end
-
-
# Returns the password property for the Messenger.private_key file.
-
#
-
1
def password
-
Cproton.pn_messenger_get_password(@impl)
-
end
-
-
# Sets the timeout period, in milliseconds.
-
#
-
# A negative timeout period implies an infinite timeout.
-
#
-
# ==== Options
-
#
-
# * timeout - the timeout period
-
#
-
1
def timeout=(timeout)
-
29
raise TypeError.new("invalid timeout: #{timeout}") if timeout.nil?
-
28
Cproton.pn_messenger_set_timeout(@impl, timeout)
-
end
-
-
# Returns the timeout period
-
#
-
1
def timeout
-
2
Cproton.pn_messenger_get_timeout(@impl)
-
end
-
-
# Returns true if blocking mode is enabled.
-
#
-
# Enable or disable blocking behavior during message sending
-
# and receiving. This affects every blocking call, with the
-
# exception of work(). Currently, the affected calls are
-
# send, recv, and stop.
-
1
def blocking?
-
Cproton.pn_messenger_is_blocking(@impl)
-
end
-
-
# Sets the blocking mode.
-
1
def blocking=(blocking)
-
Cproton.pn_messenger_set_blocking(@impl, blocking)
-
end
-
-
# Returns true if passive mode is enabled.
-
#
-
1
def passive?
-
2
Cproton.pn_messenger_is_passive(@impl)
-
end
-
-
# Turns passive mode on or off.
-
#
-
# When set to passive mode, Messenger will not attempt to perform I/O
-
# operations internally. In this mode it is necesssary to use the
-
# Selectable type to drive any I/O needed to perform requestioned
-
# actions.
-
#
-
# In this mode Messenger will never block.
-
#
-
1
def passive=(mode)
-
2
Cproton.pn_messenger_set_passive(@impl, mode)
-
end
-
-
1
def deadline
-
tstamp = Cproton.pn_messenger_deadline(@impl)
-
return tstamp / 1000.0 unless tstamp.nil?
-
end
-
-
# Reports whether an error occurred.
-
#
-
1
def error?
-
5
!Cproton.pn_messenger_errno(@impl).zero?
-
end
-
-
# Returns the most recent error number.
-
#
-
1
def errno
-
4
Cproton.pn_messenger_errno(@impl)
-
end
-
-
# Returns the most recent error message.
-
#
-
1
def error
-
14
Cproton.pn_error_text(Cproton.pn_messenger_error(@impl))
-
end
-
-
# Clears the current error state.
-
#
-
1
def clear_error
-
2
error = Cproton.pn_messenger_error(@impl)
-
2
unless error.nil?
-
2
Cproton.pn_error_clear(error)
-
end
-
end
-
-
# Currently a no-op placeholder.
-
# For future compatibility, do not send or recv messages
-
# before starting the +Messenger+.
-
#
-
1
def start
-
28
Cproton.pn_messenger_start(@impl)
-
end
-
-
# Stops the +Messenger+, preventing it from sending or receiving
-
# any more messages.
-
#
-
1
def stop
-
86
Cproton.pn_messenger_stop(@impl)
-
end
-
-
# Returns true if a Messenger is in the stopped state.
-
# This function does not block.
-
#
-
1
def stopped?
-
Cproton.pn_messenger_stopped(@impl)
-
end
-
-
# Subscribes the Messenger to messages originating from the
-
# specified source. The source is an address as specified in the
-
# Messenger introduction with the following addition. If the
-
# domain portion of the address begins with the '~' character, the
-
# Messenger will interpret the domain as host/port, bind to it,
-
# and listen for incoming messages. For example "~0.0.0.0",
-
# "amqp://~0.0.0.0" will all bind to any local interface and
-
# listen for incoming messages. An address of "amqps://~0.0.0.0"
-
# will only permit incoming SSL connections.
-
#
-
# ==== Options
-
#
-
# * address - the source address to be subscribe
-
# * timeout - an optional time-to-live value, in seconds, for the
-
# subscription
-
#
-
1
def subscribe(address, timeout=0)
-
18
raise TypeError.new("invalid address: #{address}") if address.nil?
-
17
subscription = Cproton.pn_messenger_subscribe_ttl(@impl, address, timeout)
-
17
raise Qpid::Proton::ProtonError.new("Subscribe failed") if subscription.nil?
-
14
Subscription.new(subscription)
-
end
-
-
# Path to a certificate file for the +Messenger+.
-
#
-
# This certificate is used when the +Messenger+ accepts or establishes
-
# SSL/TLS connections. This property must be specified for the
-
# Messenger to accept incoming SSL/TLS connections and to establish
-
# client authenticated outgoing SSL/TLS connection. Non client authenticated
-
# outgoing SSL/TLS connections do not require this property.
-
#
-
# ==== Options
-
#
-
# * certificate - the certificate
-
#
-
1
def certificate=(certificate)
-
2
Cproton.pn_messenger_set_certificate(@impl, certificate)
-
end
-
-
# Returns the path to a certificate file.
-
#
-
1
def certificate
-
2
Cproton.pn_messenger_get_certificate(@impl)
-
end
-
-
# Path to a private key file for the +Messenger+.
-
#
-
# The property must be specified for the +Messenger+ to accept incoming
-
# SSL/TLS connections and to establish client authenticated outgoing
-
# SSL/TLS connections. Non client authenticated SSL/TLS connections
-
# do not require this property.
-
#
-
# ==== Options
-
#
-
# * key - the key file
-
#
-
1
def private_key=(key)
-
2
Cproton.pn_messenger_set_private_key(@impl, key)
-
end
-
-
# Returns the path to a private key file.
-
#
-
1
def private_key
-
2
Cproton.pn_messenger_get_private_key(@impl)
-
end
-
-
# A path to a database of trusted certificates for use in verifying the
-
# peer on an SSL/TLS connection. If this property is +nil+, then the
-
# peer will not be verified.
-
#
-
# ==== Options
-
#
-
# * certificates - the certificates path
-
#
-
1
def trusted_certificates=(certificates)
-
2
Cproton.pn_messenger_set_trusted_certificates(@impl,certificates)
-
end
-
-
# The path to the databse of trusted certificates.
-
#
-
1
def trusted_certificates
-
2
Cproton.pn_messenger_get_trusted_certificates(@impl)
-
end
-
-
# Places the content contained in the message onto the outgoing
-
# queue of the Messenger.
-
#
-
# This method will never block, however it will send any unblocked
-
# Messages in the outgoing queue immediately and leave any blocked
-
# Messages remaining in the outgoing queue.
-
# The send call may then be used to block until the outgoing queue
-
# is empty. The outgoing attribute may be used to check the depth
-
# of the outgoing queue.
-
#
-
# ==== Options
-
#
-
# * message - the message
-
#
-
1
def put(message)
-
11
if message.nil?
-
1
raise TypeError.new("invalid message: #{message}")
-
end
-
10
unless message.kind_of?(Qpid::Proton::Message)
-
1
raise ::ArgumentError.new("invalid message type: #{message.class}")
-
end
-
# encode the message first
-
9
message.pre_encode
-
9
perform_put(message)
-
9
return outgoing_tracker
-
end
-
-
1
private
-
-
1
def perform_put(message) # :nodoc:
-
9
Cproton.pn_messenger_put(@impl, message.impl)
-
end
-
-
1
public
-
-
-
# This call will block until the indicated number of messages
-
# have been sent, or until the operation times out.
-
# If n is -1 this call will block until all outgoing messages
-
# have been sent. If n is 0 then this call will send whatever
-
# it can without blocking.
-
#
-
1
def send(n = -1)
-
Cproton.pn_messenger_send(@impl, n)
-
end
-
-
# Moves the message from the head of the incoming message queue into
-
# the supplied message object. Any content in the supplied message
-
# will be overwritten.
-
# A tracker for the incoming Message is returned. The tracker can
-
# later be used to communicate your acceptance or rejection of the
-
# Message.
-
#
-
# If no message is provided in the argument, then one is created. In
-
# either case, the one returned will be the fetched message.
-
#
-
# ==== Options
-
#
-
# * msg - the (optional) +Message+ instance to be used
-
#
-
1
def get(msg = nil)
-
msg_impl = nil
-
if msg.nil? then
-
msg_impl = nil
-
else
-
msg_impl = msg.impl
-
end
-
perform_get(msg_impl)
-
msg.post_decode unless msg.nil?
-
return incoming_tracker
-
end
-
-
1
private
-
-
1
def perform_get(msg) # :nodoc:
-
Cproton.pn_messenger_get(@impl, msg)
-
end
-
-
1
public
-
-
# Receives up to limit messages into the incoming queue. If no value
-
# for limit is supplied, this call will receive as many messages as it
-
# can buffer internally. If the Messenger is in blocking mode, this
-
# call will block until at least one Message is available in the
-
# incoming queue.
-
#
-
# Options ====
-
#
-
# * limit - the maximum number of messages to receive
-
#
-
1
def receive(limit = -1)
-
3
Cproton.pn_messenger_recv(@impl, limit)
-
end
-
-
# Returns true if the messenger is currently receiving data.
-
1
def receiving?
-
Cproton.pn_messenger_receiving(@impl)
-
end
-
-
# Attempts interrupting of the messenger thread.
-
#
-
# The Messenger interface is single-threaded, and this is the only
-
# function intended to be called from outside of is thread.
-
#
-
# Call this from a non-Messenger thread to interrupt it while it
-
# is blocking. This will cause a ::InterruptError to be raised.
-
#
-
# If there is no currently blocking call, then the next blocking
-
# call will be affected, even if it is within the same thread that
-
# originated the interrupt.
-
#
-
1
def interrupt
-
Cproton.pn_messenger_interrupt(@impl)
-
end
-
-
# Sends or receives any outstanding messages queued for a Messenger.
-
#
-
# This will block for the indicated timeout. This method may also do I/O
-
# other than sending and receiving messages. For example, closing
-
# connections after stop() has been called.
-
#
-
1
def work(timeout=-1)
-
err = Cproton.pn_messenger_work(@impl, timeout)
-
if (err == Cproton::PN_TIMEOUT) then
-
return false
-
else
-
check_for_error(err)
-
return true
-
end
-
end
-
-
# Returns the number messages in the outgoing queue that have not been
-
# transmitted.
-
#
-
1
def outgoing
-
Cproton.pn_messenger_outgoing(@impl)
-
end
-
-
# Returns the number of messages in the incoming queue that have not
-
# been retrieved.
-
#
-
1
def incoming
-
Cproton.pn_messenger_incoming(@impl)
-
end
-
-
# Adds a routing rule to the Messenger's internal routing table.
-
#
-
# The route procedure may be used to influence how a Messenger will
-
# internally treat a given address or class of addresses. Every call
-
# to the route procedure will result in Messenger appending a routing
-
# rule to its internal routing table.
-
#
-
# Whenever a Message is presented to a Messenger for delivery, it
-
# will match the address of this message against the set of routing
-
# rules in order. The first rule to match will be triggered, and
-
# instead of routing based on the address presented in the message,
-
# the Messenger will route based on the address supplied in the rule.
-
#
-
# The pattern matching syntax supports two types of matches, a '%'
-
# will match any character except a '/', and a '*' will match any
-
# character including a '/'.
-
#
-
# A routing address is specified as a normal AMQP address, however it
-
# may additionally use substitution variables from the pattern match
-
# that triggered the rule.
-
#
-
# ==== Arguments
-
#
-
# * pattern - the address pattern
-
# * address - the target address
-
#
-
# ==== Examples
-
#
-
# # route messages sent to foo to the destionaty amqp://foo.com
-
# messenger.route("foo", "amqp://foo.com")
-
#
-
# # any message to foobar will be routed to amqp://foo.com/bar
-
# messenger.route("foobar", "amqp://foo.com/bar")
-
#
-
# # any message to bar/<path> will be routed to the same path within
-
# # the amqp://bar.com domain
-
# messenger.route("bar/*", "amqp://bar.com/$1")
-
#
-
# # route all Message objects over TLS
-
# messenger.route("amqp:*", "amqps:$1")
-
#
-
# # supply credentials for foo
-
# messenger.route("amqp://foo.com/*", "amqp://user:password@foo.com/$1")
-
#
-
# # supply credentials for all domains
-
# messenger.route("amqp://*", "amqp://user:password@$1")
-
#
-
# # route all addresses through a single proxy while preserving the
-
# # original destination
-
# messenger.route("amqp://%$/*", "amqp://user:password@proxy/$1/$2")
-
#
-
# # route any address through a single broker
-
# messenger.route("*", "amqp://user:password@broker/$1")
-
#
-
1
def route(pattern, address)
-
Cproton.pn_messenger_route(@impl, pattern, address)
-
end
-
-
# Similar to #route, except that the destination of
-
# the Message is determined before the message address is rewritten.
-
#
-
# The outgoing address is only rewritten after routing has been
-
# finalized. If a message has an outgoing address of
-
# "amqp://0.0.0.0:5678", and a rewriting rule that changes its
-
# outgoing address to "foo", it will still arrive at the peer that
-
# is listening on "amqp://0.0.0.0:5678", but when it arrives there,
-
# the receiver will see its outgoing address as "foo".
-
#
-
# The default rewrite rule removes username and password from addresses
-
# before they are transmitted.
-
#
-
# ==== Arguments
-
#
-
# * pattern - the outgoing address
-
# * address - the target address
-
#
-
1
def rewrite(pattern, address)
-
Cproton.pn_messenger_rewrite(@impl, pattern, address)
-
end
-
-
1
def selectable
-
impl = Cproton.pn_messenger_selectable(@impl)
-
-
# if we don't have any selectables, then return
-
return nil if impl.nil?
-
-
fd = Cproton.pn_selectable_get_fd(impl)
-
-
selectable = @selectables[fd]
-
if selectable.nil?
-
selectable = Selectable.new(self, impl)
-
@selectables[fd] = selectable
-
end
-
return selectable
-
end
-
-
# Returns a +Tracker+ for the message most recently sent via the put
-
# method.
-
#
-
1
def outgoing_tracker
-
15
impl = Cproton.pn_messenger_outgoing_tracker(@impl)
-
15
return nil if impl == -1
-
15
Tracker.new(impl)
-
end
-
-
# Returns a +Tracker+ for the most recently received message.
-
#
-
1
def incoming_tracker
-
1
impl = Cproton.pn_messenger_incoming_tracker(@impl)
-
1
return nil if impl == -1
-
1
Tracker.new(impl)
-
end
-
-
# Signal the sender that you have acted on the Message
-
# pointed to by the tracker. If no tracker is supplied,
-
# then all messages that have been returned by the get
-
# method are accepted, except those that have already been
-
# auto-settled by passing beyond your incoming window size.
-
#
-
# ==== Options
-
#
-
# * tracker - the tracker
-
#
-
1
def accept(tracker = nil)
-
3
raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker)
-
1
if tracker.nil? then
-
1
tracker = self.incoming_tracker
-
1
flag = Cproton::PN_CUMULATIVE
-
else
-
flag = 0
-
end
-
1
Cproton.pn_messenger_accept(@impl, tracker.impl, flag)
-
end
-
-
# Rejects the incoming message identified by the tracker.
-
# If no tracker is supplied, all messages that have been returned
-
# by the get method are rejected, except those that have already
-
# been auto-settled by passing beyond your outgoing window size.
-
#
-
# ==== Options
-
#
-
# * tracker - the tracker
-
#
-
1
def reject(tracker)
-
raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker)
-
if tracker.nil? then
-
tracker = self.incoming_tracker
-
flag = Cproton::PN_CUMULATIVE
-
else
-
flag = 0
-
end
-
Cproton.pn_messenger_reject(@impl, tracker.impl, flag)
-
end
-
-
# Gets the last known remote state of the delivery associated with
-
# the given tracker, as long as the Message is still within your
-
# outgoing window. (Also works on incoming messages that are still
-
# within your incoming queue. See TrackerStatus for details on the
-
# values returned.
-
#
-
# ==== Options
-
#
-
# * tracker - the tracker
-
#
-
1
def status(tracker)
-
3
raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker)
-
1
TrackerStatus.by_value(Cproton.pn_messenger_status(@impl, tracker.impl))
-
end
-
-
# Frees a Messenger from tracking the status associated
-
# with a given tracker. If you don't supply a tracker, all
-
# outgoing messages up to the most recent will be settled.
-
#
-
# ==== Options
-
#
-
# * tracker - the tracker
-
#
-
# ==== Examples
-
#
-
1
def settle(tracker)
-
2
raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker)
-
1
if tracker.nil? then
-
tracker = self.incoming_tracker
-
flag = Cproton::PN_CUMULATIVE
-
else
-
1
flag = 0
-
end
-
1
Cproton.pn_messenger_settle(@impl, tracker.impl, flag)
-
end
-
-
# Sets the incoming window.
-
#
-
# The Messenger will track the remote status of this many incoming
-
# deliveries after they have been accepted or rejected.
-
#
-
# Messages enter this window only when you take them into your application
-
# using get(). If your incoming window size is n, and you get n+1 messages
-
# without explicitly accepting or rejecting the oldest message, then the
-
# message that passes beyond the edge of the incoming window will be
-
# assigned the default disposition of its link.
-
#
-
# ==== Options
-
#
-
# * window - the window size
-
#
-
1
def incoming_window=(window)
-
5
raise TypeError.new("invalid window: #{window}") unless valid_window?(window)
-
3
Cproton.pn_messenger_set_incoming_window(@impl, window)
-
end
-
-
# Returns the incoming window.
-
#
-
1
def incoming_window
-
3
Cproton.pn_messenger_get_incoming_window(@impl)
-
end
-
-
# Sets the outgoing window.
-
#
-
# The Messenger will track the remote status of this many outgoing
-
# deliveries after calling send.
-
# A Message enters this window when you call the put() method with the
-
# message. If your outgoing window size is n, and you call put n+1
-
# times, status information will no longer be available for the
-
# first message.
-
#
-
# ==== Options
-
#
-
# * window - the window size
-
#
-
1
def outgoing_window=(window)
-
5
raise TypeError.new("invalid window: #{window}") unless valid_window?(window)
-
3
Cproton.pn_messenger_set_outgoing_window(@impl, window)
-
end
-
-
# Returns the outgoing window.
-
#
-
1
def outgoing_window
-
3
Cproton.pn_messenger_get_outgoing_window(@impl)
-
end
-
-
# Unregisters a selectable object.
-
1
def unregister_selectable(fileno) # :nodoc:
-
@selectables.delete(fileno)
-
end
-
-
1
private
-
-
1
def valid_tracker?(tracker)
-
7
!tracker.nil? && tracker.is_a?(Tracker)
-
end
-
-
1
def valid_window?(window)
-
10
!window.nil? && [Float, Fixnum].include?(window.class)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Messenger
-
-
# A +Subscription+ is an opaque object for working with a +Messenger+'s
-
# subscriptions.
-
#
-
1
class Subscription
-
-
1
def initialize(impl) # :nodoc:
-
14
@impl = impl
-
end
-
-
1
def impl # :nodoc:
-
@impl
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Messenger
-
-
# A +Tracker+ is used to track the disposition of a +Message+.
-
#
-
1
class Tracker
-
-
1
CUMULATIVE = Cproton::PN_CUMULATIVE
-
-
1
def initialize(impl) # :nodoc:
-
16
@impl = impl
-
end
-
-
1
def impl # :nodoc:
-
3
@impl
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Messenger
-
-
# TrackerStatus contains symbols that represent the status value for a
-
# Tracker.
-
#
-
1
class TrackerStatus
-
-
1
def initialize value, name # :nodoc:
-
5
@value = value
-
5
@name = name
-
end
-
-
1
def value # :nodoc:
-
@value
-
end
-
-
1
def to_s # :nodoc:
-
@name.to_s
-
end
-
-
1
def self.by_name(name) # :nodoc:
-
@by_name[name.to_sym] unless name.nil?
-
end
-
-
1
def self.by_value(value) # :nodoc:
-
1
@by_value[value] unless value.nil?
-
end
-
-
1
private
-
-
1
def self.add_item(key, value) # :nodoc:
-
5
@by_name ||= {}
-
5
@by_name[key] = TrackerStatus.new value, key
-
5
@by_value ||= {}
-
5
@by_value[value] = @by_name[key]
-
end
-
-
1
def self.const_missing(key) # :nodoc:
-
@by_name[key]
-
end
-
-
1
self.add_item :UNKNOWN, Cproton::PN_STATUS_UNKNOWN
-
1
self.add_item :PENDING, Cproton::PN_STATUS_PENDING
-
1
self.add_item :ACCEPTED, Cproton::PN_STATUS_ACCEPTED
-
1
self.add_item :REJECTED, Cproton::PN_STATUS_REJECTED
-
1
self.add_item :SETTLED, Cproton::PN_STATUS_SETTLED
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class Acceptor
-
-
1
include Qpid::Proton::Util::Wrapper
-
-
1
def initialize(impl)
-
@impl = impl
-
self.class.store_instance(self)
-
end
-
-
1
def set_ssl_domain(ssl_domain)
-
Cproton.pn_acceptor_set_ssl_domain(@impl, ssl_domain.impl)
-
end
-
-
1
def close
-
Cproton.pn_acceptor_close(@impl)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class Backoff
-
-
1
def initialize
-
@delay = 0
-
end
-
-
1
def reset
-
@delay = 0
-
end
-
-
1
def next
-
current = @delay
-
current = 0.1 if current.zero?
-
@delay = [10, 2 * current].min
-
return current
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class Connector < Qpid::Proton::BaseHandler
-
-
1
attr_accessor :address
-
1
attr_accessor :reconnect
-
1
attr_accessor :ssl_domain
-
-
1
def initialize(connection)
-
@connection = connection
-
@address = nil
-
@heartbeat = nil
-
@reconnect = nil
-
@ssl_domain = nil
-
end
-
-
1
def on_connection_local_open(event)
-
self.connect(event.connection)
-
end
-
-
1
def on_connection_remote_open(event)
-
if !@reconnect.nil?
-
@reconnect.reset
-
@transport = nil
-
end
-
end
-
-
1
def on_transport_tail_closed(event)
-
self.on_transport_closed(event)
-
end
-
-
1
def on_transport_closed(event)
-
if !@connection.nil? && !(@connection.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
-
if !@reconnect.nil?
-
event.transport.unbind
-
delay = @reconnect.next
-
if delay == 0
-
self.connect(@connection)
-
else
-
event.reactor.schedule(delay, self)
-
end
-
else
-
@connection = nil
-
end
-
end
-
end
-
-
1
def on_timer_task(event)
-
self.connect(@connection)
-
end
-
-
1
def on_connection_remote_close(event)
-
@connection = nil
-
end
-
-
1
def connect(connection)
-
url = @address.next
-
connection.hostname = "#{url.host}:#{url.port}"
-
-
transport = Qpid::Proton::Transport.new
-
transport.bind(connection)
-
if !@heartbeat.nil?
-
transport.idle_timeout = @heartbeat
-
elsif (url.scheme == "amqps") && !@ssl_domain.nil?
-
@ssl = Qpid::Proton::SSL.new(transport, @ssl_domain)
-
@ss.peer_hostname = url.host
-
elsif !url.username.nil?
-
sasl = transport.sasl
-
if url.username == "anonymous"
-
sasl.mechanisms("ANONYMOUS")
-
else
-
sasl.plain(url.username, url.password)
-
end
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
# @private
-
1
class InternalTransactionHandler < Qpid::Proton::Handler::OutgoingMessageHandler
-
-
1
def initialize
-
super
-
end
-
-
1
def on_settled(event)
-
if event.delivery.respond_to? :transaction
-
event.transaction = event.delivery.transaction
-
event.delivery.transaction.handle_outcome(event)
-
end
-
end
-
-
end
-
-
-
# A representation of the AMQP concept of a container which, loosely
-
# speaking, is something that establishes links to or from another
-
# container on which messages are transferred.
-
#
-
# This is an extension to the Reactor classthat adds convenience methods
-
# for creating instances of Qpid::Proton::Connection, Qpid::Proton::Sender
-
# and Qpid::Proton::Receiver.
-
#
-
# @example
-
#
-
1
class Container < Reactor
-
-
1
include Qpid::Proton::Util::Reactor
-
-
1
include Qpid::Proton::Util::UUID
-
-
1
attr_accessor :container_id
-
1
attr_accessor :global_handler
-
-
1
def initialize(handlers, options = {})
-
super(handlers, options)
-
-
# only do the following if we're creating a new instance
-
if !options.has_key?(:impl)
-
@ssl = SSLConfig.new
-
if options[:global_handler]
-
self.global_handler = GlobalOverrides.new(options[:global_handler])
-
else
-
# very ugly, but using self.global_handler doesn't work in the constructor
-
ghandler = Reactor.instance_method(:global_handler).bind(self).call
-
ghandler = GlobalOverrides.new(ghandler)
-
Reactor.instance_method(:global_handler=).bind(self).call(ghandler)
-
end
-
@trigger = nil
-
@container_id = generate_uuid
-
end
-
end
-
-
# Initiates the establishment of an AMQP connection.
-
#
-
# @param options [Hash] A hash of named arguments.
-
#
-
1
def connect(options = {})
-
conn = self.connection(options[:handler])
-
conn.container = self.container_id || generate_uuid
-
connector = Connector.new(conn)
-
conn.overrides = connector
-
if !options[:url].nil?
-
connector.address = URLs.new([options[:url]])
-
elsif !options[:urls].nil?
-
connector.address = URLs.new(options[:urls])
-
elsif !options[:address].nil?
-
connector.address = URLs.new([Qpid::Proton::URL.new(options[:address])])
-
else
-
raise ::ArgumentError.new("either :url or :urls or :address required")
-
end
-
-
connector.heartbeat = options[:heartbeat] if !options[:heartbeat].nil?
-
if !options[:reconnect].nil?
-
connector.reconnect = options[:reconnect]
-
else
-
connector.reconnect = Backoff.new()
-
end
-
-
connector.ssl_domain = SessionPerConnection.new # TODO seems this should be configurable
-
-
conn.open
-
-
return conn
-
end
-
-
1
def _session(context)
-
if context.is_a?(Qpid::Proton::URL)
-
return self._session(self.connect(:url => context))
-
elsif context.is_a?(Qpid::Proton::Session)
-
return context
-
elsif context.is_a?(Qpid::Proton::Connection)
-
if context.session_policy?
-
return context.session_policy.session(context)
-
else
-
return self.create_session(context)
-
end
-
else
-
return context.session
-
end
-
end
-
-
# Initiates the establishment of a link over which messages can be sent.
-
#
-
# @param context [String, URL] The context.
-
# @param opts [Hash] Additional options.
-
# @param opts [String, Qpid::Proton::URL] The target address.
-
# @param opts [String] :source The source address.
-
# @param opts [Boolean] :dynamic
-
# @param opts [Object] :handler
-
# @param opts [Object] :tag_generator The tag generator.
-
# @param opts [Hash] :options Addtional link options
-
#
-
# @return [Sender] The sender.
-
#
-
1
def create_sender(context, opts = {})
-
if context.is_a?(::String)
-
context = Qpid::Proton::URL.new(context)
-
end
-
-
target = opts[:target]
-
if context.is_a?(Qpid::Proton::URL) && target.nil?
-
target = context.path
-
end
-
-
session = self._session(context)
-
-
sender = session.sender(opts[:name] ||
-
id(session.connection.container,
-
target, opts[:source]))
-
sender.source.address = opts[:source] if !opts[:source].nil?
-
sender.target.address = target if target
-
sender.handler = opts[:handler] if !opts[:handler].nil?
-
sender.tag_generator = opts[:tag_generator] if !opts[:tag_gnenerator].nil?
-
self._apply_link_options(opts[:options], sender)
-
sender.open
-
return sender
-
end
-
-
# Initiates the establishment of a link over which messages can be received.
-
#
-
# There are two accepted arguments for the context
-
# 1. If a Connection is supplied then the link is established using that
-
# object. The source, and optionally the target, address can be supplied
-
# 2. If it is a String or a URL then a new Connection is created on which
-
# the link will be attached. If a path is specified, but not the source
-
# address, then the path of the URL is used as the target address.
-
#
-
# The name will be generated for the link if one is not specified.
-
#
-
# @param context [Connection, URL, String] The connection or the address.
-
# @param opts [Hash] Additional otpions.
-
# @option opts [String, Qpid::Proton::URL] The source address.
-
# @option opts [String] :target The target address
-
# @option opts [String] :name The link name.
-
# @option opts [Boolean] :dynamic
-
# @option opts [Object] :handler
-
# @option opts [Hash] :options Additional link options.
-
#
-
# @return [Receiver
-
#
-
1
def create_receiver(context, opts = {})
-
if context.is_a?(::String)
-
context = Qpid::Proton::URL.new(context)
-
end
-
-
source = opts[:source]
-
if context.is_a?(Qpid::Proton::URL) && source.nil?
-
source = context.path
-
end
-
-
session = self._session(context)
-
-
receiver = session.receiver(opts[:name] ||
-
id(session.connection.container,
-
source, opts[:target]))
-
receiver.source.address = source if source
-
receiver.source.dynamic = true if opts.has_key?(:dynamic) && opts[:dynamic]
-
receiver.target.address = opts[:target] if !opts[:target].nil?
-
receiver.handler = opts[:handler] if !opts[:handler].nil?
-
self._apply_link_options(opts[:options], receiver)
-
receiver.open
-
return receiver
-
end
-
-
1
def declare_transaction(context, handler = nil, settle_before_discharge = false)
-
if context.respond_to? :txn_ctl && !context.__send__(:txn_ctl).nil?
-
class << context
-
attr_accessor :txn_ctl
-
end
-
context.txn_ctl = self.create_sender(context, nil, "txn-ctl",
-
InternalTransactionHandler.new())
-
end
-
return Transaction.new(context.txn_ctl, handler, settle_before_discharge)
-
end
-
-
# Initiates a server socket, accepting incoming AMQP connections on the
-
# interface and port specified.
-
#
-
# @param url []
-
# @param ssl_domain []
-
#
-
1
def listen(url, ssl_domain = nil)
-
url = Qpid::Proton::URL.new(url)
-
acceptor = self.acceptor(url.host, url.port)
-
ssl_config = ssl_domain
-
if ssl_config.nil? && (url.scheme == 'amqps') && @ssl
-
ssl_config = @ssl.server
-
end
-
if !ssl_config.nil?
-
acceptor.ssl_domain(ssl_config)
-
end
-
return acceptor
-
end
-
-
1
def do_work(timeout = nil)
-
self.timeout = timeout unless timeout.nil?
-
self.process
-
end
-
-
1
def id(container, remote, local)
-
if !local.nil? && !remote.nil?
-
"#{container}-#{remote}-#{local}"
-
elsif !local.nil?
-
"#{container}-#{local}"
-
elsif !remote.nil?
-
"#{container}-#{remote}"
-
else
-
"#{container}-#{generate_uuid}"
-
end
-
end
-
-
1
def _apply_link_options(options, link)
-
if !options.nil? && !options.empty?
-
if !options.is_a?(::List)
-
options = [Options].flatten
-
end
-
-
options.each {|option| o.apply(link) if o.test(link)}
-
end
-
end
-
-
1
def to_s
-
"#{self.class}<@impl=#{Cproton.pni_address_of(@impl)}>"
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class GlobalOverrides
-
-
1
def initialize(base)
-
@base = base
-
end
-
-
1
def on_unhandled(name, event)
-
event.dispatch(@base) unless self.override?(event)
-
end
-
-
1
def override?(event)
-
conn = event.connection
-
if !conn.nil? && conn.overrides?
-
overrides = conn.overrides
-
result = event.dispatch(overrides)
-
return result
-
end
-
false
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class LinkOption
-
1
def apply(link)
-
end
-
-
# Subclasses should override this to selectively apply an option.
-
1
def test(link)
-
true
-
end
-
end
-
-
1
class AtMostOne < LinkOption
-
1
def apply(link)
-
link.snd_settle_mod = Link::SND_SETTLED
-
end
-
end
-
-
1
class AtLeastOnce < LinkOption
-
1
def apply(link)
-
link.snd_settle_mode = Link::SND_UNSETTLED
-
link.rcv_settle_mode = Link::RCV_FIRST
-
end
-
end
-
-
1
class SenderOption < LinkOption
-
1
def test(link)
-
link.sender?
-
end
-
end
-
-
1
class ReceiverOption < LinkOption
-
1
def test(link)
-
link.receiver?
-
end
-
end
-
-
1
class DynamicNodeProperties < LinkOption
-
1
def initialize(properties = {})
-
@properties = []
-
properties.each do |property|
-
@properties << property.to_sym
-
end
-
end
-
-
1
def apply(link)
-
if link.receiver?
-
link.source.properties.dict = @properties
-
else
-
link.target.properties.dict = @properties
-
end
-
end
-
end
-
-
1
class Filter < ReceiverOption
-
1
def initialize(filter_set = {})
-
@filter_set = filter_set
-
end
-
-
1
def apply(receiver)
-
receiver.source.filter.dict = @filter_set
-
end
-
end
-
-
#class Selector < Filter
-
# def initialize(value, name = 'selector')
-
#
-
# end
-
#end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class Reactor
-
-
1
include Qpid::Proton::Util::Handler
-
-
# @private
-
1
include Qpid::Proton::Util::SwigHelper
-
-
# @private
-
1
PROTON_METHOD_PREFIX = "pn_reactor"
-
-
1
proton_caller :yield
-
-
1
proton_caller :mark
-
-
1
proton_caller :start
-
-
1
proton_caller :stop
-
-
# @private
-
1
include Qpid::Proton::Util::Timeout
-
-
1
include Qpid::Proton::Util::Wrapper
-
-
1
attr_reader :errors
-
-
1
def self.wrap(impl)
-
return nil if impl.nil?
-
-
self.fetch_instance(impl, :pn_reactor_attachments) || Reactor.new(nil, :impl => impl)
-
end
-
-
1
def initialize(handlers, options = {})
-
@impl = options[:impl]
-
if @impl.nil?
-
@impl = Cproton.pn_reactor
-
end
-
if !handlers.nil?
-
[handlers].flatten.each {|handler| self.handler.add(handler)}
-
end
-
@errors = []
-
@handlers = []
-
self.class.store_instance(self, :pn_reactor_attachments)
-
end
-
-
# Returns whether the reactor has any unbuffered data.
-
#
-
# @return [Boolean] True if there is no unbuffered data.
-
#
-
1
def quiesced?
-
Cproton.pn_reactor_quiesced(@impl)
-
end
-
-
1
def on_error(info)
-
self.errors << info
-
self.yield
-
end
-
-
1
def global_handler
-
impl = Cproton.pn_reactor_get_global_handler(@impl)
-
Qpid::Proton::Handler::WrappedHandler.wrap(impl, self.method(:on_error))
-
end
-
-
1
def global_handler=(handler)
-
impl = chandler(handler, self.method(:on_error))
-
Cproton.pn_reactor_set_global_handler(@impl, impl)
-
Cproton.pn_decref(impl)
-
end
-
-
# Returns the timeout period.
-
#
-
# @return [Fixnum] The timeout period, in seconds.
-
#
-
1
def timeout
-
millis_to_timeout(Cproton.pn_reactor_get_timeout(@impl))
-
end
-
-
# Sets the timeout period.
-
#
-
# @param timeout [Fixnum] The timeout, in seconds.
-
#
-
1
def timeout=(timeout)
-
Cproton.pn_reactor_set_timeout(@impl, timeout_to_millis(timeout))
-
end
-
-
1
def handler
-
impl = Cproton.pn_reactor_get_handler(@impl)
-
Qpid::Proton::Handler::WrappedHandler.wrap(impl, self.method(:on_error))
-
end
-
-
1
def handler=(handler)
-
impl = chandler(handler, set.method(:on_error))
-
Cproton.pn_reactor_set_handler(@impl, impl)
-
Cproton.pn_decref(impl)
-
end
-
-
1
def run(&block)
-
self.timeout = 3.14159265359
-
self.start
-
while self.process do
-
if block_given?
-
yield
-
end
-
end
-
self.stop
-
end
-
-
1
def wakeup
-
n = Cproton.pn_reactor_wakeup(@impl)
-
unless n.zero?
-
io = Cproton.pn_reactor_io(@impl)
-
raise IOError.new(Cproton.pn_io_error(io))
-
end
-
end
-
-
1
def process
-
result = Cproton.pn_reactor_process(@impl)
-
if !self.errors.nil? && !self.errors.empty?
-
(0...self.errors.size).each do |index|
-
error_set = self.errors[index]
-
print error.backtrace.join("\n")
-
end
-
raise self.errors.last
-
end
-
return result
-
end
-
-
1
def schedule(delay, task)
-
impl = chandler(task, self.method(:on_error))
-
task = Task.wrap(Cproton.pn_reactor_schedule(@impl, sec_to_millis(delay), impl))
-
Cproton.pn_decref(impl)
-
return task
-
end
-
-
1
def acceptor(host, port, handler = nil)
-
impl = chandler(handler, self.method(:on_error))
-
aimpl = Cproton.pn_reactor_acceptor(@impl, host, "#{port}", impl)
-
Cproton.pn_decref(impl)
-
if !aimpl.nil?
-
return Acceptor.new(aimpl)
-
else
-
io = Cproton.pn_reactor_io(@impl)
-
io_error = Cproton.pn_io_error(io)
-
error_text = Cproton.pn_error_text(io_error)
-
text = "(#{Cproton.pn_error_text(io_error)} (#{host}:#{port}))"
-
raise IOError.new(text)
-
end
-
end
-
-
1
def connection(handler = nil)
-
impl = chandler(handler, self.method(:on_error))
-
conn = Qpid::Proton::Connection.wrap(Cproton.pn_reactor_connection(@impl, impl))
-
Cproton.pn_decref(impl)
-
return conn
-
end
-
-
1
def selectable(handler = nil)
-
impl = chandler(handler, self.method(:on_error))
-
result = Selectable.wrap(Cproton.pn_reactor_selectable(@impl))
-
if !impl.nil?
-
record = Cproton.pn_selectable_attachments(result.impl)
-
Cproton.pn_record_set_handler(record, impl)
-
Cproton.pn_decref(impl)
-
end
-
return result
-
end
-
-
1
def update(sel)
-
Cproton.pn_reactor_update(@impl, sel.impl)
-
end
-
-
1
def push_event(obj, etype)
-
Cproton.pn_collector_put(Cproton.pn_reactor_collector(@impl), Qpid::Proton::Util::RBCTX, Cproton.pn_py2void(obj), etype.number)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class SessionPerConnection
-
-
1
include Qpid::Proton::Util::Reactor
-
-
1
def initialize
-
@default_session = nil
-
end
-
-
1
def session(connection)
-
if @default_session.nil?
-
@default_session = self.create_session
-
@default_session.context = self
-
end
-
return @default_session
-
end
-
-
1
def on_session_remote_close(event)
-
event.connection.close
-
@default_session = nil
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class SSLConfig
-
-
1
def initialize
-
@client = Qpid::Proton::SSLDomain.new(Qpid::Proton::SSLDomain::MODE_CLIENT)
-
@server = Qpid::Proton::SSLDomain.new(Qpid::Proton::SSLDomain::MODE_SERVER)
-
end
-
-
1
def set_credentials(cert_file, key_file, password)
-
@client.set_credentials(cert_file, key_file, password)
-
@server.set_credentials(cert_file, key_file, password)
-
end
-
-
1
def set_trusted_ca_db(certificate_db)
-
@client.set_trusted_ca_db(certificate_db)
-
@server.set_trusted_ca_db(certificate_db)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class Task
-
-
# @private
-
1
include Qpid::Proton::Util::Wrapper
-
-
1
def self.wrap(impl)
-
return nil if impl.nil?
-
self.fetch_instance(impl, :pn_task_attachments) || Task.new(impl)
-
end
-
-
1
def initialize(impl)
-
@impl = impl
-
self.class.store_instance(self, :pn_task_attachments)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Reactor
-
-
1
class URLs
-
-
1
def initialize(values)
-
@values = [values].flatten
-
@iter = @values.each
-
end
-
-
1
def next
-
begin
-
return @iter.next
-
rescue StopIteration
-
@iter = @values.each
-
return @iter.next
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
#--
-
# Patch the Array class to provide methods for adding its contents
-
# to a Qpid::Proton::Data instance.
-
#++
-
-
1
module Qpid::Proton::Types
-
-
# Holds the information for an AMQP Array compound type.
-
#
-
# It holds the type for the array and the descriptor if the
-
# array is described.
-
#
-
# @private
-
#
-
1
class ArrayHeader
-
1
attr_reader :type
-
1
attr_reader :descriptor
-
-
1
def initialize(type, descriptor = nil)
-
27
@type = type
-
27
@descriptor = descriptor
-
end
-
-
# Returns true if the array is described.
-
1
def described?
-
8
!@descriptor.nil?
-
end
-
-
1
def ==(that)
-
2
((@type == that.type) && (@descriptor == that.descriptor))
-
end
-
end
-
-
end
-
-
# @private
-
1
class Array # :nodoc:
-
-
# Used to declare an array as an AMQP array.
-
#
-
# The value, if defined, is an instance of Qpid::Proton::Types::ArrayHeader
-
1
attr_accessor :proton_array_header
-
-
# Returns true if the array is the a Proton described type.
-
1
def proton_described?
-
1
!@proton_array_header.nil? && @proton_array_header.described?
-
end
-
-
# Puts the elements of the array into the specified Qpid::Proton::Data object.
-
1
def proton_put(data)
-
5
raise TypeError, "data object cannot be nil" if data.nil?
-
-
4
if @proton_array_header.nil?
-
1
proton_put_list(data)
-
else
-
3
proton_put_array(data)
-
end
-
end
-
-
1
private
-
-
1
def proton_put_list(data)
-
# create a list, then enter it and add each element
-
1
data.put_list
-
1
data.enter
-
1
each do |element|
-
# get the proton type for the element
-
4
mapping = Qpid::Proton::Codec::Mapping.for_class(element.class)
-
# add the element
-
4
mapping.put(data, element)
-
end
-
# exit the list
-
1
data.exit
-
end
-
-
1
def proton_put_array(data)
-
3
data.put_array(@proton_array_header.described?, @proton_array_header.type)
-
3
data.enter
-
3
if @proton_array_header.described?
-
1
data.symbol = @proton_array_header.descriptor
-
end
-
-
3
each do |element|
-
142
@proton_array_header.type.put(data, element)
-
end
-
-
2
data.exit
-
end
-
-
1
class << self
-
-
# Gets the elements of an array or list out of the specified
-
# Qpid::Proton::Data object.
-
1
def proton_get(data)
-
6
raise TypeError, "can't convert nil into Qpid::Proton::Data" if data.nil?
-
-
5
type = data.type
-
-
5
if type == Qpid::Proton::Codec::LIST
-
1
result = proton_get_list(data)
-
4
elsif type == Qpid::Proton::Codec::ARRAY
-
2
result = proton_get_array(data)
-
else
-
2
raise TypeError, "element is not a list and not an array"
-
end
-
end
-
-
1
private
-
-
1
def proton_get_list(data)
-
1
size = data.list
-
1
raise TypeError, "not a list" unless data.enter
-
1
elements = []
-
1
(0...size).each do
-
4
data.next
-
4
type = data.type
-
4
raise TypeError, "missing next element in list" unless type
-
4
elements << type.get(data)
-
end
-
1
data.exit
-
1
return elements
-
end
-
-
1
def proton_get_array(data)
-
2
count, described, type = data.array
-
-
2
raise TypeError, "not an array" unless data.enter
-
2
elements = []
-
-
2
descriptor = nil
-
-
2
if described
-
1
data.next
-
1
descriptor = data.symbol
-
end
-
-
2
elements.proton_array_header = Qpid::Proton::Types::ArrayHeader.new(type, descriptor)
-
2
(0...count).each do |which|
-
141
if data.next
-
141
etype = data.type
-
141
raise TypeError, "missing next element in array" unless etype
-
141
raise TypeError, "invalid array element: #{etype}" unless etype == type
-
141
elements << type.get(data)
-
end
-
end
-
2
data.exit
-
2
return elements
-
end
-
-
end
-
-
end
-
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Types
-
-
# @private
-
1
class Described
-
-
1
attr_reader :descriptor
-
1
attr_reader :value
-
-
1
def initialize(descriptor, value)
-
@descriptor = descriptor
-
@value = value
-
end
-
-
# Puts the description into the Data object.
-
#
-
# ==== Arguments
-
#
-
# * data - the Qpid::Proton::Data instance
-
#
-
# ==== Examples
-
#
-
# described = Qpid::Proton::Described.new("my-descriptor", "the value")
-
# data = Qpid::Proton::Data.new
-
# ...
-
# described.put(data)
-
#
-
1
def put(data)
-
data.symbol = @descriptor
-
data.string = @value
-
end
-
-
1
def ==(that) # :nodoc:
-
(that.is_a?(Qpid::Proton::Types::Described) &&
-
(self.descriptor == that.descriptor) &&
-
(self.value == that.value))
-
end
-
-
1
def to_s # :nodoc:
-
"descriptor=#{descriptor} value=#{value}"
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
#--
-
# Patch the Hash class to provide methods for adding its contents
-
# to a Qpid::Proton::Data instance.
-
#++
-
-
# @private
-
1
class Hash # :nodoc:
-
-
# Places the contents of the hash into the specified data object.
-
#
-
# ==== Arguments
-
#
-
# * data - the Qpid::Proton::Data instance
-
#
-
# ==== Examples
-
#
-
# data = Qpid::Proton::Data.new
-
# values = {:foo => :bar}
-
# values.proton_data_put(data)
-
#
-
1
def proton_data_put(data)
-
2
raise TypeError, "data object cannot be nil" if data.nil?
-
-
1
data.put_map
-
1
data.enter
-
-
1
each_pair do |key, value|
-
4
type = Qpid::Proton::Codec::Mapping.for_class(key.class)
-
4
type.put(data, key)
-
4
type = Qpid::Proton::Codec::Mapping.for_class(value.class)
-
4
type.put(data, value)
-
end
-
-
1
data.exit
-
end
-
-
1
class << self
-
-
1
def proton_data_get(data)
-
3
raise TypeError, "data object cannot be nil" if data.nil?
-
-
2
type = data.type
-
-
2
raise TypeError, "element is not a map" unless type == Qpid::Proton::Codec::MAP
-
-
1
count = data.map
-
1
result = {}
-
-
1
data.enter
-
-
1
(0...(count/2)).each do
-
4
data.next
-
4
type = data.type
-
4
key = type.get(data)
-
4
data.next
-
4
type = data.type
-
4
value = type.get(data)
-
4
result[key] = value
-
end
-
-
1
data.exit
-
-
1
return result
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Types
-
-
# @private
-
1
def self.is_valid_utf?(value)
-
# In Ruby 1.9+ we have encoding methods that can check the content of
-
# the string, so use them to see if what we have is unicode. If so,
-
# good! If not, then just treat is as binary.
-
#
-
# No such thing in Ruby 1.8. So there we need to use Iconv to try and
-
# convert it to unicode. If it works, good! But if it raises an
-
# exception then we'll treat it as binary.
-
168
if RUBY_VERSION < "1.9"
-
return true if value.isutf8
-
return false
-
else
-
return true if (value.encoding == "UTF-8" ||
-
168
value.encode("UTF-8").valid_encoding?)
-
-
return false
-
end
-
end
-
-
# UTFString lets an application explicitly state that a
-
# string of characters is to be UTF-8 encoded.
-
#
-
1
class UTFString < ::String
-
-
1
def initialize(value)
-
168
if !Qpid::Proton::Types.is_valid_utf?(value)
-
raise RuntimeError.new("invalid UTF string")
-
end
-
-
168
super(value)
-
end
-
-
end
-
-
# BinaryString lets an application explicitly declare that
-
# a string value represents arbitrary data.
-
#
-
1
class BinaryString < ::String; end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# This mixin provides a method for mapping from an underlying Proton
-
# C library class to a Ruby class.
-
#
-
# @private
-
#
-
1
module ClassWrapper
-
-
1
WRAPPERS =
-
{
-
"pn_void" => proc {|x| Cproton.pn_void2rb(x)},
-
"pn_rbref" => proc {|x| Cproton.pn_void2rb(x)},
-
"pn_connection" => proc {|x| Qpid::Proton::Connection.wrap(Cproton.pn_cast_pn_connection(x))},
-
"pn_session" => proc {|x| Qpid::Proton::Session.wrap(Cproton.pn_cast_pn_session(x))},
-
"pn_link" => proc {|x| Qpid::Proton::Link.wrap(Cproton.pn_cast_pn_link(x))},
-
"pn_delivery" => proc {|x| Qpid::Proton::Delivery.wrap(Cproton.pn_cast_pn_delivery(x))},
-
"pn_transport" => proc {|x| Qpid::Proton::Transport.wrap(Cproton.pn_cast_pn_transport(x))},
-
"pn_selectable" => proc {|x| Qpid::Proton::Selectable.wrap(Cproton.pn_cast_pn_selectable(x))},
-
"pn_reactor" => proc {|x| Qpid::Proton::Reactor::Reactor.wrap(Cproton.pn_cast_pn_reactor(x))},
-
"pn_task" => proc {|x| Qpid::Proton::Reactor::Task.wrap(Cproton.pn_cast_pn_task(x))},
-
}
-
-
1
def class_wrapper(clazz, c_impl, &block)
-
proc_func = WRAPPERS[clazz]
-
if !proc_func.nil?
-
proc_func.yield(c_impl)
-
elsif block_given?
-
yield(c_impl)
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
1
class Condition
-
-
1
def initialize(name, description = nil, info = nil)
-
@name = name
-
@description = description
-
@info = info
-
end
-
-
# @private
-
1
def to_s
-
"Condition(#{@name}, #{@description}, #{@info})"
-
end
-
-
# @private
-
1
def ==(other)
-
((other.class = self.class) &&
-
(other.name == self.name) &&
-
(other.description == self.description) &&
-
(other.info == self.info))
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# Provides a means for defining constant values within the namespace
-
# of a class.
-
#
-
# If the class has defined the class method, :post_add_constant, then that
-
# method will be invoked after each new item is added. It must be defined
-
# *before* any constants are defined.
-
#
-
# ==== Example
-
#
-
# class GrammarComponent
-
#
-
# include Qpid::Proton::Constants
-
#
-
# def self.post_add_constant(key, value)
-
# @terminal << value if value.terminal?
-
# @nonterminal << value if !value.terminal? && !value.rule
-
# @rule << value if value.rule
-
# end
-
#
-
# self.add_constant :LEFT_PARENTHESIS, new GrammarComponent("(", :terminal)
-
# self.add_constant :RIGHT_PARENTHESIS, new GrammarComponent(")", :terminal)
-
# self.add_constant :ELEMENT, new GrammarComponent("E", :rule)
-
#
-
# def initialize(component, type)
-
# @component = component
-
# @type = type
-
# end
-
#
-
# def terminal?; @type == :terminal; end
-
#
-
# def rule?; @type == :rule; end
-
#
-
# end
-
#
-
# @private
-
#
-
1
module Constants
-
-
1
def self.included(base)
-
1
base.extend ClassMethods
-
end
-
-
1
module ClassMethods
-
-
1
def add_constant(key, value)
-
5
self.const_set(key, value)
-
-
5
@pn_by_value ||= {}
-
5
@pn_by_value[value] = key
-
-
5
if self.respond_to? :post_add_constant
-
self.post_add_constant(key, value)
-
end
-
end
-
-
1
def by_value(value)
-
(@pn_by_value || {})[value]
-
end
-
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# @private
-
1
module Engine
-
-
# Convenience method to receive messages from a delivery.
-
#
-
# @param delivery [Qpid::Proton::Delivery] The delivery.
-
# @param message [Qpid::Proton::Message] The message to use.
-
#
-
# @return [Qpid::Proton::Message] the message
-
#
-
1
def self.receive_message(delivery, msg = nil)
-
msg = Qpid::Proton::Message.new if msg.nil?
-
msg.decode(delivery.link.receive(delivery.pending))
-
delivery.link.advance
-
return msg
-
end
-
-
1
def data_to_object(data_impl) # :nodoc:
-
object = nil
-
unless data_impl.nil?
-
data = Qpid::Proton::Codec::Data.new(data_impl)
-
data.rewind
-
data.next
-
object = data.object
-
data.rewind
-
end
-
return object
-
end
-
-
1
def object_to_data(object, data_impl) # :nodoc:
-
unless object.nil?
-
data = Data.new(data_impl)
-
data.object = object
-
end
-
end
-
-
1
def condition_to_object(condition) # :nodoc:
-
result = nil
-
if Cproton.pn_condition_is_set(condition)
-
result = Condition.new(Cproton.pn_condition_get_name(condition),
-
Cproton.pn_condition_get_description(condition),
-
data_to_object(Cproton.pn_condition_info(condition)))
-
end
-
return result
-
end
-
-
1
def object_to_condition(object, condition) # :nodoc:
-
Cproton.pn_condition_clear(condition)
-
unless object.nil?
-
Cproton.pn_condition_set_name(condition, object.name)
-
Cproton.pn_condition_set_description(condition, object.description)
-
info = Data.new(Cproton.pn_condition_info(condition))
-
if object.info?
-
info.object = object.info
-
end
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# Provides mixin functionality for dealing with exception conditions.
-
#
-
# @private
-
1
module ErrorHandler
-
-
1
def self.included(base)
-
7
base.extend(self)
-
-
7
unless defined? base.to_be_wrapped
-
7
class << base
-
7
@@to_be_wrapped = []
-
end
-
end
-
-
7
define_method :method_added do |name|
-
155
if (!@@to_be_wrapped.nil?) && (@@to_be_wrapped.include? name)
-
22
@@to_be_wrapped.delete name
-
22
create_exception_handler_wrapper(name)
-
end
-
end
-
end
-
-
1
def can_raise_error(method_names, options = {})
-
12
error_class = options[:error_class]
-
12
below = options[:below] || 0
-
# coerce the names to be an array
-
12
Array(method_names).each do |method_name|
-
# if the method doesn't already exist then queue this aliasing
-
32
unless self.method_defined? method_name
-
23
@@to_be_wrapped ||= []
-
23
@@to_be_wrapped << method_name
-
else
-
9
create_exception_handler_wrapper(method_name, error_class, below)
-
end
-
end
-
end
-
-
1
def create_exception_handler_wrapper(method_name, error_class = nil, below = 0)
-
31
original_method_name = method_name.to_s
-
31
wrapped_method_name = "_excwrap_#{original_method_name}"
-
31
alias_method wrapped_method_name, original_method_name
-
31
define_method original_method_name do |*args, &block|
-
# need to get a reference to the method object itself since
-
# calls to Class.send interfere with Messenger.send
-
139
method = self.method(wrapped_method_name.to_sym)
-
139
rc = method.call(*args, &block)
-
131
check_for_error(rc, error_class) if rc < below
-
120
return rc
-
end
-
end
-
-
# Raises an Proton-specific error if a return code is non-zero.
-
#
-
# Expects the class to provide an +error+ method.
-
1
def check_for_error(code, error_class = nil)
-
-
20
raise ::ArgumentError.new("Invalid error code: #{code}") if code.nil?
-
-
19
return code if code > 0
-
-
18
case(code)
-
-
when Qpid::Proton::Error::NONE
-
return
-
-
when Qpid::Proton::Error::EOS
-
1
raise Qpid::Proton::EOSError.new(self.error)
-
-
when Qpid::Proton::Error::ERROR
-
1
raise Qpid::Proton::ProtonError.new(self.error)
-
-
when Qpid::Proton::Error::OVERFLOW
-
1
raise Qpid::Proton::OverflowError.new(self.error)
-
-
when Qpid::Proton::Error::UNDERFLOW
-
1
raise Qpid::Proton::UnderflowError.new(self.error)
-
-
when Qpid::Proton::Error::ARGUMENT
-
2
raise Qpid::Proton::ArgumentError.new(self.error)
-
-
when Qpid::Proton::Error::STATE
-
raise Qpid::Proton::StateError.new(self.error)
-
-
when Qpid::Proton::Error::TIMEOUT
-
11
raise Qpid::Proton::TimeoutError.new(self.error)
-
-
when Qpid::Proton::Error::INPROGRESS
-
return
-
-
when Qpid::Proton::Error::INTERRUPTED
-
raise Qpid::Proton::InterruptedError.new(self.error)
-
-
when Qpid::Proton::Error::INPROGRESS
-
raise Qpid::Proton::InProgressError.new(self.error)
-
-
else
-
-
raise ::ArgumentError.new("Unknown error code: #{code}")
-
-
end
-
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# @private
-
1
module Handler
-
-
1
def chandler(handler, on_error)
-
return nil if handler.nil?
-
-
if handler.instance_of?(Qpid::Proton::Handler::WrappedHandler)
-
impl = handler.impl
-
Cproton.pn_incref(impl)
-
return impl
-
else
-
cadaptor = Qpid::Proton::Handler::CAdaptor.new(handler, on_error)
-
rbhandler = Cproton.pn_rbhandler(cadaptor)
-
return rbhandler
-
end
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
1
module Reactor
-
-
1
def create_session(connection, handler = nil)
-
session = connection.session
-
session.open
-
return session
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# Provides helper functions for writing wrapper functions for the
-
# underlying C APIs.
-
#
-
# Before defining any mutators the class must define the name of the
-
# prefix for methods with the constant PROTON_METOD_PREFIX.
-
#
-
# == Mutators, Setters And Getters
-
#
-
# There are three types of wrappers that are supported:
-
#
-
# [proton_writer] Defines a set-only method for the named attribute.
-
# [proton_reader] Defines a get-only method for the named attribute.
-
# [proton_accessor] Defines both a set- and a get-method for the named
-
# attribute.
-
# [proton_caller] A simple wrapper for calling an underlying method,
-
# avoids repetitive boiler plate coding.
-
#
-
# == Arguments
-
#
-
# [:is_or_get => {:is, :get}] For both the getter and the mutator types
-
# you can also declare that the method uses "is" instead of "get" in the
-
# underlying API. Such methods are then defined with "?"
-
#
-
# @example
-
# class Terminus
-
#
-
# include WrapperHelper
-
#
-
# PROTON_METHOD_PREFIX = "pn_terminus"
-
#
-
# # add methods "type" and "type=" that call "pn_terminus_{get,set}_type"
-
# proton_accessor :type
-
#
-
# # adds the method "dynamic?" that calls "pn_terminus_is_dynamic"
-
# proton_accessor :dynamic, :is_or_get => :is
-
#
-
# # adds a method named "foo" that calls "pn_terminus_foo"
-
# proton_caller :foo
-
#
-
# end
-
#
-
# @private
-
1
module SwigHelper
-
-
1
def self.included(base)
-
11
base.extend ClassMethods
-
end
-
-
1
module ClassMethods # :nodoc:
-
-
1
def create_wrapper_method(name, proton_method, with_arg = false)
-
93
if with_arg
-
20
define_method "#{name}" do |arg|
-
Cproton.__send__(proton_method.to_sym, @impl, arg)
-
end
-
else
-
73
define_method "#{name}" do
-
Cproton.__send__(proton_method.to_sym, @impl)
-
end
-
end
-
end
-
-
# Defines a method that calls an underlying C library function.
-
1
def proton_caller(name, options = {})
-
43
proton_method = "#{self::PROTON_METHOD_PREFIX}_#{name}"
-
# drop the trailing '?' if this is a property method
-
43
proton_method = proton_method[0..-2] if proton_method.end_with? "?"
-
43
create_wrapper_method(name, proton_method)
-
end
-
-
1
def proton_writer(name, options = {})
-
20
proton_method = "#{self::PROTON_METHOD_PREFIX}_set_#{name}"
-
20
create_wrapper_method("#{name}=", proton_method, true)
-
end
-
-
1
def proton_reader(name, options = {})
-
30
an_is_method = options[:is_or_get] == :is
-
30
prefix = (an_is_method) ? "is" : "get"
-
30
proton_method = "#{self::PROTON_METHOD_PREFIX}_#{prefix}_#{name}"
-
30
name = "#{name}?" if an_is_method
-
30
create_wrapper_method(name, proton_method)
-
end
-
-
1
def proton_accessor(name, options = {})
-
20
proton_writer(name, options)
-
20
proton_reader(name, options)
-
end
-
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# Provides methods for converting between milliseconds, seconds
-
# and timeout values.
-
#
-
# @private
-
1
module Timeout
-
-
1
def sec_to_millis(s)
-
return (s * 1000).to_int
-
end
-
-
1
def millis_to_sec(ms)
-
return (ms.to_f / 1000.0).to_int
-
end
-
-
1
def timeout_to_millis(s)
-
return Cproton::PN_MILLIS_MAX if s.nil?
-
-
return sec_to_millis(s)
-
end
-
-
1
def millis_to_timeout(ms)
-
return nil if ms == Cproton::PN_MILLIS_MAX
-
-
return millis_to_sec(ms)
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
1
module UUID
-
-
1
def generate_uuid
-
# generate a UUID based on what APIs are available with the current
-
# version of Ruby
-
SecureRandom.uuid
-
end
-
-
end
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# The major version for the underlying Proton library.
-
# @private
-
1
VERSION_MAJOR = Cproton::PN_VERSION_MAJOR
-
-
# The minor version for the underlying Proton library.
-
# @private
-
1
VERSION_MINOR = Cproton::PN_VERSION_MINOR
-
-
end
-
#--
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#++
-
-
1
module Qpid::Proton::Util
-
-
# @private
-
1
module Wrapper
-
-
# @private
-
1
def impl=(impl)
-
@impl = impl
-
end
-
-
# @private
-
1
def impl
-
@impl
-
end
-
-
1
def self.registry
-
@registry ||= {}
-
end
-
-
1
def self.included(base)
-
12
base.extend(ClassMethods)
-
end
-
-
# Adds methods to the target class for storing and retrieving pure Ruby
-
# wrappers to underlying Proton structures.
-
#
-
# Such wrappers are stored in a registry using a key. The key is then
-
# attached to the Proton structure as a record. That record lives for as
-
# long as the Proton structure lives, and when the structure is released
-
# the record acts as hook to also delete the Ruby wrapper object from the
-
# registry.
-
#
-
# @private
-
#
-
1
module ClassMethods
-
-
# @private
-
1
def get_key(impl)
-
("%032x" % Cproton.pni_address_of(impl))
-
end
-
-
# Stores the given object for later retrieval.
-
#
-
# @param object [Object] The object.
-
# @param attachment_method [Symbol] The Proton attachment method.
-
#
-
1
def store_instance(object, attachment_method = nil)
-
# ensure the impl has a reference to the wrapper object
-
object.impl.instance_eval { @proton_wrapper = object }
-
registry_key = get_key(object.impl)
-
unless attachment_method.nil?
-
record = Cproton.__send__(attachment_method, object.impl)
-
rbkey = Cproton.Pn_rbkey_new
-
Cproton.Pn_rbkey_set_registry(rbkey, Cproton.pn_rb2void(Qpid::Proton::Util::Wrapper.registry))
-
Cproton.Pn_rbkey_set_method(rbkey, "delete")
-
Cproton.Pn_rbkey_set_key_value(rbkey, registry_key)
-
Cproton.pn_record_def(record, RBCTX, Cproton.Pn_rbkey__class());
-
Cproton.pn_record_set(record, RBCTX, rbkey)
-
end
-
Qpid::Proton::Util::Wrapper.registry[registry_key] = object
-
end
-
-
# Retrieves the wrapper object with the supplied Proton struct.
-
#
-
# @param impl [Object] The wrapper for the Proton struct.
-
# @param attachment_method [Symbol] The Proton attachment method.
-
#
-
# @return [Object] The Ruby wrapper object.
-
#
-
1
def fetch_instance(impl, attachment_method = nil)
-
# if the impl has a wrapper already attached, then return it
-
if impl.instance_variable_defined?(:@proton_wrapper)
-
return impl.instance_variable_get(:@proton_wrapper)
-
end
-
unless attachment_method.nil?
-
record = Cproton.__send__(attachment_method, impl)
-
rbkey = Cproton.pni_void2rbkey(Cproton.pn_record_get(record, RBCTX))
-
# if we don't have a key, then we don't have an object
-
return nil if rbkey.nil?
-
registry_key = Cproton.Pn_rbkey_get_key_value(rbkey)
-
else
-
registry_key = get_key(impl)
-
end
-
# if the object's not in the registry then return
-
return nil unless Qpid::Proton::Util::Wrapper.registry.has_key?(registry_key)
-
-
result = Qpid::Proton::Util::Wrapper.registry[registry_key]
-
# result = nil unless result.weakref_alive?
-
if result.nil?
-
raise Qpid::Proton::ProtonError.new("missing object for key=#{registry_key}")
-
else
-
# update the impl since the Swig wrapper for it may have changed
-
result.impl = impl
-
end
-
return result
-
end
-
-
end
-
-
end
-
-
# @private
-
1
RBCTX = Wrapper.hash.to_i
-
-
end
-
#
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#
-
-
1
module Qpid
-
-
1
module Proton
-
-
1
class ExceptionHandlingClass
-
1
include Qpid::Proton::Util::ErrorHandler
-
-
1
def error
-
6
"This is a test error: #{Time.new}"
-
end
-
end
-
-
1
describe "The exception handling mixin" do
-
-
1
before (:each) do
-
9
@handler = Qpid::Proton::ExceptionHandlingClass.new
-
end
-
-
1
it "does not raise an error on a zero code" do
-
1
expect {
-
1
@handler.check_for_error(0)
-
}.to_not raise_error
-
end
-
-
1
it "raises EOS on PN_EOS" do
-
1
expect {
-
1
@handler.check_for_error(Qpid::Proton::Error::EOS)
-
}.to raise_error(Qpid::Proton::EOSError)
-
end
-
-
1
it "raises Error on PN_ERR" do
-
1
expect {
-
1
@handler.check_for_error(Qpid::Proton::Error::ERROR)
-
}.to raise_error(Qpid::Proton::ProtonError)
-
end
-
-
1
it "raises Overflow on PN_OVERFLOW" do
-
1
expect {
-
1
@handler.check_for_error(Qpid::Proton::Error::OVERFLOW)
-
}.to raise_error(Qpid::Proton::OverflowError)
-
end
-
-
1
it "raises Underflow on PN_UNDERFLOW" do
-
1
expect {
-
1
@handler.check_for_error(Qpid::Proton::Error::UNDERFLOW)
-
}.to raise_error(Qpid::Proton::UnderflowError)
-
end
-
-
1
it "raises Argument on PN_ARG_ERR" do
-
1
expect {
-
1
@handler.check_for_error(Qpid::Proton::Error::ARGUMENT)
-
}.to raise_error(Qpid::Proton::ArgumentError)
-
end
-
-
1
it "raises Timeout on PN_TIMEOUT" do
-
1
expect {
-
1
@handler.check_for_error(Qpid::Proton::Error::TIMEOUT)
-
}.to raise_error(Qpid::Proton::TimeoutError)
-
end
-
-
1
it "raises an Ruby ArgumentError on a nil code" do
-
1
expect {
-
1
@handler.check_for_error(nil)
-
}.to raise_error(::ArgumentError)
-
end
-
-
1
it "raises a Ruby ArgumentError on an unknown value" do
-
1
expect {
-
1
@handler.check_for_error("farkle")
-
}.to raise_error(::ArgumentError)
-
end
-
-
end
-
-
end
-
-
end
-
#
-
# Licensed to the Apache Software Foundation (ASF) under one
-
# or more contributor license agreements. See the NOTICE file
-
# distributed with this work for additional information
-
# regarding copyright ownership. The ASF licenses this file
-
# to you under the Apache License, Version 2.0 (the
-
# "License"); you may not use this file except in compliance
-
# with the License. You may obtain a copy of the License at
-
#
-
# http://www.apache.org/licenses/LICENSE-2.0
-
#
-
# Unless required by applicable law or agreed to in writing,
-
# software distributed under the License is distributed on an
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-
# KIND, either express or implied. See the License for the
-
# specific language governing permissions and limitations
-
# under the License.
-
#
-
-
1
require "spec_helper"
-
-
1
describe "The extended hash type" do
-
-
1
before :each do
-
4
@data = Qpid::Proton::Codec::Data.new
-
4
@hash = random_hash(rand(128) + 64)
-
end
-
-
1
it "raises an error when put into a nil Data instance" do
-
1
expect {
-
1
@hash.proton_data_put(nil)
-
}.to raise_error(TypeError)
-
end
-
-
1
it "can be put into an instance of Data" do
-
1
@hash.proton_data_put(@data)
-
1
result = Hash.proton_data_get(@data)
-
1
expect(result.keys).to match_array(@hash.keys)
-
1
expect(result.values).to match_array(@hash.values)
-
end
-
-
1
it "raises an error when retrieved from a nil Data instance" do
-
1
expect {
-
1
Hash.proton_data_get(nil)
-
}.to raise_error(TypeError)
-
end
-
-
1
it "raises an error when trying to get what is not a Hash" do
-
1
@data.string = random_string(128)
-
1
@data.rewind
-
-
1
expect {
-
1
Hash.proton_data_get(@data)
-
}.to raise_error(TypeError)
-
end
-
-
end