Welcome! Please see the About page for a little more info on how this works.

0 votes
in java.jmx by
According to the java.jmx doc:

([opts & body])
  Execute body with a JMX connection created based on opts. opts can include [default]:

     :protocol    The protocol to use [rmi:///jndi/rmi]
     :host        The host to connect to [localhost]
     :port        The port to connect to [3000]
     :jndi-path   The jndi-path to use [jmxuri]
     :url         The full url (as a String) to use instead of generating a rmi url from
                  the above options [nil]
     :environment A map representing the environment used for the connection.
                  See JMXConnectorFactory/connect for details [{}]

The description indicates :url is by default 'nil', and when it is not, it will be used instead of options above.

However, if I called the function with :url=nil and other options, it will use the nil url anyway, and ignore other options.

=> (jmx/with-connection {:url nil :host "localhost"} (jmx/mbean-names "*:*"))

NullPointerException   javax.management.remote.JMXServiceURL.<init> (JMXServiceURL.java:142)
=> (jmx/with-connection {:host "localhost"} (jmx/mbean-names "*:*"))

ConnectException Connection refused (Connection refused)  java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)

I checked the code:

(JMXServiceURL. (:url opts# (jmx-url opts#)))

I believe the intention here is to fallback to (jmx-url opts#) when either there's no :url key or :url is nil (as said in doc also)

But the actual behavior is not falling back, if opts# contains :url => nil.

=> (:url {:url nil :foo "bar"} "fallback")
=> (:url {:foo "bar"} "fallback")

2 Answers

0 votes

Comment made by: weichu

I guess a simple "or" should work:

- (JMXServiceURL. (:url opts# (jmx-url opts#))) + (JMXServiceURL. (or (:url opts#) (jmx-url opts#)))

0 votes
Reference: https://clojure.atlassian.net/browse/JMX-20 (reported by alex+import)