Permalink
Browse files

Allow invoking overloaded jmx methods.

By default the invoke fn will pick the first jmx method signature that
it finds. This is normally fine, but in the case of overloaded jmx
methods may not be correct. This patch keeps the default behavior of the
invoke method but allows for specifying a cusom method signature in the
case that an overloaded method needs to be invoked.
  • Loading branch information...
1 parent 9a13a24 commit b76f33a0d65471802e119d93ff35a140bfc33aba @nickmbailey nickmbailey committed Feb 22, 2012
Showing with 20 additions and 5 deletions.
  1. +16 −4 src/main/clojure/clojure/java/jmx.clj
  2. +4 −1 src/test/clojure/clojure/java/test_jmx.clj
@@ -261,16 +261,28 @@
[n]
(doall (map #(-> % .getName keyword) (operations n))))
-(defn invoke
- "Invoke an operation an an MBean."
- [n op & args]
+(defn invoke-signature
+ "Invoke an operation an an MBean. You must also supply
+ the signature of the operation. This is useful in cases
+ where the operation is overloaded. Otherwise you should
+ use the 'invoke' operation which will determine the
+ signature for you.
+
+ The signature parameter is a sequence of strings that
+ describes the method parameter types in order."
+ [n op signature & args]
(if ( seq args)
(.invoke *connection* (as-object-name n) (name op)
(into-array Object args)
- (into-array String (op-param-types n op)))
+ (into-array String signature))
(.invoke *connection* (as-object-name n) (name op)
nil nil)))
+(defn invoke
+ "Invoke an operation an an MBean."
+ [n op & args]
+ (apply invoke-signature n op (op-param-types n op) args))
+
(defn mbean
"Like clojure.core/bean, but for JMX beans. Returns a read-only map of
a JMX bean's attributes. If an attribute it not supported, value is
@@ -84,7 +84,10 @@
(jmx/invoke "java.lang:type=Memory" :gc))
(testing "with arguments"
(.addLogger (LogManager/getLogManager) (Logger/getLogger "clojure.java.test_jmx"))
- (jmx/invoke "java.util.logging:type=Logging" :setLoggerLevel "clojure.java.test_jmx" "WARNING")))
+ (jmx/invoke "java.util.logging:type=Logging" :setLoggerLevel "clojure.java.test_jmx" "WARNING"))
+ (testing "with signature"
+ (jmx/invoke-signature "java.lang:type=Threading" :getThreadInfo ["long"] 1)
+ (jmx/invoke-signature "java.lang:type=Threading" :getThreadInfo ["long" "int"] 1 (new java.lang.Integer 1))))
(deftest test-objects->data
(testing "it works recursively on maps"

0 comments on commit b76f33a

Please sign in to comment.