Class: JMX::MBeanServer
- Inherits:
-
Object
- Object
- JMX::MBeanServer
- Defined in:
- lib/jmx/server.rb
Overview
The MBeanServer represents a connection to an MBean server rather than an actual MBean server. Depending upon how this object is constructed you can either talk to the PlatformMBeanServer or any “remote” MBean server. – Represents both MBeanServer and MBeanServerConnection ++
Constant Summary collapse
- @@classes =
{}
Instance Attribute Summary collapse
-
#server ⇒ Object
Returns the value of attribute server.
Class Method Summary collapse
Instance Method Summary collapse
- #[](object_name) ⇒ Object
- #[]=(class_name, object_name) ⇒ Object
- #default_domain ⇒ Object
- #domains ⇒ Object
-
#initialize(location = nil, username = nil, password = nil) ⇒ MBeanServer
constructor
when creatinga new MBeanServer you can optionally specify a location, username, and password if specify these values (or at least the location) the MBeanServer instance will connect to an existing (and remote ) MBean server and register the mbeans there.
- #mbean_count ⇒ Object
- #query_names(name = nil, query = nil) ⇒ Object
- #register_mbean(object, object_name) ⇒ Object
- #unregister_mbean(object_name) ⇒ Object
Constructor Details
#initialize(location = nil, username = nil, password = nil) ⇒ MBeanServer
when creatinga new MBeanServer you can optionally specify a location, username, and password if specify these values (or at least the location) the MBeanServer instance will connect to an existing (and remote ) MBean server and register the mbeans there. otherwise the server will connect to to the local Platform MBean Server.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jmx/server.rb', line 24 def initialize(location=nil, username=nil, password=nil) if (location) env = username ? {"jmx.remote.credentials" => [username, password].to_java(:string)} : nil url = JMXServiceURL.new location @server = JMXConnectorFactory.connect(url, env).getMBeanServerConnection else @server = java.lang.management.ManagementFactory.getPlatformMBeanServer #@server = MBeanServerFactory.createMBeanServer end end |
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
17 18 19 |
# File 'lib/jmx/server.rb', line 17 def server @server end |
Class Method Details
.find(agent_id = nil) ⇒ Object
85 86 87 |
# File 'lib/jmx/server.rb', line 85 def self.find(agent_id=nil) MBeanServerFactory.findMBeanServer(agent_id) end |
Instance Method Details
#[](object_name) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jmx/server.rb', line 37 def [](object_name) name = ObjectName.make object_name unless @server.isRegistered(name) raise NoSuchBeanError.new("No name: #{object_name}") end #### TODO: Why? @server.getObjectInstance name MBeanProxy.generate(@server, name) end |
#[]=(class_name, object_name) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/jmx/server.rb', line 49 def []=(class_name, object_name) name = ObjectName.make object_name @server.createMBean class_name, name, nil, nil MBeanProxy.generate(@server, name) end |
#default_domain ⇒ Object
57 58 59 |
# File 'lib/jmx/server.rb', line 57 def default_domain @server.getDefaultDomain end |
#domains ⇒ Object
61 62 63 |
# File 'lib/jmx/server.rb', line 61 def domains @server.domains end |
#mbean_count ⇒ Object
65 66 67 |
# File 'lib/jmx/server.rb', line 65 def mbean_count @server.getMBeanCount end |
#query_names(name = nil, query = nil) ⇒ Object
69 70 71 72 73 |
# File 'lib/jmx/server.rb', line 69 def query_names(name=nil, query=nil) object_name = name.nil? ? nil : ObjectName.make(name) @server.query_names(object_name, query) end |
#register_mbean(object, object_name) ⇒ Object
79 80 81 82 83 |
# File 'lib/jmx/server.rb', line 79 def register_mbean(object, object_name) name = ObjectName.make(object_name) @server.registerMBean(object, name) MBeanProxy.generate(@server, name) end |
#unregister_mbean(object_name) ⇒ Object
75 76 77 |
# File 'lib/jmx/server.rb', line 75 def unregister_mbean(object_name) @server.unregisterMBean(ObjectName.make(object_name)) end |