Use ArrayBuffer, no longer resend noop's due to acknowledgements
This commit is contained in:
parent
ecad54efb3
commit
16ac40daba
|
@ -31,6 +31,9 @@
|
||||||
:data-threshold (* 10 1024)
|
:data-threshold (* 10 1024)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
(def noop-string "[\"noop\"]")
|
||||||
|
|
||||||
;; almost all special cases are for making this work with IE
|
;; almost all special cases are for making this work with IE
|
||||||
(def ie-headers
|
(def ie-headers
|
||||||
{"Content-Type" "text/html"})
|
{"Content-Type" "text/html"})
|
||||||
|
@ -208,10 +211,10 @@
|
||||||
(outstanding-bytes [this])
|
(outstanding-bytes [this])
|
||||||
)
|
)
|
||||||
|
|
||||||
(deftype ArrayBuffer [;; id of the next array that is conj'ed, can't
|
(deftype ArrayBuffer [;; id of the last array that is conj'ed, can't
|
||||||
;; always be derived because flush buffer might
|
;; always be derived because flush buffer might
|
||||||
;; be empty
|
;; be empty
|
||||||
next-array-id
|
array-id
|
||||||
|
|
||||||
;; needed for session status
|
;; needed for session status
|
||||||
last-acknowledged-id
|
last-acknowledged-id
|
||||||
|
@ -227,10 +230,11 @@
|
||||||
]
|
]
|
||||||
IArrayBuffer
|
IArrayBuffer
|
||||||
(queue [this string]
|
(queue [this string]
|
||||||
(ArrayBuffer. (inc next-array-id)
|
(let [next-array-id (inc array-id)]
|
||||||
last-acknowledged-id
|
(ArrayBuffer. next-array-id
|
||||||
to-acknowledge-arrays
|
last-acknowledged-id
|
||||||
(conj to-flush-arrays [next-array-id string])))
|
to-acknowledge-arrays
|
||||||
|
(conj to-flush-arrays [next-array-id string]))))
|
||||||
|
|
||||||
;; id may cause the following splits:
|
;; id may cause the following splits:
|
||||||
;; normal case:
|
;; normal case:
|
||||||
|
@ -242,7 +246,7 @@
|
||||||
;; everything before id can be discarded, everything after id
|
;; everything before id can be discarded, everything after id
|
||||||
;; becomes new flush-arrs and is resend
|
;; becomes new flush-arrs and is resend
|
||||||
(acknowledge-id [this id]
|
(acknowledge-id [this id]
|
||||||
(ArrayBuffer. next-array-id
|
(ArrayBuffer. array-id
|
||||||
id
|
id
|
||||||
clojure.lang.PersistentQueue/EMPTY
|
clojure.lang.PersistentQueue/EMPTY
|
||||||
(into (drop-queue to-acknowledge-arrays id)
|
(into (drop-queue to-acknowledge-arrays id)
|
||||||
|
@ -252,11 +256,11 @@
|
||||||
;; to-flush-arrays is empty
|
;; to-flush-arrays is empty
|
||||||
(to-flush [this]
|
(to-flush [this]
|
||||||
(when-let [to-flush (seq to-flush-arrays)]
|
(when-let [to-flush (seq to-flush-arrays)]
|
||||||
[to-flush (ArrayBuffer. next-array-id
|
[to-flush (ArrayBuffer. array-id
|
||||||
last-acknowledged-id
|
last-acknowledged-id
|
||||||
(into to-acknowledge-arrays
|
(into to-acknowledge-arrays
|
||||||
(remove (fn [[id string]]
|
(remove (fn [[id string]]
|
||||||
(= string "[\"noop\"]"))
|
(= string noop-string))
|
||||||
to-flush))
|
to-flush))
|
||||||
clojure.lang.PersistentQueue/EMPTY)]))
|
clojure.lang.PersistentQueue/EMPTY)]))
|
||||||
(last-acknowledged-id [this]
|
(last-acknowledged-id [this]
|
||||||
|
@ -386,7 +390,7 @@
|
||||||
(let [session-agent *agent*]
|
(let [session-agent *agent*]
|
||||||
(schedule (fn []
|
(schedule (fn []
|
||||||
(send-off session-agent #(-> %
|
(send-off session-agent #(-> %
|
||||||
(queue-string "[\"noop\"]")
|
(queue-string noop-string)
|
||||||
flush-buffer)))
|
flush-buffer)))
|
||||||
(:heartbeat-interval details))))))
|
(:heartbeat-interval details))))))
|
||||||
(clear-session-timeout [this]
|
(clear-session-timeout [this]
|
||||||
|
@ -485,7 +489,9 @@
|
||||||
details
|
details
|
||||||
nil ;; backchannel
|
nil ;; backchannel
|
||||||
(ArrayBuffer.
|
(ArrayBuffer.
|
||||||
0 ;; next-array-id
|
0 ;; array-id, 0 is never used by the
|
||||||
|
;; array-buffer, it is used by the
|
||||||
|
;; first message with the session id
|
||||||
0 ;; last-acknowledged-id
|
0 ;; last-acknowledged-id
|
||||||
;; to-acknowledge-arrays
|
;; to-acknowledge-arrays
|
||||||
clojure.lang.PersistentQueue/EMPTY
|
clojure.lang.PersistentQueue/EMPTY
|
||||||
|
|
Reference in a new issue