 
 (defonce server (atom nil))
 
-(defonce object-pattern (atom "java.lang:*"))
+(defonce config (atom {:object-pattern "java.lang:*"
+                       :jmx-remote-host "localhost"
+                       :jmx-remote-port 11080}))
 
-(defonce jmx-remote-host (atom "localhost"))
-
-(defonce jmx-remote-port (atom 1080))
+(defn- get-connection-map []
+  {:host (:jmx-remote-host @config) :port (:jmx-remote-port @config)})
 
 (defn- handle-describe [operation]
   (fn [request]
-    (jmx/with-connection {:host @jmx-remote-host :port @jmx-remote-port}
+    (jmx/with-connection (get-connection-map)
       (let [mbean (get-in request [:params :bean])
             op (keyword operation)]
         (doall (describe mbean op))))))


(defn- handle-invoke [operation]
  (fn [request]
    (jmx/with-connection {:host @jmx-remote-host :port @jmx-remote-port}
      (let [mbean (get-in request [:params :bean])
            args (get-in request [:params :args])
            types (get-in request [:params :types])]


(defn- handle-list-beans []
  (fn [request]
    (jmx/with-connection (get-connection-map)
      (doall (list-beans (:object-pattern @config))))))

(defroutes app-routes
  (GET "/list" [] (handle-list-beans))
