Skip to content

Commit 9519cf2

Browse files
committed
Initial files.
0 parents  commit 9519cf2

File tree

14 files changed

+526
-0
lines changed

14 files changed

+526
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/target
2+
/classes
3+
/checkouts
4+
pom.xml
5+
pom.xml.asc
6+
*.jar
7+
*.class
8+
/.lein-*
9+
/.nrepl-port

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright © 2018 The Clojang Project
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# component
2+
3+
[![Build Status][travis-badge]][travis]
4+
[![Dependencies Status][deps-badge]][deps]
5+
[![Clojars Project][clojars-badge]][clojars]
6+
7+
*A Clojang life-cycle implementation of the Component library for use in large/complex applications*
8+
9+
[![Project logo][logo]][logo-large]
10+
11+
12+
#### Contents
13+
14+
* [About](#about-)
15+
* [Usage](#usage-)
16+
* [Donating](#donating-)
17+
* [License](#license-)
18+
19+
20+
## About [↟](#contents)
21+
22+
TBD
23+
24+
25+
## Usage [↟](#contents)
26+
27+
TBD
28+
29+
30+
## Donating [↟](#contents)
31+
32+
A donation account for supporting development on this project has been set up
33+
on Liberapay here:
34+
35+
* [https://liberapay.com/clojang/donate](https://liberapay.com/clojang/donate)
36+
37+
You can learn more about Liberapay on its [Wikipedia entry][libera-wiki] or on the
38+
service's ["About" page][libera-about].
39+
40+
[libera-wiki]: https://en.wikipedia.org/wiki/Liberapay
41+
[libera-about]: https://liberapay.com/about/
42+
43+
44+
## License [↟](#contents)
45+
46+
```
47+
Copyright © 2018 The Clojang Project
48+
49+
Distributed under the Apache License Version 2.0.
50+
```
51+
52+
53+
<!-- Named page links below: /-->
54+
55+
[travis]: https://travis-ci.org/clojang/component
56+
[travis-badge]: https://travis-ci.org/clojang/component.png?branch=master
57+
[deps]: http://jarkeeper.com/clojang/component
58+
[deps-badge]: http://jarkeeper.com/clojang/component/status.svg
59+
[clojars]: https://clojars.org/clojang/component
60+
[clojars-badge]: https://img.shields.io/clojars/v/clojang/component.svg
61+
[logo]: https://github.com/clojang/resources/blob/master/images/logo-5-250x.png
62+
[logo-large]: https://github.com/clojang/resources/blob/master/images/logo-5-1000x.png
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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)

project.clj

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
(defn get-banner
2+
[]
3+
(try
4+
(str
5+
(slurp "resources/text/banner.txt")
6+
;(slurp "resources/text/loading.txt")
7+
)
8+
;; If another project can't find the banner, just skip it.
9+
(catch Exception _ "")))
10+
11+
(defn get-prompt
12+
[ns]
13+
(str "\u001B[35m[\u001B[34m"
14+
ns
15+
"\u001B[35m]\u001B[33m λ\u001B[m=> "))
16+
17+
(defproject clojang/component "0.1.0-SNAPSHOT"
18+
:description "A Clojang life-cycle implementation of the Component library for use in large/complex applications"
19+
:url "https://github.com/clojang/component"
20+
:scm {
21+
:name "git"
22+
:url "https://github.com/clojang/component"}
23+
:license {
24+
:name "Apache License, Version 2.0"
25+
:url "http://www.apache.org/licenses/LICENSE-2.0"}
26+
:dependencies [
27+
[clojusc/dev-system "0.1.0"]
28+
[clojusc/twig "0.3.3"]
29+
[com.stuartsierra/component "0.3.2"]
30+
[org.clojure/clojure "1.9.0"]]
31+
:profiles {
32+
:ubercompile {
33+
:aot :all}
34+
:lint {
35+
:source-paths ^:replace ["src"]
36+
:test-paths ^:replace []
37+
:plugins [
38+
[jonase/eastwood "0.2.8"]
39+
[lein-ancient "0.6.15"]
40+
[lein-bikeshed "0.5.1"]
41+
[lein-kibit "0.1.6"]
42+
[venantius/yagni "0.1.4"]]}
43+
:test {
44+
:aot :all
45+
:plugins [
46+
[lein-ltest "0.3.0"]]
47+
:source-paths ["test"]
48+
:test-selectors {
49+
:default :unit
50+
:unit :unit
51+
:system :system
52+
:integration :integration}}
53+
:dev {
54+
:dependencies [
55+
[clojusc/trifl "0.3.0"]
56+
[org.clojure/tools.namespace "0.2.11"]]
57+
:source-paths ["dev-resources/src"]
58+
:repl-options {
59+
:init-ns clojang.component.repl
60+
:prompt ~get-prompt
61+
:init ~(println (get-banner))}}}
62+
:aliases {
63+
;; Dev Aliases
64+
"repl" ["do"
65+
["clean"]
66+
["repl"]]
67+
"ubercompile" ["do"
68+
["clean"]
69+
["with-profile" "+ubercompile" "compile"]]
70+
"check-vers" ["with-profile" "+lint" "ancient" "check" ":all"]
71+
"check-jars" ["with-profile" "+lint" "do"
72+
["deps" ":tree"]
73+
["deps" ":plugin-tree"]]
74+
"check-deps" ["do"
75+
["check-jars"]
76+
["check-vers"]]
77+
"kibit" ["with-profile" "+lint" "kibit"]
78+
"eastwood" ["with-profile" "+lint" "eastwood" "{:namespaces [:source-paths]}"]
79+
"lint" ["do"
80+
["kibit"]
81+
;["eastwood"]
82+
]
83+
"ltest" ["with-profile" "+test" "ltest"]})
84+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{:logging {
2+
:level :debug
3+
:nss [clojang com.ericsson.otp.erlang jiface]}}

resources/text/banner.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
___| | _)
3+
| | _ \ | _` | __ \ _` |
4+
| | ( | | ( | | | ( |
5+
\____|_|\___/ |\__,_|_| _|\__, |
6+
___/ |___/
7+
---------- ------------ -
8+
- c o m p o n e n t ------------
9+
----------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
(ns clojang.component.components.config
2+
(:require
3+
[clojang.component.config :as config]
4+
[com.stuartsierra.component :as component]
5+
[taoensso.timbre :as log])
6+
(:import
7+
(clojure.lang Keyword)))
8+
9+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10+
;;; Utility Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12+
13+
(defn- get-cfg
14+
[system]
15+
(->> [:config :data]
16+
(get-in system)
17+
(into {})))
18+
19+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20+
;;; Config Component API ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22+
23+
(defn log-level
24+
[system]
25+
(get-in (get-cfg system) [:logging :level]))
26+
27+
(defn log-nss
28+
[system]
29+
(get-in (get-cfg system) [:logging :nss]))
30+
31+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32+
;;; Component Lifecycle Implementation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34+
35+
(defrecord Config [data])
36+
37+
(defn start
38+
[this]
39+
(log/info "Starting config component ...")
40+
(log/debug "Started config component.")
41+
(let [cfg (config/data)]
42+
(log/trace "Built configuration:" cfg)
43+
(assoc this :data cfg)))
44+
45+
(defn stop
46+
[this]
47+
(log/info "Stopping config component ...")
48+
(log/debug "Stopped config component.")
49+
this)
50+
51+
(def lifecycle-behaviour
52+
{:start start
53+
:stop stop})
54+
55+
(extend Config
56+
component/Lifecycle
57+
lifecycle-behaviour)
58+
59+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60+
;;; Component Constructor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62+
63+
(defn create-component
64+
""
65+
[]
66+
(map->Config {}))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(ns clojang.component.components.default-node
2+
(:require
3+
[clojang.component.components.config :as config]
4+
[clojusc.twig :as logger]
5+
[com.stuartsierra.component :as component]
6+
[taoensso.timbre :as log]))
7+
8+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9+
;;; Component Lifecycle Implementation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11+
12+
(defrecord DefaultNode [])
13+
14+
(defn start
15+
[this]
16+
(log/info "Starting default node component ...")
17+
(let [log-level (config/log-level this)
18+
log-nss (config/log-nss this)]
19+
;; XXX TBD
20+
(log/debug "Started default node component.")
21+
this))
22+
23+
(defn stop
24+
[this]
25+
(log/info "Stopping default node component ...")
26+
(log/debug "Stopped default node component.")
27+
this)
28+
29+
(def lifecycle-behaviour
30+
{:start start
31+
:stop stop})
32+
33+
(extend DefaultNode
34+
component/Lifecycle
35+
lifecycle-behaviour)
36+
37+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38+
;;; Component Constructor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40+
41+
(defn create-component
42+
""
43+
[]
44+
(map->DefaultNode {}))

0 commit comments

Comments
 (0)