Mercurial > lasercutter
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/jmx/Bean.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,35 @@ 1.4 +(ns clojure.contrib.jmx.Bean 1.5 + (:gen-class 1.6 + :implements [javax.management.DynamicMBean] 1.7 + :init init 1.8 + :state state 1.9 + :constructors {[Object] []}) 1.10 + (:require [clojure.contrib.jmx :as jmx]) 1.11 + (:import [javax.management DynamicMBean MBeanInfo AttributeList])) 1.12 + 1.13 +(defn -init [derefable] 1.14 + [[] derefable]) 1.15 + 1.16 +; TODO: rest of the arguments, as needed 1.17 +(defn generate-mbean-info [clj-bean] 1.18 + (MBeanInfo. (.. clj-bean getClass getName) ; class name 1.19 + "Clojure Dynamic MBean" ; description 1.20 + (jmx/map->attribute-infos @(.state clj-bean)) ; attributes 1.21 + nil ; constructors 1.22 + nil ; operations 1.23 + nil)) ; notifications 1.24 + 1.25 +(defn -getMBeanInfo 1.26 + [this] 1.27 + (generate-mbean-info this)) 1.28 + 1.29 +(defn -getAttribute 1.30 + [this attr] 1.31 + (@(.state this) (keyword attr))) 1.32 + 1.33 +(defn -getAttributes 1.34 + [this attrs] 1.35 + (let [result (AttributeList.)] 1.36 + (doseq [attr attrs] 1.37 + (.add result (.getAttribute this attr))) 1.38 + result)) 1.39 \ No newline at end of file