                                (Thread/sleep 1000)
                                (recur scheduler f (dec attempts))))))
 
-(defn ^{:internal true} create-job
+(try-defn (import [org.immutant.jobs ClojureJob ScheduledJobMBean]
+                  org.projectodd.polyglot.jobs.BaseScheduledJob)
+  ^{:internal true} create-job
   "Instantiates and starts a job"
   [f name spec singleton]
-  (let [^JobScheduler scheduler (scheduler singleton)]
+  (let [scheduler (scheduler singleton)]
     (doto
         (proxy [BaseScheduledJob ScheduledJobMBean]
             [ClojureJob (app-name) name "" spec singleton]

;; 02110-1301 USA, or see the FSF site: http://www.fsf.org.

(ns immutant.jobs.internal
  (:use [immutant.utilities :only [app-name]])
  (:require [immutant.registry :as registry]
            [clojure.tools.logging :as log])
  (:import [org.immutant.jobs ClojureJob JobScheduler JobSchedulizer ScheduledJobMBean]
           [org.immutant.jobs.as JobsServices]
           [org.projectodd.polyglot.jobs BaseScheduledJob]))

(defn ^{:private true} #^JobSchedulizer job-schedulizer  []
  (registry/fetch "job-schedulizer"))

(defn ^{:internal true} create-scheduler


(defn ^{:internal true} stop-job
  "Stops (unschedules) a job, removing it from the scheduler."
  [job]
  (if-not (.isShutdown (.getScheduler job))
    (.stop job)))

;; we don't currently register an mbean for each job, since we can't
;; yet easily unregister the mbean
;; ignore reflection here for now, since we don't even use it yet
(try-defn (import org.immutant.jobs.as.JobsServices) register-job-mbean [name job]
  (.installMBean
   (job-schedulizer)
   (.append JobsServices/JOBS
