class Qpid::Proton::Condition

An AMQP error condition.

An error sent across an AMQP connection has a name, description and optional extra info. The {Connectin}, {Session} and {Link} endpoint classes all have a condition method to check for errors.

{Condition} can also be raised as an exception.

Attributes

description[R]
info[R]
name[R]

Public Class Methods

convert(obj, default_name="error") click to toggle source

Convert an object to a condition. @param obj the object to turn into a condition @param default_name name to use if obj does not imply a name @return [Condition] Conversion depends on the type of obj

  • Condition: return obj

  • Exception: return Condition(obj.class.name, obj.to_s)

  • String-like: return String.try_convert(obj)

  • nil: return nil

@raise ::ArgumentError if obj is not convertible to {Condition}

# File lib/core/condition.rb, line 60
def self.convert(obj, default_name="error")
  case obj
  when nil then nil
  when Condition then obj
  when Exception then Condition.new(obj.class.name, obj.to_s)
  when SWIG::TYPE_p_pn_condition_t
    if Cproton.pn_condition_is_set(obj)
      Condition.new(Cproton.pn_condition_get_name(obj),
                    Cproton.pn_condition_get_description(obj),
                    Codec::Data.to_object(Cproton.pn_condition_info(obj)))
    end
  else
    raise ::ArgumentError, "can't convert #{obj.class.name} to #{self.class.name}" unless obj.respond_to? :to_str
    Condition.new(default_name, obj.to_str)
  end
end
new(name, description = nil, info = nil) click to toggle source
Calls superclass method
# File lib/core/condition.rb, line 33
def initialize(name, description = nil, info = nil)
  @name = name
  @description = description
  @info = info
  super(to_s)
end

Private Class Methods

assign(impl, cond) click to toggle source
# File lib/core/condition.rb, line 79
def self.assign(impl, cond)
  Cproton.pn_condition_clear(impl)
  if cond
    cond = self.convert(cond)
    Cproton.pn_condition_set_name(impl, cond.name) if cond.name
    Cproton.pn_condition_set_description(impl, cond.description) if cond.description
    Codec::Data.from_object(Cproton.pn_condition_info(impl), cond.info) if cond.info
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/core/condition.rb, line 44
def ==(other)
  ((other.is_a? Condition) &&
   (other.name == self.name) &&
   (other.description == self.description) &&
   (other.info == self.info))
end
inspect() click to toggle source
# File lib/core/condition.rb, line 42
def inspect() "#{self.class.name}(#{@name.inspect}, #{@description.inspect}, #{@info.inspect})"; end
to_s() click to toggle source
# File lib/core/condition.rb, line 40
def to_s() "#{@name}: #{@description}"; end