minor cleanups and addition of missing function doc comments
This commit is contained in:
parent
123b343e81
commit
eed182bdd1
|
@ -1,6 +1,6 @@
|
||||||
(ns views.core
|
(ns views.core
|
||||||
(:import
|
(:import
|
||||||
[java.util.concurrent ArrayBlockingQueue TimeUnit]
|
(java.util.concurrent ArrayBlockingQueue TimeUnit)
|
||||||
(clojure.lang Atom))
|
(clojure.lang Atom))
|
||||||
(:require
|
(:require
|
||||||
[views.protocols :refer [IView id data relevant?]]
|
[views.protocols :refer [IView id data relevant?]]
|
||||||
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
|
|
||||||
(defn reset-stats!
|
(defn reset-stats!
|
||||||
|
"Resets statistics collected back to zero."
|
||||||
[^Atom view-system]
|
[^Atom view-system]
|
||||||
(swap! view-system update-in [:statistics] assoc
|
(swap! view-system update-in [:statistics] assoc
|
||||||
:refreshes 0
|
:refreshes 0
|
||||||
|
@ -37,7 +38,8 @@
|
||||||
:deduplicated 0)
|
:deduplicated 0)
|
||||||
view-system)
|
view-system)
|
||||||
|
|
||||||
(defn collect-stats?
|
(defn collecting-stats?
|
||||||
|
"Whether view statem statistics collection and logging is enabled or not."
|
||||||
[^Atom view-system]
|
[^Atom view-system]
|
||||||
(boolean (get-in @view-system [:statistics :logger])))
|
(boolean (get-in @view-system [:statistics :logger])))
|
||||||
|
|
||||||
|
@ -199,10 +201,10 @@
|
||||||
(if (relevant? v namespace parameters hints)
|
(if (relevant? v namespace parameters hints)
|
||||||
(if-not (.contains refresh-queue view-sig)
|
(if-not (.contains refresh-queue view-sig)
|
||||||
(when-not (.offer refresh-queue view-sig)
|
(when-not (.offer refresh-queue view-sig)
|
||||||
(if (collect-stats? view-system) (swap! view-system update-in [:statistics :dropped] inc))
|
(if (collecting-stats? view-system) (swap! view-system update-in [:statistics :dropped] inc))
|
||||||
(error "refresh-queue full, dropping refresh request for" view-sig))
|
(error "refresh-queue full, dropping refresh request for" view-sig))
|
||||||
(do
|
(do
|
||||||
(if (collect-stats? view-system) (swap! view-system update-in [:statistics :deduplicated] inc))
|
(if (collecting-stats? view-system) (swap! view-system update-in [:statistics :deduplicated] inc))
|
||||||
(trace "already queued for refresh" view-sig))))
|
(trace "already queued for refresh" view-sig))))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(error e "error determining if view is relevant" view-sig))))
|
(error e "error determining if view is relevant" view-sig))))
|
||||||
|
@ -247,7 +249,7 @@
|
||||||
|
|
||||||
(defn do-view-refresh!
|
(defn do-view-refresh!
|
||||||
[^Atom view-system {:keys [namespace view-id parameters] :as view-sig}]
|
[^Atom view-system {:keys [namespace view-id parameters] :as view-sig}]
|
||||||
(if (collect-stats? view-system) (swap! view-system update-in [:statistics :refreshes] inc))
|
(if (collecting-stats? view-system) (swap! view-system update-in [:statistics :refreshes] inc))
|
||||||
(try
|
(try
|
||||||
(let [view (get-in @view-system [:views view-id])
|
(let [view (get-in @view-system [:views view-id])
|
||||||
vdata (data view namespace parameters)
|
vdata (data view namespace parameters)
|
||||||
|
@ -394,14 +396,14 @@
|
||||||
((:put-hints-fn @view-system) view-system hints)
|
((:put-hints-fn @view-system) view-system hints)
|
||||||
view-system)
|
view-system)
|
||||||
|
|
||||||
(defn- get-views-map
|
(defn- ->views-map
|
||||||
[views]
|
[views]
|
||||||
(map vector (map id views) views))
|
(map vector (map id views) views))
|
||||||
|
|
||||||
(defn add-views!
|
(defn add-views!
|
||||||
"Add a collection of views to the system."
|
"Add a collection of views to the system."
|
||||||
[^Atom view-system views]
|
[^Atom view-system views]
|
||||||
(swap! view-system update-in [:views] (fnil into {}) (get-views-map views))
|
(swap! view-system update-in [:views] (fnil into {}) (->views-map views))
|
||||||
view-system)
|
view-system)
|
||||||
|
|
||||||
(def default-options
|
(def default-options
|
||||||
|
@ -478,7 +480,7 @@
|
||||||
(trace "initializing views system using options:" options)
|
(trace "initializing views system using options:" options)
|
||||||
(reset! view-system
|
(reset! view-system
|
||||||
{:refresh-queue (ArrayBlockingQueue. (:refresh-queue-size options))
|
{:refresh-queue (ArrayBlockingQueue. (:refresh-queue-size options))
|
||||||
:views (into {} (get-views-map (:views options)))
|
:views (into {} (->views-map (:views options)))
|
||||||
:send-fn (:send-fn options)
|
:send-fn (:send-fn options)
|
||||||
:put-hints-fn (:put-hints-fn options)
|
:put-hints-fn (:put-hints-fn options)
|
||||||
:auth-fn (:auth-fn options)
|
:auth-fn (:auth-fn options)
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
(contains-view? test-views-system :bar)
|
(contains-view? test-views-system :bar)
|
||||||
(contains-view? test-views-system :baz)))
|
(contains-view? test-views-system :baz)))
|
||||||
(is (not (:logging? @test-views-system)))
|
(is (not (:logging? @test-views-system)))
|
||||||
(is (not (collect-stats? test-views-system)))
|
(is (not (collecting-stats? test-views-system)))
|
||||||
(is (empty? (subscribed-views test-views-system)))
|
(is (empty? (subscribed-views test-views-system)))
|
||||||
(let [refresh-watcher (:refresh-watcher @test-views-system)
|
(let [refresh-watcher (:refresh-watcher @test-views-system)
|
||||||
workers (:workers @test-views-system)]
|
workers (:workers @test-views-system)]
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
(init! test-views-system options)
|
(init! test-views-system options)
|
||||||
(is (seq (:statistics @test-views-system)))
|
(is (seq (:statistics @test-views-system)))
|
||||||
(is (:logging? @test-views-system))
|
(is (:logging? @test-views-system))
|
||||||
(is (collect-stats? test-views-system))
|
(is (collecting-stats? test-views-system))
|
||||||
(let [logger-thread (get-in @test-views-system [:statistics :logger])]
|
(let [logger-thread (get-in @test-views-system [:statistics :logger])]
|
||||||
(is (.isAlive ^Thread logger-thread))
|
(is (.isAlive ^Thread logger-thread))
|
||||||
; 2. shutdown views
|
; 2. shutdown views
|
||||||
|
|
Loading…
Reference in a new issue