Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

:environment option for jmx/with-connection

  • Loading branch information...
commit 6f2b1d73b50b7b9f0d753aa0f5fd343b67f75bf6 1 parent 0a1bfc9
Stuart Halloway authored February 18, 2010
42  src/main/clojure/clojure/contrib/jmx/client.clj
@@ -14,22 +14,25 @@
14 14
 
15 15
 (in-ns 'clojure.contrib.jmx)
16 16
 
17  
-; TODO: needs an integration test
18  
-; TODO: why full package needed for JMXConnectorFactory?
19 17
 (defmacro with-connection
20  
-  "Execute body with JMX connection specified by opts (:port)."
  18
+  "Execute body with JMX connection specified by opts. opts can also
  19
+   include an optional :environment key which is passed as the
  20
+   environment arg to JMXConnectorFactory/connect."
21 21
   [opts & body]
22  
-  `(with-open [connector# (javax.management.remote.JMXConnectorFactory/connect
23  
-                           (JMXServiceURL. (jmx-url ~opts)) {})]
24  
-     (binding [*connection* (.getMBeanServerConnection connector#)]
25  
-       ~@body)))
  22
+  `(let [opts# ~opts
  23
+         env# (get opts# :environment {})
  24
+         opts# (dissoc opts# :environment)]
  25
+     (with-open [connector# (javax.management.remote.JMXConnectorFactory/connect
  26
+                             (JMXServiceURL. (jmx-url opts#)) env#)]
  27
+       (binding [*connection* (.getMBeanServerConnection connector#)]
  28
+         ~@body))))
26 29
 
27 30
 (defn mbean-info [n]
28 31
   (.getMBeanInfo *connection* (as-object-name n)))
29 32
 
30 33
 (defn raw-read
31  
-  "Read an mbean property. Returns low-level Java object model for composites, tabulars, etc.
32  
-   Most callers should use read."
  34
+  "Read an mbean property. Returns low-level Java object model for
  35
+   composites, tabulars, etc. Most callers should use read."
33 36
   [n attr]
34 37
   (.getAttribute *connection* (as-object-name n) (as-str attr)))
35 38
 
@@ -43,14 +46,16 @@
43 46
    java.io.NotSerializableException
44 47
    java.lang.ClassNotFoundException
45 48
    javax.management.AttributeNotFoundException]
46  
-  "Exceptions that might be thrown if you try to read an unsupported attribute.
47  
-   by testing agains jconsole and Tomcat. This is dreadful and ad-hoc but I did not
48  
-   want to swallow all exceptions.")
  49
+  "Exceptions that might be thrown if you try to read an unsupported
  50
+   attribute. Found these by testing agains jconsole and Tomcat. This
  51
+   is dreadful and ad-hoc but I did not want to swallow all
  52
+   exceptions.")
49 53
 
50 54
 (defn read-supported
51  
-  "Calls read to read an mbean property, *returning* unsupported operation exceptions instead of throwing them.
52  
-   Used to keep mbean from blowing up. Note that some terribly-behaved mbeans use java.lang.InternalError to
53  
-   indicate an unsupported operation!"
  55
+  "Calls read to read an mbean property, *returning* unsupported
  56
+   operation exceptions instead of throwing them. Used to keep mbean
  57
+   from blowing up. Note that some terribly-behaved mbeans use
  58
+   java.lang.InternalError to indicate an unsupported operation!"
54 59
   [n attr]
55 60
   (try
56 61
    (read n attr)
@@ -67,7 +72,7 @@
67 72
    (Attribute. (as-str attr) value)))
68 73
 
69 74
 (defn attribute-info
70  
-  "Get the MBeanAttributeInfo for an attribute"
  75
+  "Get the MBeanAttributeInfo for an attribute."
71 76
   [object-name attr-name]
72 77
   (filter #(= (as-str attr-name) (.getName %))
73 78
           (.getAttributes (mbean-info object-name))))
@@ -83,12 +88,13 @@
83 88
   (.getOperations (mbean-info n)))
84 89
 
85 90
 (defn operation
86  
-  "The MBeanOperationInfo for operation op on mbean n. Used for invoke."
  91
+  "The MBeanOperationInfo for operation op on mbean n. Used by invoke."
87 92
   [n op]
88 93
   (first  (filter #(= (-> % .getName keyword) op) (operations n))))
89 94
 
90 95
 (defn op-param-types 
91  
-  "The parameter types (as class name strings) for operation op on n. Used for invoke."
  96
+  "The parameter types (as class name strings) for operation op on n.
  97
+   Used for invoke."
92 98
   [n op]
93 99
   (map #(-> % .getType) (.getSignature (operation n op))))
94 100
 

0 notes on commit 6f2b1d7

Please sign in to comment.
Something went wrong with that request. Please try again.