Permalink
Browse files

Expose jobs via mbeans [IMMUTANT-34]

  • Loading branch information...
1 parent a7485d4 commit f3c52360e1488ab544fcee09969e6fc0d528b8cd @tobias tobias committed Oct 11, 2012
Showing with 29 additions and 27 deletions.
  1. +29 −27 modules/jobs/src/main/clojure/immutant/jobs/internal.clj
@@ -60,41 +60,43 @@ A singleton scheduler will participate in a cluster, and will only execute its j
(let [s (scheduler singleton)]
(wait-for-scheduler s #(.getScheduler s))))
+(try-defn (import org.immutant.jobs.as.JobsServices) register-job-mbean [name job]
+ (.installMBean
+ (job-schedulizer)
+ (.append JobsServices/JOBS
+ (doto (make-array String 2)
+ (aset 0 (app-name))
+ (aset 1 name)))
+ "immutant.jobs"
+ job))
+
(try-defn (import org.projectodd.polyglot.jobs.BaseScheduledJob)
^{:internal true} create-job
"Instantiates and starts a job"
[f name spec singleton]
- (let [scheduler (scheduler singleton)]
- (doto
- (proxy [BaseScheduledJob ScheduledJobMBean]
- [ClojureJob (app-name) name "" spec singleton]
- (start []
- (wait-for-scheduler
- scheduler
- #(.addJob scheduler
- name (app-name)
- (ClojureJob. (registry/fetch "clojure-runtime") f)))
- (let [^BaseScheduledJob this this] ;; hack to eliminate reflection
- (proxy-super start)))
- (getScheduler []
- (.getScheduler scheduler)))
- .start)))
+ (let [scheduler (scheduler singleton)
+ job
+ (doto
+ (proxy [BaseScheduledJob ScheduledJobMBean]
+ [ClojureJob (app-name) name "" spec singleton]
+ (start []
+ (wait-for-scheduler
+ scheduler
+ #(.addJob scheduler
+ name (app-name)
+ (ClojureJob. (registry/fetch "clojure-runtime") f)))
+ (let [^BaseScheduledJob this this] ;; hack to eliminate reflection
+ (proxy-super start)))
+ (getScheduler []
+ (.getScheduler scheduler)))
+ .start)]
+ (register-job-mbean name job)
+ job))
(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
- (doto (make-array String 2)
- (aset 0 (app-name))
- (aset 1 name)))
- "immutant.jobs"
- job))
+

0 comments on commit f3c5236

Please sign in to comment.