1717; ; 2. Static visualization of a sample flow
1818; ; 3. Evolution as the flow changes
1919
20- #_(defmethod print-method clojure.lang.IObj [obj ^java.io.Writer w]
21- )
22-
23-
24- (comment
25- (defmethod print-method clojure.core.async.impl.buffers.SlidingBuffer [buf ^java.io.Writer w]
26- (.write w (str " #sliding-buffer[size=" (.-n buf) " ]" )))
27- (defmethod print-method clojure.core.async.flow.spi.ProcLauncher [launcher ^java.io.Writer w]
28- (.write w " #proc-launcher[]" ))
29- (defmethod print-method clojure.core.async.impl.channels.ManyToManyChannel [ch ^java.io.Writer w]
30- (.write w (str " #chan[buffer-size=" (if (.-buf ch) (count (.-buf ch)) 0 ) " ]" )))
31- (defmethod print-method clojure.core.async.flow.impl.graph.Graph [graph ^java.io.Writer w]
32- (.write w (pr-str (datafy/datafy graph)))))
33- #_(defmethod print-method clojure.core.protocols.Datafiable [x ^java.io.Writer w]
34- (.write w (pr-str (datafy/datafy x))))
35-
36- (defn protocols [x]
37- (->> (class x)
38- .getInterfaces
39- (filter #(-> % .getName (.startsWith " clojure.lang." )))
40- (map #(-> % .getSimpleName (clojure.string/replace #"^\$ " " " )))
41- distinct))
42- stats/config
43- (async/chan 1 )
44- (def stats-flow
45- (flow/create-flow stats/config))
46- (protocols stats-flow)
47- (instance? clojure.core.async.flow.impl.graph.Graph stats-flow)
48-
49- (defn ff [obj w]
50- (let [protocols (->> (class obj) (.getInterfaces ) (map #(.getName %)))]
51- (.write w " #<reified " )
52- (if (seq protocols)
53- (do
54- (.write w " :protocols " )
55- (pr-str protocols w))
56- (.write w " :no-protocols" ))
57- (.write w " >" )))
58-
59- (ff stats-flow *out*)
60- (.getInterfaces (class stats-flow))
61-
62- (defn all-protocol-vars [x]
63- (->> (all-ns )
64- (mapcat ns-publics)
65- (vals )
66- (keep #(-> % meta :protocol ))
67- (distinct )
68- (filter #(satisfies? @% x))))
69-
70- (defn protocol-var-ns-name [p]
71- (-> (meta p) (:ns ) (ns-name )))
72-
73- (map protocol-var-ns-name (all-protocol-vars stats-flow))
74-
75- (defn ff [p x]
76- (str/starts-with? (protocol-var-ns-name p)
77- (-> (class x) (.getPackageName ))))
78-
79- (filter
80- #(ff % stats-flow)
81- (all-protocol-vars stats-flow))
82-
20+ (defn id-for [x]
21+ (cond (keyword? x) (str (symbol x))
22+ (vector? x) (str/join " _" (map id-for x))
23+ (string? x) x
24+ :else (str x)))
8325
8426(defn conn-table [flow]
8527 (let [{:keys [conns procs]} (datafy/datafy flow)
@@ -90,12 +32,6 @@ stats/config
9032 {:source (id-for from)
9133 :target (id-for to)}))}))
9234
93- (defn id-for [x]
94- (cond (keyword? x) (str (symbol x))
95- (vector? x) (str/join " _" (map id-for x))
96- (string? x) x
97- :else (str x)))
98-
9935(defn proc-table [flow]
10036 (let [{:keys [conns procs]} (datafy/datafy flow)
10137 all-proc-chans (into #{} cat conns)]
@@ -118,6 +54,10 @@ stats/config
11854 ^:kind/hiccup
11955 [:div (for [[k v] outs]
12056 [:div [:strong (name k)] " : " v])]]))}))
57+
58+ (def stats-flow
59+ (flow/create-flow stats/config))
60+
12161(proc-table stats-flow)
12262
12363; ; would be more interesting if we show the buffer state
0 commit comments