Mercurial > lasercutter
annotate 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 |
rev | line source |
---|---|
rlm@10 | 1 (ns clojure.contrib.jmx.Bean |
rlm@10 | 2 (:gen-class |
rlm@10 | 3 :implements [javax.management.DynamicMBean] |
rlm@10 | 4 :init init |
rlm@10 | 5 :state state |
rlm@10 | 6 :constructors {[Object] []}) |
rlm@10 | 7 (:require [clojure.contrib.jmx :as jmx]) |
rlm@10 | 8 (:import [javax.management DynamicMBean MBeanInfo AttributeList])) |
rlm@10 | 9 |
rlm@10 | 10 (defn -init [derefable] |
rlm@10 | 11 [[] derefable]) |
rlm@10 | 12 |
rlm@10 | 13 ; TODO: rest of the arguments, as needed |
rlm@10 | 14 (defn generate-mbean-info [clj-bean] |
rlm@10 | 15 (MBeanInfo. (.. clj-bean getClass getName) ; class name |
rlm@10 | 16 "Clojure Dynamic MBean" ; description |
rlm@10 | 17 (jmx/map->attribute-infos @(.state clj-bean)) ; attributes |
rlm@10 | 18 nil ; constructors |
rlm@10 | 19 nil ; operations |
rlm@10 | 20 nil)) ; notifications |
rlm@10 | 21 |
rlm@10 | 22 (defn -getMBeanInfo |
rlm@10 | 23 [this] |
rlm@10 | 24 (generate-mbean-info this)) |
rlm@10 | 25 |
rlm@10 | 26 (defn -getAttribute |
rlm@10 | 27 [this attr] |
rlm@10 | 28 (@(.state this) (keyword attr))) |
rlm@10 | 29 |
rlm@10 | 30 (defn -getAttributes |
rlm@10 | 31 [this attrs] |
rlm@10 | 32 (let [result (AttributeList.)] |
rlm@10 | 33 (doseq [attr attrs] |
rlm@10 | 34 (.add result (.getAttribute this attr))) |
rlm@10 | 35 result)) |