Class: Jolokia::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jolokia/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/jolokia/client.rb', line 8

def initialize(opts = {})
  @url = opts[:url]
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/jolokia/client.rb', line 6

def url
  @url
end

Instance Method Details

#execute(mbean, operation, args = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jolokia/client.rb', line 31

def execute(mbean, operation, args = nil)
  options = {
    'type' => 'exec',
    'mbean' => mbean,
    'operation' => operation
  }

  if args
    options['arguments'] = args.is_a?(Array) ? args : [args]
  end

  request(:post, options)
end

#get_attribute(mbean, attribute, path = nil) ⇒ Object



12
13
14
15
16
17
# File 'lib/jolokia/client.rb', line 12

def get_attribute(mbean, attribute, path = nil)
  options = { 'type' => 'read', 'mbean' => mbean, 'attribute' => attribute }
  options['path'] = path if path

  request(:post, options)['value']
end

#request(method, opts) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/jolokia/client.rb', line 45

def request(method, opts)
  resp = connection.send(method, '', opts)

  if resp.body['status'] != 200
    raise RemoteError.new(resp.body['status'],
                          resp.body['error'],
                          resp.body['stacktrace'])
  end

  resp.body
end

#set_attribute(mbean, attribute, value, path = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jolokia/client.rb', line 19

def set_attribute(mbean, attribute, value, path = nil)
  options = {
    'type' => 'write',
    'mbean' => mbean,
    'attribute' => attribute,
    'value' => value
  }
  options['path'] = path if path

  request(:post, options)
end