Class: Qpid::Management::BrokerObject
- Inherits:
-
Object
- Object
- Qpid::Management::BrokerObject
- Defined in:
- lib/qpid_management/broker_object.rb
Overview
Representation of an object in the broker retrieved via QMF
Direct Known Subclasses
Acl, Binding, Bridge, Broker, Cluster, Connection, Exchange, HaBroker, Link, Memory, Queue, Session, Subscription
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Class Method Summary collapse
-
.qmf_class(clazz) ⇒ String
Helper method to convert a Class to its QMF name counterpart.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Exposes data from the QMF response.
-
#created_at ⇒ Time
Returns the time at which this object was created.
-
#deleted_at ⇒ Time
Returns the time at which this object was deleted.
-
#id ⇒ String
Returns the full object id.
-
#initialize(agent, content) ⇒ BrokerObject
constructor
Creates a new BrokerObject.
-
#invoke_method(*args) ⇒ Object
Invokes a QMF method.
-
#method_missing(method, *args, &block) ⇒ Object
Exposes data from the QMF response via methods, e.g.
-
#refresh! ⇒ Object
Refreshes the information associated with this instance by requerying the broker.
-
#short_id ⇒ String
Returns the short object id, i.e.
- #to_s ⇒ Object
-
#updated_at ⇒ Time
Returns the time at which this object was last updated.
Constructor Details
#initialize(agent, content) ⇒ BrokerObject
Creates a new BrokerObject
28 29 30 31 32 |
# File 'lib/qpid_management/broker_object.rb', line 28 def initialize(agent, content) @agent = agent @content = content @values = content['_values'] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Exposes data from the QMF response via methods, e.g. queue.msgDepth
109 110 111 112 113 |
# File 'lib/qpid_management/broker_object.rb', line 109 def method_missing(method, *args, &block) key = method.to_s return self[key] if args.empty? and not self[key].nil? super end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
23 24 25 |
# File 'lib/qpid_management/broker_object.rb', line 23 def content @content end |
Class Method Details
.qmf_class(clazz) ⇒ String
Helper method to convert a Class to its QMF name counterpart. For example, QpidConfig::Connection will be converted to connection.
56 57 58 |
# File 'lib/qpid_management/broker_object.rb', line 56 def self.qmf_class(clazz) clazz.name.split(/::/).last.downcase end |
Instance Method Details
#[](key) ⇒ Object
Exposes data from the QMF response
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/qpid_management/broker_object.rb', line 92 def [](key) return nil unless @values.has_key?(key) value = @values[key] if value.is_a?(Hash) and value.has_key?('_object_name') full_name = value['_object_name'] colon = full_name.index(':') unless colon.nil? full_name = full_name[colon+1..-1] colon = full_name.index(':') return full_name[colon+1..-1] unless colon.nil? end end return value end |
#created_at ⇒ Time
Returns the time at which this object was created
72 73 74 |
# File 'lib/qpid_management/broker_object.rb', line 72 def created_at Time.at(content['_create_ts'] / 1000000000.0) end |
#deleted_at ⇒ Time
Returns the time at which this object was deleted. Only ever applies to BrokerObject instances created from a QMF event.
79 80 81 |
# File 'lib/qpid_management/broker_object.rb', line 79 def deleted_at Time.at(content['_delete_ts'] / 1000000000.0) end |
#id ⇒ String
Returns the full object id
48 49 50 |
# File 'lib/qpid_management/broker_object.rb', line 48 def id @content['_object_id']['_object_name'] end |
#invoke_method(*args) ⇒ Object
Invokes a QMF method
121 122 123 |
# File 'lib/qpid_management/broker_object.rb', line 121 def invoke_method(*args) @agent.invoke_method(*args) end |
#refresh! ⇒ Object
Refreshes the information associated with this instance by requerying the broker
36 37 38 39 40 41 42 43 44 |
# File 'lib/qpid_management/broker_object.rb', line 36 def refresh! refreshed = @agent.named_object(self.class, id) if refreshed @content = refreshed.content @values = @content['_values'] else raise ObjectDeletedError end end |
#short_id ⇒ String
Returns the short object id, i.e. without the leading org.apache.qpid.broker:<class name>:
62 63 64 65 66 67 68 |
# File 'lib/qpid_management/broker_object.rb', line 62 def short_id clazz = BrokerObject.qmf_class(self.class) if id =~ /org.apache.qpid.broker:#{clazz}:(.*)/ return $1; end return nil end |
#to_s ⇒ Object
115 116 117 |
# File 'lib/qpid_management/broker_object.rb', line 115 def to_s @values.to_s end |
#updated_at ⇒ Time
Returns the time at which this object was last updated
85 86 87 |
# File 'lib/qpid_management/broker_object.rb', line 85 def updated_at Time.at(content['_update_ts'] / 1000000000.0) end |