Created
October 7, 2014 13:20
-
-
Save fogus/5db69dc7a101e6e3fa40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defrecord Server [service-map] | |
component/Lifecycle | |
(start [component] | |
(info :msg "Starting server.") | |
(let [server (bootstrap/create-server (:service-map service-map))] | |
(bootstrap/start server) | |
(assoc component :server server))) | |
(stop [component] | |
(info :msg "Stopping server.") | |
(update-in component [:server] bootstrap/stop))) | |
(definterceptorfn add-conn | |
[conn] | |
(on-request ::add-conn #(assoc % :conn conn))) | |
(defrecord ServiceMap [service-data conn] | |
component/Lifecycle | |
(start [component] | |
(info :msg "Adding connection interceptor to service-map.") | |
(let [service-map (update-in service-data | |
[::bootstrap/interceptors] | |
conj (add-conn (:conn conn)))] | |
(assoc component :service-map service-map))) | |
(stop [component] | |
(info :msg "Removing connection interceptor from service-map.") | |
(update-in component | |
[:service-map ::bootstrap/interceptors] | |
pop))) | |
(defn mk-service-map | |
[conn & [opts]] | |
(map->ServiceMap {:service-data (merge service/service opts)})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment