aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-02-18 05:25:39 -0500
committerStuart Halloway <stu@thinkrelevance.com>2010-02-18 05:25:39 -0500
commit6f2b1d73b50b7b9f0d753aa0f5fd343b67f75bf6 (patch)
tree84243c922de4594c4844c87574ad4df80c445078
parent0a1bfc9b4a1d5e20365d1905806eaf61e13c6db1 (diff)
:environment option for jmx/with-connection
-rw-r--r--src/main/clojure/clojure/contrib/jmx/client.clj42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/main/clojure/clojure/contrib/jmx/client.clj b/src/main/clojure/clojure/contrib/jmx/client.clj
index 7af947d1..fa67ca77 100644
--- a/src/main/clojure/clojure/contrib/jmx/client.clj
+++ b/src/main/clojure/clojure/contrib/jmx/client.clj
@@ -14,22 +14,25 @@
(in-ns 'clojure.contrib.jmx)
-; TODO: needs an integration test
-; TODO: why full package needed for JMXConnectorFactory?
(defmacro with-connection
- "Execute body with JMX connection specified by opts (:port)."
+ "Execute body with JMX connection specified by opts. opts can also
+ include an optional :environment key which is passed as the
+ environment arg to JMXConnectorFactory/connect."
[opts & body]
- `(with-open [connector# (javax.management.remote.JMXConnectorFactory/connect
- (JMXServiceURL. (jmx-url ~opts)) {})]
- (binding [*connection* (.getMBeanServerConnection connector#)]
- ~@body)))
+ `(let [opts# ~opts
+ env# (get opts# :environment {})
+ opts# (dissoc opts# :environment)]
+ (with-open [connector# (javax.management.remote.JMXConnectorFactory/connect
+ (JMXServiceURL. (jmx-url opts#)) env#)]
+ (binding [*connection* (.getMBeanServerConnection connector#)]
+ ~@body))))
(defn mbean-info [n]
(.getMBeanInfo *connection* (as-object-name n)))
(defn raw-read
- "Read an mbean property. Returns low-level Java object model for composites, tabulars, etc.
- Most callers should use read."
+ "Read an mbean property. Returns low-level Java object model for
+ composites, tabulars, etc. Most callers should use read."
[n attr]
(.getAttribute *connection* (as-object-name n) (as-str attr)))
@@ -43,14 +46,16 @@
java.io.NotSerializableException
java.lang.ClassNotFoundException
javax.management.AttributeNotFoundException]
- "Exceptions that might be thrown if you try to read an unsupported attribute.
- by testing agains jconsole and Tomcat. This is dreadful and ad-hoc but I did not
- want to swallow all exceptions.")
+ "Exceptions that might be thrown if you try to read an unsupported
+ attribute. Found these by testing agains jconsole and Tomcat. This
+ is dreadful and ad-hoc but I did not want to swallow all
+ exceptions.")
(defn read-supported
- "Calls read to read an mbean property, *returning* unsupported operation exceptions instead of throwing them.
- Used to keep mbean from blowing up. Note that some terribly-behaved mbeans use java.lang.InternalError to
- indicate an unsupported operation!"
+ "Calls read to read an mbean property, *returning* unsupported
+ operation exceptions instead of throwing them. Used to keep mbean
+ from blowing up. Note that some terribly-behaved mbeans use
+ java.lang.InternalError to indicate an unsupported operation!"
[n attr]
(try
(read n attr)
@@ -67,7 +72,7 @@
(Attribute. (as-str attr) value)))
(defn attribute-info
- "Get the MBeanAttributeInfo for an attribute"
+ "Get the MBeanAttributeInfo for an attribute."
[object-name attr-name]
(filter #(= (as-str attr-name) (.getName %))
(.getAttributes (mbean-info object-name))))
@@ -83,12 +88,13 @@
(.getOperations (mbean-info n)))
(defn operation
- "The MBeanOperationInfo for operation op on mbean n. Used for invoke."
+ "The MBeanOperationInfo for operation op on mbean n. Used by invoke."
[n op]
(first (filter #(= (-> % .getName keyword) op) (operations n))))
(defn op-param-types
- "The parameter types (as class name strings) for operation op on n. Used for invoke."
+ "The parameter types (as class name strings) for operation op on n.
+ Used for invoke."
[n op]
(map #(-> % .getType) (.getSignature (operation n op))))