Class: Qpid::Management::BrokerObject

Inherits:
Object
  • Object
show all
Defined in:
lib/qpid_management/broker_object.rb

Overview

Representation of an object in the broker retrieved via QMF

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, content) ⇒ BrokerObject

Creates a new BrokerObject

Parameters:

  • agent (BrokerAgent)

    the agent used to query the data from the broker

  • content (Hash)

    the raw QMF response data from the broker



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

#contentObject (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.

Parameters:

  • clazz (Class)

    the Class to convert

Returns:

  • (String)

    the converted QMF name counterpart for this Class



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

Parameters:

  • key (String)

    the key to look up a value, e.g. msgDepth for a queue

Returns:

  • the value associated with the key, or nil if not found



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_atTime

Returns the time at which this object was created

Returns:

  • (Time)

    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_atTime

Returns the time at which this object was deleted. Only ever applies to BrokerObject instances created from a QMF event.

Returns:

  • (Time)

    the time at which this object was deleted



79
80
81
# File 'lib/qpid_management/broker_object.rb', line 79

def deleted_at
  Time.at(content['_delete_ts'] / 1000000000.0)
end

#idString

Returns the full object id

Returns:

  • (String)

    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

Raises:



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_idString

Returns the short object id, i.e. without the leading org.apache.qpid.broker:<class name>:

Returns:

  • (String)

    the short object id



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_sObject



115
116
117
# File 'lib/qpid_management/broker_object.rb', line 115

def to_s
  @values.to_s
end

#updated_atTime

Returns the time at which this object was last updated

Returns:

  • (Time)

    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