2020-12-24 14:32:19 +01:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2022-09-20 23:23:22 +02:00
|
|
|
;; Copyright (c) KALEIDOS INC
|
2020-12-24 14:32:19 +01:00
|
|
|
|
|
|
|
(ns app.srepl
|
|
|
|
"Server Repl."
|
|
|
|
(:require
|
2021-09-29 16:39:25 +02:00
|
|
|
[app.common.logging :as l]
|
2020-12-24 14:32:19 +01:00
|
|
|
[app.common.spec :as us]
|
2021-01-31 19:25:26 +01:00
|
|
|
[app.srepl.main]
|
2020-12-24 14:32:19 +01:00
|
|
|
[clojure.core.server :as ccs]
|
2021-01-31 19:25:26 +01:00
|
|
|
[clojure.main :as cm]
|
2020-12-24 14:32:19 +01:00
|
|
|
[clojure.spec.alpha :as s]
|
2021-01-31 19:25:26 +01:00
|
|
|
[integrant.core :as ig]))
|
2020-12-24 14:32:19 +01:00
|
|
|
|
|
|
|
(defn- repl-init
|
|
|
|
[]
|
|
|
|
(ccs/repl-init)
|
|
|
|
(in-ns 'app.srepl.main))
|
|
|
|
|
|
|
|
(defn repl
|
|
|
|
[]
|
|
|
|
(cm/repl
|
|
|
|
:init repl-init
|
|
|
|
:read ccs/repl-read))
|
|
|
|
|
|
|
|
;; --- State initialization
|
|
|
|
|
|
|
|
(s/def ::name ::us/not-empty-string)
|
|
|
|
(s/def ::port int?)
|
|
|
|
(s/def ::host ::us/not-empty-string)
|
|
|
|
|
|
|
|
(defmethod ig/pre-init-spec ::server
|
|
|
|
[_]
|
|
|
|
(s/keys :opt-un [::port ::host ::name]))
|
|
|
|
|
|
|
|
(defmethod ig/prep-key ::server
|
|
|
|
[_ cfg]
|
2021-01-27 17:31:17 +01:00
|
|
|
(merge {:name "main"} cfg))
|
2020-12-24 14:32:19 +01:00
|
|
|
|
|
|
|
(defmethod ig/init-key ::server
|
|
|
|
[_ {:keys [port host name] :as cfg}]
|
2021-07-07 10:31:01 +02:00
|
|
|
(when (and port host name)
|
|
|
|
(l/info :msg "initializing server repl" :port port :host host :name name)
|
|
|
|
(ccs/start-server {:address host
|
|
|
|
:port port
|
|
|
|
:name name
|
|
|
|
:accept 'app.srepl/repl})
|
|
|
|
cfg))
|
2020-12-24 14:32:19 +01:00
|
|
|
|
|
|
|
(defmethod ig/halt-key! ::server
|
|
|
|
[_ cfg]
|
2021-07-07 10:31:01 +02:00
|
|
|
(when cfg
|
|
|
|
(ccs/stop-server (:name cfg))))
|
2020-12-24 14:32:19 +01:00
|
|
|
|
|
|
|
|