Skip to content

Commit fdbcc46

Browse files
eliminate reflection
1 parent 7fff243 commit fdbcc46

File tree

1 file changed

+22
-13
lines changed
  • src/main/clojure/clojure/java

1 file changed

+22
-13
lines changed

src/main/clojure/clojure/java/jmx.clj

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@
7575
(:use [clojure.walk :only [postwalk]])
7676
(:import [clojure.lang Associative]
7777
java.lang.management.ManagementFactory
78-
[javax.management Attribute AttributeList DynamicMBean MBeanInfo
79-
ObjectName RuntimeMBeanException MBeanAttributeInfo MBeanServerConnection]
78+
[javax.management Attribute AttributeList DynamicMBean MBeanInfo MBeanServer
79+
ObjectName RuntimeMBeanException MBeanAttributeInfo MBeanOperationInfo
80+
MBeanParameterInfo MBeanServerConnection]
8081
[javax.management.remote JMXConnectorFactory JMXServiceURL]))
8182

83+
(set! *warn-on-reflection* true)
84+
8285
(def ^{:dynamic true
8386
:doc "The connection to be used for JMX ops. Defaults to the local process."
84-
:skip-wiki true}
87+
:skip-wiki true
88+
:tag MBeanServer}
8589
*connection*
8690
(ManagementFactory/getPlatformMBeanServer))
8791

@@ -200,7 +204,8 @@
200204
(binding [*connection* (.getMBeanServerConnection connector#)]
201205
~@body))))
202206

203-
(defn ^{:skip-wiki true} mbean-info [n]
207+
(defn ^{:skip-wiki true} mbean-info
208+
^MBeanInfo [n]
204209
(.getMBeanInfo *connection* (as-object-name n)))
205210

206211
(defn ^{:skip-wiki true} raw-read
@@ -210,7 +215,7 @@
210215
[n attrs]
211216
(if (sequential? attrs)
212217
(into {}
213-
(map (fn [attr] [(keyword (.getName attr)) (.getValue attr)])
218+
(map (fn [^Attribute attr] [(keyword (.getName attr)) (.getValue attr)])
214219
(.getAttributes *connection*
215220
(as-object-name n)
216221
(into-array (map name attrs)))))
@@ -241,9 +246,9 @@
241246

242247
(defn ^{:skip-wiki true} attribute-info
243248
"Get the MBeanAttributeInfo for an attribute."
244-
[object-name attr-name]
249+
^MBeanAttributeInfo [object-name attr-name]
245250
(first
246-
(filter #(= (name attr-name) (.getName %))
251+
(filter #(= (name attr-name) (.getName ^MBeanAttributeInfo %))
247252
(.getAttributes (mbean-info object-name)))))
248253

249254
(defn readable?
@@ -258,14 +263,16 @@
258263

259264
(defn- operation
260265
"The MBeanOperationInfo for operation op on mbean n. Used by invoke."
261-
[n op]
262-
(first (filter #(= (-> % .getName keyword) op) (operations n))))
266+
^MBeanOperationInfo [n op]
267+
(first (filter (fn [^MBeanOperationInfo info]
268+
(= (-> info .getName keyword) op)) (operations n))))
263269

264270
(defn- op-param-types
265271
"The parameter types (as class name strings) for operation op on n.
266272
Used for invoke."
267273
[n op]
268-
(map #(-> % .getType) (.getSignature (operation n op))))
274+
(map #(.getType ^MBeanParameterInfo %)
275+
(.getSignature (operation n op))))
269276

270277
(defn register-mbean
271278
"Register an mbean with the current *connection*."
@@ -285,13 +292,15 @@
285292
(defn attribute-names
286293
"All attribute names available on an MBean."
287294
[n]
288-
(doall (map #(-> % .getName keyword)
295+
(doall (map (fn [^MBeanAttributeInfo info]
296+
(-> info .getName keyword))
289297
(.getAttributes (mbean-info n)))))
290298

291299
(defn operation-names
292300
"All operation names available on an MBean."
293301
[n]
294-
(doall (map #(-> % .getName keyword) (operations n))))
302+
(doall (map (fn [^MBeanOperationInfo info]
303+
(-> info .getName keyword)) (operations n))))
295304

296305
(defn invoke-signature
297306
"Invoke an operation an an MBean. You must also supply
@@ -355,7 +364,7 @@
355364
(ref-set state-ref
356365
(merge @state-ref state-update))))))
357366
(setAttributes [_ attrs]
358-
(let [attr-names (map (fn [attr]
367+
(let [attr-names (map (fn [^Attribute attr]
359368
(.setAttribute _ attr)
360369
(.getName attr))
361370
attrs)]

0 commit comments

Comments
 (0)