|
| 1 | +(ns clojang.component.repl |
| 2 | + "The Clojang component development namespace." |
| 3 | + (:require |
| 4 | + [clojang.component.system] |
| 5 | + [clojure.java.io :as io] |
| 6 | + [clojure.pprint :refer [pprint]] |
| 7 | + [clojure.set :as set] |
| 8 | + [clojure.string :as string] |
| 9 | + [clojure.tools.namespace.repl :as repl] |
| 10 | + [clojusc.dev.system.core :as system-api] |
| 11 | + [clojusc.twig :as logger] |
| 12 | + [com.stuartsierra.component :as component] |
| 13 | + [taoensso.timbre :as log] |
| 14 | + [trifl.java :refer [show-methods]])) |
| 15 | + |
| 16 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 17 | +;;; Constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 18 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 19 | + |
| 20 | +(def system-ns "clojang.component.system") |
| 21 | +(def refresh-callback 'clojang.component.repl/startup) |
| 22 | + |
| 23 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 24 | +;;; Initial Setup & Utility Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 25 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 26 | + |
| 27 | +(logger/set-level! '[clojang] :debug) |
| 28 | + |
| 29 | +(def ^:dynamic *mgr* nil) |
| 30 | + |
| 31 | +(defn banner |
| 32 | + [] |
| 33 | + (println (slurp (io/resource "text/banner.txt"))) |
| 34 | + :ok) |
| 35 | + |
| 36 | +(defn mgr-arg |
| 37 | + [] |
| 38 | + (if *mgr* |
| 39 | + *mgr* |
| 40 | + (throw (new Exception |
| 41 | + (str "A state manager is not defined; " |
| 42 | + "have you run (startup)?"))))) |
| 43 | + |
| 44 | +(defn system-arg |
| 45 | + [] |
| 46 | + (if-let [state (:state *mgr*)] |
| 47 | + (system-api/get-system state) |
| 48 | + (throw (new Exception |
| 49 | + (str "System data structure is not defined; " |
| 50 | + "have you run (startup)?"))))) |
| 51 | + |
| 52 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 53 | +;;; State Management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 54 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 55 | + |
| 56 | +(defn startup |
| 57 | + [] |
| 58 | + (log/trace "Creating state manager ...") |
| 59 | + (alter-var-root #'*mgr* (constantly (system-api/create-state-manager))) |
| 60 | + (log/trace "State manager was created:" *mgr*) |
| 61 | + (log/trace "Setting system namespace ...") |
| 62 | + (system-api/set-system-ns (:state *mgr*) system-ns) |
| 63 | + (log/trace "Set system namespace to:" (system-api/get-system-ns (:state *mgr*))) |
| 64 | + (log/trace "System status:" (system-api/get-status (:state *mgr*))) |
| 65 | + (log/trace "Starting system ...") |
| 66 | + (system-api/startup *mgr*)) |
| 67 | + |
| 68 | +(defn shutdown |
| 69 | + [] |
| 70 | + (when *mgr* |
| 71 | + (let [result (system-api/shutdown (mgr-arg))] |
| 72 | + (alter-var-root #'*mgr* (constantly nil)) |
| 73 | + result))) |
| 74 | + |
| 75 | +(def system system-arg) |
| 76 | + |
| 77 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 78 | +;;; Reloading Management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 79 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 80 | + |
| 81 | +(defn reset |
| 82 | + [] |
| 83 | + (shutdown) |
| 84 | + (repl/refresh :after refresh-callback)) |
| 85 | + |
| 86 | +(def refresh #'repl/refresh) |
0 commit comments