Skip to content

Commit

Permalink
Implement pprint handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Nov 26, 2023
1 parent 42a5c25 commit 0a0a6e7
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/overtone/at_at.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
(ns overtone.at-at
(:import [java.util.concurrent ScheduledThreadPoolExecutor TimeUnit ThreadPoolExecutor Future]
[java.io Writer])
(:gen-class))
(:require
[clojure.pprint :as pprint])
(:import
(java.io Writer)
(java.util.concurrent ScheduledThreadPoolExecutor
TimeUnit
ThreadPoolExecutor)))

(defrecord PoolInfo [thread-pool jobs-ref id-count-ref])
(defrecord MutablePool [pool-atom])
Expand All @@ -13,17 +17,34 @@
[date]
(.format (java.text.SimpleDateFormat. "EEE hh':'mm':'ss's'") date))

(defmethod pprint/simple-dispatch PoolInfo [obj]
(println (str "#<PoolInfo: " (:thread-pool obj) " "
(count @(:jobs-ref obj)) " jobs>")))

(defmethod print-method PoolInfo
[obj ^Writer w]
(.write w (str "#<PoolInfo: " (:thread-pool obj) " "
(count @(:jobs-ref obj)) " jobs>")))

(defmethod pprint/simple-dispatch MutablePool [obj]
(println (str "#<MutablePool - "
"jobs: "(count @(:jobs-ref @(:pool-atom obj)))
">")))

(defmethod print-method MutablePool
[obj ^Writer w]
(.write w (str "#<MutablePool - "
"jobs: "(count @(:jobs-ref @(:pool-atom obj)))
">")))

(defmethod pprint/simple-dispatch RecurringJob [obj]
(println (str "#<RecurringJob id: " (:id obj)
", created-at: " (format-date (:created-at obj))
", ms-period: " (:ms-period obj)
", initial-delay: " (:initial-delay obj)
", desc: \"" (:desc obj) "\""
", scheduled? " @(:scheduled? obj) ">")))

(defmethod print-method RecurringJob
[obj ^Writer w]
(.write w (str "#<RecurringJob id: " (:id obj)
Expand All @@ -33,6 +54,13 @@
", desc: \"" (:desc obj) "\""
", scheduled? " @(:scheduled? obj) ">")))

(defmethod pprint/simple-dispatch ScheduledJob [obj]
(println (str "#<ScheduledJob id: " (:id obj)
", created-at: " (format-date (:created-at obj))
", initial-delay: " (:initial-delay obj)
", desc: \"" (:desc obj) "\""
", scheduled? " @(:scheduled? obj) ">")))

(defmethod print-method ScheduledJob
[obj ^Writer w]
(.write w (str "#<ScheduledJob id: " (:id obj)
Expand All @@ -56,8 +84,6 @@
[]
(.availableProcessors (Runtime/getRuntime)))



(defn- schedule-job
"Schedule the fun to execute periodically in pool-info's pool with the
specified initial-delay and ms-period. Returns a RecurringJob record."
Expand Down

0 comments on commit 0a0a6e7

Please sign in to comment.