2 * collectd/java - org/collectd/java/GenericJMX.java
3 * Copyright (C) 2009 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
22 package org.collectd.java;
24 import java.util.List;
25 import java.util.ArrayList;
27 import java.util.TreeMap;
29 import org.collectd.api.Collectd;
30 import org.collectd.api.CollectdConfigInterface;
31 import org.collectd.api.CollectdInitInterface;
32 import org.collectd.api.CollectdReadInterface;
33 import org.collectd.api.CollectdShutdownInterface;
34 import org.collectd.api.OConfigValue;
35 import org.collectd.api.OConfigItem;
37 public class GenericJMX implements CollectdConfigInterface,
38 CollectdReadInterface,
39 CollectdShutdownInterface
41 static private Map<String,GenericJMXConfMBean> _mbeans
42 = new TreeMap<String,GenericJMXConfMBean> ();
44 private List<GenericJMXConfConnection> _connections = null;
48 Collectd.registerConfig ("GenericJMX", this);
49 Collectd.registerRead ("GenericJMX", this);
50 Collectd.registerShutdown ("GenericJMX", this);
52 this._connections = new ArrayList<GenericJMXConfConnection> ();
55 public int config (OConfigItem ci) /* {{{ */
57 List<OConfigItem> children;
60 Collectd.logDebug ("GenericJMX plugin: config: ci = " + ci + ";");
62 children = ci.getChildren ();
63 for (i = 0; i < children.size (); i++)
68 child = children.get (i);
69 key = child.getKey ();
70 if (key.equalsIgnoreCase ("MBean"))
74 GenericJMXConfMBean mbean = new GenericJMXConfMBean (child);
77 catch (IllegalArgumentException e)
79 Collectd.logError ("GenericJMX plugin: "
80 + "Evaluating `MBean' block failed: " + e);
83 else if (key.equalsIgnoreCase ("Connection"))
87 GenericJMXConfConnection conn = new GenericJMXConfConnection (child);
88 this._connections.add (conn);
90 catch (IllegalArgumentException e)
92 Collectd.logError ("GenericJMX plugin: "
93 + "Evaluating `Connection' block failed: " + e);
98 Collectd.logError ("GenericJMX plugin: Unknown config option: " + key);
100 } /* for (i = 0; i < children.size (); i++) */
103 } /* }}} int config */
105 public int read () /* {{{ */
107 for (int i = 0; i < this._connections.size (); i++)
111 this._connections.get (i).query ();
115 Collectd.logError ("GenericJMX: Caught unexpected exception: " + e);
116 e.printStackTrace ();
123 public int shutdown () /* {{{ */
125 System.out.print ("org.collectd.java.GenericJMX.Shutdown ();\n");
126 this._connections = null;
128 } /* }}} int shutdown */
133 static public GenericJMXConfMBean getMBean (String alias)
135 return (_mbeans.get (alias));
138 static private void putMBean (GenericJMXConfMBean mbean)
140 Collectd.logDebug ("GenericJMX.putMBean: Adding " + mbean.getName ());
141 _mbeans.put (mbean.getName (), mbean);
143 } /* class GenericJMX */
145 /* vim: set sw=2 sts=2 et fdm=marker : */