diff options
author | Robert Gemmell <robbie@apache.org> | 2015-06-25 10:22:51 +0000 |
---|---|---|
committer | Robert Gemmell <robbie@apache.org> | 2015-06-25 10:22:51 +0000 |
commit | 32ae758bc2e8fd962b66a4ab6341b14009f1907e (patch) | |
tree | 2f4d8174813284a6ea58bb6b7f6520aa92287476 /qpid/tools/src/ruby/qpid_management/lib/qpid_management/broker_object.rb | |
parent | 116d91ad7825a98af36a869fc751206fbce0c59f (diff) | |
parent | f7e896076143de4572b4f1f67ef0765125f2498d (diff) | |
download | qpid-python-32ae758bc2e8fd962b66a4ab6341b14009f1907e.tar.gz |
NO-JIRA: create branch for qpid-cpp 0.34 RC process
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid-cpp-0.34-rc@1687469 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/tools/src/ruby/qpid_management/lib/qpid_management/broker_object.rb')
-rw-r--r-- | qpid/tools/src/ruby/qpid_management/lib/qpid_management/broker_object.rb | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/qpid/tools/src/ruby/qpid_management/lib/qpid_management/broker_object.rb b/qpid/tools/src/ruby/qpid_management/lib/qpid_management/broker_object.rb new file mode 100644 index 0000000000..fbbe5ff6e2 --- /dev/null +++ b/qpid/tools/src/ruby/qpid_management/lib/qpid_management/broker_object.rb @@ -0,0 +1,126 @@ +# 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. +# + +module Qpid + module Management + # Representation of an object in the broker retrieved via QMF + class BrokerObject + attr_reader :content + + # Creates a new BrokerObject + # @param [BrokerAgent] agent the agent used to query the data from the broker + # @param [Hash] content the raw QMF response data from the broker + def initialize(agent, content) + @agent = agent + @content = content + @values = content['_values'] + end + + # Refreshes the information associated with this instance by requerying the broker + # @raise [ObjectDeletedError] if the object has been deleted + def refresh! + refreshed = @agent.named_object(self.class, id) + if refreshed + @content = refreshed.content + @values = @content['_values'] + else + raise ObjectDeletedError + end + end + + # Returns the full object id + # @return [String] the full object id + def id + @content['_object_id']['_object_name'] + end + + # Helper method to convert a Class to its QMF name counterpart. For + # example, QpidConfig::Connection will be converted to connection. + # @param [Class] clazz the Class to convert + # @return [String] the converted QMF name counterpart for this Class + def self.qmf_class(clazz) + clazz.name.split(/::/).last.downcase + end + + # Returns the short object id, i.e. without the leading org.apache.qpid.broker:<class name>: + # @return [String] the short object id + def short_id + clazz = BrokerObject.qmf_class(self.class) + if id =~ /org.apache.qpid.broker:#{clazz}:(.*)/ + return $1; + end + return nil + end + + # Returns the time at which this object was created + # @return [Time] the time at which this object was created + def created_at + Time.at(content['_create_ts'] / 1000000000.0) + end + + # Returns the time at which this object was deleted. Only ever applies to + # BrokerObject instances created from a QMF event. + # @return [Time] the time at which this object was deleted + def deleted_at + Time.at(content['_delete_ts'] / 1000000000.0) + end + + # Returns the time at which this object was last updated + # @return [Time] the time at which this object was last updated + def updated_at + Time.at(content['_update_ts'] / 1000000000.0) + end + + # Exposes data from the QMF response + # @param [String] key the key to look up a value, e.g. msgDepth for a queue + # @return the value associated with the key, or nil if not found + 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 + + # Exposes data from the QMF response via methods, e.g. queue.msgDepth + def method_missing(method, *args, &block) + key = method.to_s + return self[key] if args.empty? and not self[key].nil? + super + end + + def to_s + @values.to_s + end + + # Invokes a QMF method + # @see BrokerAgent#invoke_method + def invoke_method(*args) + @agent.invoke_method(*args) + end + end + end +end |