1
- using Mux, MemPool, Distributed, Sockets
1
+ using Mux, Sockets
2
+ import HTTP
3
+ import HTTP: WebSockets
4
+ using MemPool, Distributed
2
5
3
6
struct LinePlot
4
7
core_key:: Symbol
@@ -172,22 +175,22 @@ function client_handler(sock, id, port, port_range, config_updated, config, seek
172
175
if id != myid ()
173
176
fsock_ready = Base. Event ()
174
177
worker_host, worker_port = worker_host_port (id, port, port_range)
175
- Mux . HTTP . WebSockets. open (" ws://$worker_host :$worker_port /data_feed" ) do _fsock
178
+ WebSockets. open (" ws://$worker_host :$worker_port /data_feed" ) do _fsock
176
179
fsock = _fsock
177
180
@debug " D3R forwarder for $id ready"
178
181
notify (fsock_ready)
179
- while ! eof (fsock) && isopen (fsock)
182
+ while true
180
183
try
181
- bytes = readavailable (fsock)
184
+ bytes = WebSockets . receive (fsock)
182
185
if length (bytes) == 0
183
186
sleep (0.1 )
184
187
continue
185
188
end
186
189
data = String (bytes)
187
190
# @info "D3R forwarder for $id received data"
188
- write (sock, data)
191
+ WebSockets . send (sock, data)
189
192
catch err
190
- if err isa Mux . WebSockets. WebSocketClosedError || err isa Base . IOError
193
+ if err isa WebSockets. WebSocketError && err. message isa WebSockets . CloseFrameBody
191
194
# Force-close client and forwarder
192
195
@async close (sock)
193
196
@async close (fsock)
@@ -203,25 +206,25 @@ function client_handler(sock, id, port, port_range, config_updated, config, seek
203
206
end
204
207
if id == myid ()
205
208
@debug " D3R client for $id sending initial config"
206
- write (sock, JSON3. write ((;cmd= " data" , payload= sanitize (D3R_LOGS[port]))))
209
+ WebSockets . send (sock, JSON3. write ((;cmd= " data" , payload= sanitize (D3R_LOGS[port]))))
207
210
_workers = workers ()
208
211
if ! (myid () in _workers)
209
212
# FIXME : Get this from the Context
210
213
_workers = vcat (myid (), _workers)
211
214
end
212
- write (sock, JSON3. write ((;cmd= " config" , payload= sanitize ((;myid= myid (),workers= _workers,ctxs= config)))))
215
+ WebSockets . send (sock, JSON3. write ((;cmd= " config" , payload= sanitize ((;myid= myid (),workers= _workers,ctxs= config)))))
213
216
end
214
217
push! (get! (()-> [], D3R_CLIENT_SOCKETS[port], id), sock)
215
218
@debug " D3R client for $id ready"
216
- while ! eof (sock) && isopen (sock)
219
+ while true
217
220
try
218
- data = String (read (sock))
221
+ data = String (WebSockets . receive (sock))
219
222
@debug " D3R client for $id received: $data "
220
223
if id == myid ()
221
224
#= FIXME
222
225
if config_updated[]
223
226
config_updated[] = false
224
- write (sock, JSON3.write((;cmd="config", payload=sanitize(config))))
227
+ WebSockets.send (sock, JSON3.write((;cmd="config", payload=sanitize(config))))
225
228
end
226
229
=#
227
230
if seek_store != = nothing
@@ -231,7 +234,7 @@ function client_handler(sock, id, port, port_range, config_updated, config, seek
231
234
for (idx,key) in enumerate (Tables. columnnames (raw_logs))
232
235
logs[key] = Tables. columns (raw_logs)[idx]
233
236
end
234
- write (sock, JSON3. write ((;cmd= " data" , payload= sanitize (logs))))
237
+ WebSockets . send (sock, JSON3. write ((;cmd= " data" , payload= sanitize (logs))))
235
238
continue
236
239
end
237
240
m = match (r" seek\( ([0-9]*),([0-9]*)\) " , data)
@@ -242,19 +245,19 @@ function client_handler(sock, id, port, port_range, config_updated, config, seek
242
245
for (idx,key) in enumerate (Tables. columnnames (raw_logs))
243
246
logs[key] = Tables. columns (raw_logs)[idx]
244
247
end
245
- write (sock, JSON3. write ((;cmd= " data" , payload= sanitize (logs))))
248
+ WebSockets . send (sock, JSON3. write ((;cmd= " data" , payload= sanitize (logs))))
246
249
continue
247
250
end
248
251
end
249
252
if data == " data"
250
- write (sock, JSON3. write ((;cmd= " data" , payload= sanitize (D3R_LOGS[port]))))
253
+ WebSockets . send (sock, JSON3. write ((;cmd= " data" , payload= sanitize (D3R_LOGS[port]))))
251
254
end
252
255
else
253
256
@debug " D3R client sending to forwarder: $data "
254
- write (fsock, data)
257
+ WebSockets . send (fsock, data)
255
258
end
256
259
catch err
257
- if err isa Mux . WebSockets. WebSocketClosedError || err isa Base . IOError
260
+ if err isa WebSockets. WebSocketError && err. message isa WebSockets . CloseFrameBody
258
261
idx = findfirst (x-> x== sock, D3R_CLIENT_SOCKETS[port][id])
259
262
if idx != = nothing
260
263
deleteat! (D3R_CLIENT_SOCKETS[port][id], idx)
273
276
function TimespanLogging. Events. creation_hook (d3r:: D3Renderer , log)
274
277
for sock in get! (()-> [], get! (()-> Dict {Int,Vector{Any}} (), D3R_CLIENT_SOCKETS, d3r. port), myid ())
275
278
try
276
- if isopen (sock)
277
- write (sock, JSON3. write ((;cmd= " add" , payload= sanitize (log))))
278
- end
279
+ WebSockets. send (sock, JSON3. write ((;cmd= " add" , payload= sanitize (log))))
279
280
catch err
280
- if err isa Mux . WebSockets. WebSocketClosedError
281
+ if err isa WebSockets . WebSocketError && err . message isa WebSockets. CloseFrameBody
281
282
continue
282
283
end
283
284
rethrow (err)
287
288
function TimespanLogging. Events. deletion_hook (d3r:: D3Renderer , idx)
288
289
for sock in get! (()-> [], get! (()-> Dict {Int,Vector{Any}} (), D3R_CLIENT_SOCKETS, d3r. port), myid ())
289
290
try
290
- if isopen (sock)
291
- write (sock, JSON3. write ((;cmd= " delete" , payload= idx)))
292
- end
291
+ WebSockets. send (sock, JSON3. write ((;cmd= " delete" , payload= idx)))
293
292
catch err
294
- if err isa Mux . WebSockets. WebSocketClosedError
293
+ if err isa WebSockets . WebSocketError && err . message isa WebSockets. CloseFrameBody
295
294
continue
296
295
end
297
296
rethrow (err)
0 commit comments