|
69 | 69 |
|
70 | 70 | (defn wrap-channel
|
71 | 71 | "Make io.netty.channel.Channel look a bit like a clojure map of the Channel's AttributeMap.
|
72 |
| - Only supports plain keyword keys. Doesn't distinguish between Attribute with nil value and absent attribute." |
| 72 | + Only supports plain keyword keys. Doesn't distinguish between Attribute with nil value and absent attribute. |
| 73 | + NB Can't seq properly yet." |
73 | 74 | [^Channel channel]
|
74 | 75 | (reify
|
75 | 76 | ILookup
|
|
101 | 102 | ; Counted:
|
102 | 103 | (count [_] (unsupported "This is a wrapped io.netty.channel.Channel. No count."))))
|
103 | 104 |
|
| 105 | +(defn channels |
| 106 | + "Workaround for inability to reify seq (see `wrap-channel-group`). |
| 107 | + Returns map of ChannelId -> Channel (not wrapped)." |
| 108 | + [{:keys [clients] :as server}] |
| 109 | + (->> clients .iterator iterator-seq (map (fn [ch] [(.id ch) ch])) (into {}))) |
| 110 | + |
104 | 111 | (defn wrap-channel-group
|
105 | 112 | "Make io.netty.channel.group.ChannelGroup look a bit like a clojure map of `ChannelId` -> `Channel`.
|
106 | 113 | Each `Channel` is wrapped with `wrap-channel`.
|
107 |
| - NB Can't seq properly yet!!, use `(iterator-seq (.iterator x))` to get seq of raw channels..." |
| 114 | + NB Can't seq properly yet, see `channels` instead." |
108 | 115 | ; It's already a java.util.Set<io.netty.channel.Channel>.
|
109 | 116 | ; Don't want to bring in clj-commons/potemkin for def-map-type!
|
110 | 117 | [^ChannelGroup channel-group]
|
|
131 | 138 | ;; (map (fn [^Channel ch]
|
132 | 139 | ;; (log/debug "Trying to create MapEntry for" (.id ch))
|
133 | 140 | ;; (MapEntry. (.id ch) (wrap-channel ch))) channel-group))
|
134 |
| - Iterable ;; NB these pretend it's just a Set |
| 141 | + Iterable |
135 | 142 | ;; (forEach [_ action] (.forEach channel-group action))
|
136 |
| - (iterator [_] (.iterator channel-group)) |
| 143 | + (iterator [_] (.iterator channel-group)) ; NB returns channels, not wrapped! |
137 | 144 | ;;(spliterator [_] (.spliterator channel-group))
|
138 | 145 | ILookup
|
139 | 146 | (valAt [_ k]
|
|
0 commit comments