Exception: Qpid::Proton::Condition

Inherits:
ProtonError
  • Object
show all
Defined in:
lib/core/condition.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description = nil, info = nil) ⇒ Condition

Returns a new instance of Condition



33
34
35
36
37
38
# File 'lib/core/condition.rb', line 33

def initialize(name, description = nil, info = nil)
  @name = name
  @description = description
  @info = info
  super(to_s)
end

Instance Attribute Details

#description (readonly)



31
32
33
# File 'lib/core/condition.rb', line 31

def description
  @description
end

#info (readonly)



31
32
33
# File 'lib/core/condition.rb', line 31

def info
  @info
end

#name (readonly)



31
32
33
# File 'lib/core/condition.rb', line 31

def name
  @name
end

Class Method Details

.convert(obj, default_name = "error") ⇒ Condition

Convert an object to a condition.

  • Condition: return obj

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

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

  • nil: return nil

Parameters:

  • obj

    the object to turn into a condition

  • default_name (defaults to: "error")

    name to use if obj does not imply a name

Returns:

  • (Condition)

    Conversion depends on the type of obj

Raises:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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

Instance Method Details

#==(other)



44
45
46
47
48
49
# 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



42
# File 'lib/core/condition.rb', line 42

def inspect() "#{self.class.name}(#{@name.inspect}, #{@description.inspect}, #{@info.inspect})"; end

#to_s



40
# File 'lib/core/condition.rb', line 40

def to_s() "#{@name}: #{@description}"; end