aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/jmx/Bean.clj
blob: cae67d213ee55090061bfe91e8737fb692300949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns clojure.contrib.jmx.Bean
  (:gen-class
   :implements [javax.management.DynamicMBean]
   :init init
   :state state
   :constructors {[Object] []})
  (:require [clojure.contrib.jmx :as jmx])
  (:import [javax.management DynamicMBean MBeanInfo AttributeList]))

(defn -init [derefable]
  [[] derefable])

; TODO: rest of the arguments, as needed
(defn generate-mbean-info [clj-bean]
  (MBeanInfo. (.. clj-bean getClass getName)                      ; class name
              "Clojure Dynamic MBean"                             ; description
              (jmx/map->attribute-infos @(.state clj-bean))       ; attributes
              nil                                                 ; constructors
              nil                                                 ; operations
              nil))                                               ; notifications                                          

(defn -getMBeanInfo
  [this]
  (generate-mbean-info this))

(defn -getAttribute
  [this attr]
  (@(.state this) (keyword attr)))

(defn -getAttributes
  [this attrs]
  (let [result (AttributeList.)]
    (doseq [attr attrs]
      (.add result (.getAttribute this attr)))
    result))