Skip to content

Commit

Permalink
Started working on a TCP server for the CLI.
Browse files Browse the repository at this point in the history
This will be to avoid the long wait times for the JVM startup.
  • Loading branch information
ryugi committed May 24, 2017
1 parent c7eb7fb commit ea584b8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/clj/timi/config.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns timi.config
(:require [clojure.edn]
[clojure.java.io]))
(:require
[clojure.edn]
[clojure.java.io]))

(def config-file (clojure.java.io/resource "config.edn"))

Expand Down
1 change: 1 addition & 0 deletions src/clj/timi/server/cli/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns timi.server.cli.core)
2 changes: 1 addition & 1 deletion src/clj/timi/cli.clj → src/clj/timi/server/cli/old.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns timi.cli
(ns timi.server.cli.old
(:require
[clojure.pprint :refer [pprint]]
[timi.config :as config]
Expand Down
45 changes: 45 additions & 0 deletions src/clj/timi/server/cli/tcp.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(ns timi.server.cli.tcp
(:require
[clojure.tools.logging :as log]
[net.tcp :as tcp]
[net.ty.channel :as channel]
[net.ty.pipeline :as pipeline]
[timi.config :as config]
[timi.server.cli.core : as cli]))

(def config (config/read-config))

(defn parse-commands
[cmds]
(log/info "In parse-commands, got:" cmds)
cmds)

(defn run-commands
[cmds]
(log/info "In run-commands, got:" cmds)
cmds)

(defn pipeline
[]
(pipeline/channel-initializer
[(pipeline/line-based-frame-decoder)
pipeline/string-decoder
pipeline/string-encoder
pipeline/line-frame-encoder
(pipeline/with-input [ctx msg]
(channel/write-and-flush! ctx (-> msg
(parse-commands)
(run-commands))))]))

(defn serve
([]
(serve config))
([config]
(tcp/server
{:handler (pipeline)}
(get-in config [:cli :server :host])
(get-in config [:cli :server :port]))))

(defn -main
[& _]
(serve))
12 changes: 10 additions & 2 deletions src/clj/timi/server/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[trifl.java :as java])
(:gen-class))

(def config (timi.config/read-config))
(def config (config/read-config))

(logger/set-level! (get-in config [:log :ns])
(get-in config [:log :level]))
Expand All @@ -20,9 +20,17 @@
"Used by the ring handler configuration in project.clj."
(web/app config))

(defn get-system
([]
(get-system #'app config))
([config]
(get-system (web/app config) config))
([app config]
(components/init app config)))

(defn -main
[& args]
(let [system (components/init #'app config)]
(let [system (get-system)]
(log/info "Starting Tímı ...")
(component/start system)
;; Setup interrupt/terminate handling
Expand Down

0 comments on commit ea584b8

Please sign in to comment.