Skip to content

Commit

Permalink
simplify jmx/read-supported and improve test output
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthalloway committed Mar 30, 2010
1 parent a0178ae commit d157d64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
23 changes: 4 additions & 19 deletions src/main/clojure/clojure/contrib/jmx/client.clj
Expand Up @@ -40,31 +40,16 @@
(comp jmx->clj raw-read)
"Read an mbean property.")

(defvar read-exceptions
[UnsupportedOperationException
InternalError
java.io.NotSerializableException
java.lang.ClassNotFoundException
javax.management.AttributeNotFoundException
javax.management.RuntimeMBeanException]
"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!"
from blowing up. Note: There is no good exception that aggregates
unsupported operations, hence the overly-general catch block."
[n attr]
(try
(read n attr)
(catch Throwable t
(let [cause (root-cause t)]
(if (some #(instance? % cause) read-exceptions)
cause
(throw t))))))
(catch Exception e
e)))

(defn write! [n attr value]
(.setAttribute
Expand Down
2 changes: 1 addition & 1 deletion src/test/clojure/clojure/contrib/test_jmx.clj
Expand Up @@ -113,7 +113,7 @@
(deftest various-beans-are-readable
(testing "that all java.lang beans can be read without error"
(doseq [mb (jmx/mbean-names "*:*")]
(jmx/mbean mb))))
(is (map? (jmx/mbean mb)) mb))))

(deftest test-jmx-url
(testing "creates default url"
Expand Down

0 comments on commit d157d64

Please sign in to comment.