view src/clojure/contrib/jmx/Bean.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line source
1 (ns clojure.contrib.jmx.Bean
2 (:gen-class
3 :implements [javax.management.DynamicMBean]
4 :init init
5 :state state
6 :constructors {[Object] []})
7 (:require [clojure.contrib.jmx :as jmx])
8 (:import [javax.management DynamicMBean MBeanInfo AttributeList]))
10 (defn -init [derefable]
11 [[] derefable])
13 ; TODO: rest of the arguments, as needed
14 (defn generate-mbean-info [clj-bean]
15 (MBeanInfo. (.. clj-bean getClass getName) ; class name
16 "Clojure Dynamic MBean" ; description
17 (jmx/map->attribute-infos @(.state clj-bean)) ; attributes
18 nil ; constructors
19 nil ; operations
20 nil)) ; notifications
22 (defn -getMBeanInfo
23 [this]
24 (generate-mbean-info this))
26 (defn -getAttribute
27 [this attr]
28 (@(.state this) (keyword attr)))
30 (defn -getAttributes
31 [this attrs]
32 (let [result (AttributeList.)]
33 (doseq [attr attrs]
34 (.add result (.getAttribute this attr)))
35 result))