X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=bindings%2Fjava%2Forg%2Fcollectd%2Fjava%2FGenericJMXConfConnection.java;h=0c81bc9ad941760f07021530d6663f32ee34b75f;hb=d6021a800b12c89b5a78877af2c5b9abc1a8e609;hp=0108b53fdb1d5f3b56e7d477c54c5c2ef35a73ad;hpb=1e4db580e37d235755de0c4a4c08ba7a6ac7bb4c;p=collectd.git diff --git a/bindings/java/org/collectd/java/GenericJMXConfConnection.java b/bindings/java/org/collectd/java/GenericJMXConfConnection.java index 0108b53f..0c81bc9a 100644 --- a/bindings/java/org/collectd/java/GenericJMXConfConnection.java +++ b/bindings/java/org/collectd/java/GenericJMXConfConnection.java @@ -1,6 +1,6 @@ /* * collectd/java - org/collectd/java/GenericJMXConfConnection.java - * Copyright (C) 2009 Florian octo Forster + * Copyright (C) 2009,2010 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -22,8 +22,10 @@ package org.collectd.java; import java.util.List; +import java.util.Map; import java.util.Iterator; import java.util.ArrayList; +import java.util.HashMap; import javax.management.MBeanServerConnection; import javax.management.ObjectName; @@ -40,7 +42,10 @@ import org.collectd.api.OConfigItem; class GenericJMXConfConnection { + private String _username = null; + private String _password = null; private String _host = null; + private String _instance_prefix = null; private String _service_url = null; private MBeanServerConnection _jmx_connection = null; private List _mbeans = null; @@ -76,14 +81,29 @@ private void connect () /* {{{ */ { JMXServiceURL service_url; JMXConnector connector; + Map environment; if (_jmx_connection != null) return; + environment = null; + if (this._password != null) + { + String[] credentials; + + if (this._username == null) + this._username = new String ("monitorRole"); + + credentials = new String[] { this._username, this._password }; + + environment = new HashMap (); + environment.put (JMXConnector.CREDENTIALS, credentials); + } + try { service_url = new JMXServiceURL (this._service_url); - connector = JMXConnectorFactory.connect (service_url); + connector = JMXConnectorFactory.connect (service_url, environment); _jmx_connection = connector.getMBeanServerConnection (); } catch (Exception e) @@ -125,12 +145,30 @@ private void connect () /* {{{ */ if (tmp != null) this._host = tmp; } + else if (child.getKey ().equalsIgnoreCase ("User")) + { + String tmp = getConfigString (child); + if (tmp != null) + this._username = tmp; + } + else if (child.getKey ().equalsIgnoreCase ("Password")) + { + String tmp = getConfigString (child); + if (tmp != null) + this._password = tmp; + } else if (child.getKey ().equalsIgnoreCase ("ServiceURL")) { String tmp = getConfigString (child); if (tmp != null) this._service_url = tmp; } + else if (child.getKey ().equalsIgnoreCase ("InstancePrefix")) + { + String tmp = getConfigString (child); + if (tmp != null) + this._instance_prefix = tmp; + } else if (child.getKey ().equalsIgnoreCase ("Collect")) { String tmp = getConfigString (child); @@ -177,7 +215,17 @@ private void connect () /* {{{ */ pd.setPlugin ("GenericJMX"); for (int i = 0; i < this._mbeans.size (); i++) - this._mbeans.get (i).query (this._jmx_connection, pd); + { + int status; + + status = this._mbeans.get (i).query (this._jmx_connection, pd, + this._instance_prefix); + if (status != 0) + { + this._jmx_connection = null; + return; + } + } /* for */ } /* }}} void query */ public String toString ()