Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 352
Provides Prioritised delivering of Zero Streams Frames#718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
08cefe0111a3b837142ea922effd70ec02e39a74d7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -56,6 +56,7 @@ public final class UnboundedProcessor<T> extends FluxProcessor<T, T> | ||
| AtomicLongFieldUpdater.newUpdater(UnboundedProcessor.class, "requested"); | ||
| final Queue<T> queue; | ||
| final Queue<T> priorityQueue; | ||
| volatile boolean done; | ||
| Throwable error; | ||
| volatile CoreSubscriber<? super T> actual; | ||
| @@ -67,11 +68,12 @@ public final class UnboundedProcessor<T> extends FluxProcessor<T, T> | ||
| public UnboundedProcessor() { | ||
| this.queue = new MpscUnboundedArrayQueue<>(Queues.SMALL_BUFFER_SIZE); | ||
| this.priorityQueue = new MpscUnboundedArrayQueue<>(Queues.SMALL_BUFFER_SIZE); | ||
| } | ||
| @Override | ||
| public int getBufferSize() { | ||
| return Queues.capacity(this.queue); | ||
| return Integer.MAX_VALUE; | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch | ||
| } | ||
| @Override | ||
| @@ -84,6 +86,7 @@ void drainRegular(Subscriber<? super T> a) { | ||
| int missed = 1; | ||
| final Queue<T> q = queue; | ||
| final Queue<T> pq = priorityQueue; | ||
| for (; ; ) { | ||
| @@ -93,10 +96,18 @@ void drainRegular(Subscriber<? super T> a) { | ||
| while (r != e) { | ||
| boolean d = done; | ||
| T t = q.poll(); | ||
| boolean empty = t == null; | ||
| T t; | ||
| boolean empty; | ||
| if (!pq.isEmpty()) { | ||
| t = pq.poll(); | ||
| empty = false; | ||
| } else { | ||
| t = q.poll(); | ||
| empty = t == null; | ||
| } | ||
| if (checkTerminated(d, empty, a, q)) { | ||
| if (checkTerminated(d, empty, a)) { | ||
| return; | ||
| } | ||
| @@ -110,7 +121,7 @@ void drainRegular(Subscriber<? super T> a) { | ||
| } | ||
| if (r == e) { | ||
| if (checkTerminated(done, q.isEmpty(), a, q)) { | ||
| if (checkTerminated(done, q.isEmpty() && pq.isEmpty(), a)) { | ||
| return; | ||
| } | ||
| } | ||
| @@ -129,12 +140,10 @@ void drainRegular(Subscriber<? super T> a) { | ||
| void drainFused(Subscriber<? super T> a) { | ||
| int missed = 1; | ||
| final Queue<T> q = queue; | ||
| for (; ; ) { | ||
| if (cancelled) { | ||
| q.clear(); | ||
| clear(); | ||
| actual = null; | ||
| return; | ||
| } | ||
| @@ -188,14 +197,9 @@ public void drain() { | ||
| } | ||
| } | ||
| boolean checkTerminated(boolean d, boolean empty, Subscriber<? super T> a, Queue<T> q) { | ||
| boolean checkTerminated(boolean d, boolean empty, Subscriber<? super T> a) { | ||
| if (cancelled) { | ||
| while (!q.isEmpty()) { | ||
| T t = q.poll(); | ||
| if (t != null) { | ||
| release(t); | ||
| } | ||
| } | ||
| clear(); | ||
| actual = null; | ||
| return true; | ||
| } | ||
| @@ -237,6 +241,23 @@ public Context currentContext() { | ||
| return actual != null ? actual.currentContext() : Context.empty(); | ||
| } | ||
| public void onNextPrioritized(T t) { | ||
| if (done || cancelled) { | ||
| Operators.onNextDropped(t, currentContext()); | ||
| release(t); | ||
| return; | ||
| } | ||
| if (!priorityQueue.offer(t)) { | ||
| Throwable ex = | ||
| Operators.onOperatorError(null, Exceptions.failWithOverflow(), t, currentContext()); | ||
| onError(Operators.onOperatorError(null, ex, t, currentContext())); | ||
| release(t); | ||
| return; | ||
| } | ||
| drain(); | ||
| } | ||
| @Override | ||
| public void onNext(T t) { | ||
| if (done || cancelled) { | ||
| @@ -319,25 +340,24 @@ public void cancel() { | ||
| } | ||
| } | ||
| @Override | ||
| public T peek() { | ||
| return queue.peek(); | ||
| } | ||
| @Override | ||
| @Nullable | ||
| public T poll() { | ||
| Queue<T> pq = this.priorityQueue; | ||
| if (!pq.isEmpty()) { | ||
| return pq.poll(); | ||
| } | ||
| return queue.poll(); | ||
| } | ||
| @Override | ||
| public int size() { | ||
| return queue.size(); | ||
| return priorityQueue.size() + queue.size(); | ||
| } | ||
| @Override | ||
| public boolean isEmpty() { | ||
| return queue.isEmpty(); | ||
| return priorityQueue.isEmpty() && queue.isEmpty(); | ||
| } | ||
| @Override | ||
| @@ -348,6 +368,12 @@ public void clear() { | ||
| release(t); | ||
| } | ||
| } | ||
| while (!priorityQueue.isEmpty()) { | ||
| T t = priorityQueue.poll(); | ||
| if (t != null) { | ||
| release(t); | ||
| } | ||
| } | ||
| } | ||
| @Override | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should tighten this up in the spec, whether it's stream 0 prioritised or KEEPALIVE and LEASE only as you have implemented. I'll generally defer to @robertroeser for this, but put my thoughts on the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely. I have already created an issue on that!