author | dfuchs |
Mon, 06 Nov 2017 18:17:09 +0000 | |
branch | http-client-branch |
changeset 55768 | 8674257c75ce |
parent 55763 | 634d8e14c172 |
child 55792 | 0936888d5a4a |
permissions | -rw-r--r-- |
55763 | 1 |
/* |
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.incubator.http.internal.common; |
|
27 |
||
28 |
import java.io.Closeable; |
|
29 |
import java.lang.System.Logger.Level; |
|
30 |
import java.nio.ByteBuffer; |
|
31 |
import java.util.List; |
|
32 |
import java.util.Objects; |
|
33 |
import java.util.concurrent.CompletableFuture; |
|
34 |
import java.util.concurrent.ConcurrentLinkedQueue; |
|
35 |
import java.util.concurrent.Flow; |
|
36 |
import java.util.concurrent.Flow.Subscriber; |
|
37 |
import java.util.concurrent.atomic.AtomicLong; |
|
38 |
import java.util.concurrent.atomic.AtomicReference; |
|
39 |
||
40 |
/** |
|
41 |
* A wrapper for a Flow.Subscriber. This wrapper delivers data to the wrapped |
|
42 |
* Subscriber which is supplied to the constructor. This class takes care of |
|
43 |
* downstream flow control automatically and upstream flow control automatically |
|
44 |
* by default. |
|
45 |
* <p> |
|
46 |
* Processing is done by implementing the {@link #incoming(List, boolean)} method |
|
47 |
* which supplies buffers from upstream. This method (or any other method) |
|
48 |
* can then call the outgoing() method to deliver processed buffers downstream. |
|
49 |
* <p> |
|
50 |
* Upstream error signals are delivered downstream directly. Cancellation from |
|
51 |
* downstream is also propagated upstream immediately. |
|
52 |
* <p> |
|
53 |
* Each SubscriberWrapper has a {@link java.util.concurrent.CompletableFuture}{@code <Void>} |
|
54 |
* which propagates completion/errors from downstream to upstream. Normal completion |
|
55 |
* can only occur after onComplete() is called, but errors can be propagated upwards |
|
56 |
* at any time. |
|
57 |
*/ |
|
58 |
public abstract class SubscriberWrapper |
|
59 |
implements FlowTube.TubeSubscriber, Closeable, Flow.Processor<List<ByteBuffer>,List<ByteBuffer>> |
|
60 |
// TODO: SSLTube Subscriber will never change? Does this really need to be a TS? |
|
61 |
{ |
|
62 |
static final boolean DEBUG = Utils.DEBUG;; // Revisit: temporary dev flag. |
|
63 |
final System.Logger logger = |
|
64 |
Utils.getDebugLogger(this::dbgString, DEBUG); |
|
65 |
||
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
66 |
public enum SchedulingAction { CONTINUE, RETURN, RESCHEDULE }; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
67 |
|
55763 | 68 |
volatile Flow.Subscription upstreamSubscription; |
69 |
final SubscriptionBase downstreamSubscription; |
|
70 |
volatile boolean upstreamCompleted; |
|
71 |
volatile boolean downstreamCompleted; |
|
72 |
volatile boolean completionAcknowledged; |
|
73 |
private volatile Subscriber<? super List<ByteBuffer>> downstreamSubscriber; |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
74 |
// processed byte to send to the downstream subscriber. |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
75 |
private final ConcurrentLinkedQueue<List<ByteBuffer>> outputQ; |
55763 | 76 |
private final CompletableFuture<Void> cf; |
77 |
private final SequentialScheduler pushScheduler; |
|
78 |
private final AtomicReference<Throwable> errorRef = new AtomicReference<>(); |
|
79 |
||
80 |
/** |
|
81 |
* Wraps the given downstream subscriber. For each call to {@link |
|
82 |
* #onNext(List<ByteBuffer>) } the given filter function is invoked |
|
83 |
* and the list (if not empty) returned is passed downstream. |
|
84 |
* |
|
85 |
* A {@code CompletableFuture} is supplied which can be used to signal an |
|
86 |
* error from downstream and which terminates the wrapper or which signals |
|
87 |
* completion of downstream activity which can be propagated upstream. Error |
|
88 |
* completion can be signaled at any time, but normal completion must not be |
|
89 |
* signaled before onComplete() is called. |
|
90 |
*/ |
|
91 |
public SubscriberWrapper() |
|
92 |
{ |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
93 |
this.outputQ = new ConcurrentLinkedQueue<>(); |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
94 |
this.cf = new MinimalFuture<>(); |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
95 |
this.pushScheduler = |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
96 |
SequentialScheduler.synchronizedScheduler(new DownstreamPusher()); |
55763 | 97 |
this.downstreamSubscription = new SubscriptionBase(pushScheduler, |
98 |
this::downstreamCompletion); |
|
99 |
} |
|
100 |
||
101 |
@Override |
|
102 |
public final void subscribe(Subscriber<? super List<ByteBuffer>> downstreamSubscriber) { |
|
103 |
Objects.requireNonNull(downstreamSubscriber); |
|
104 |
this.downstreamSubscriber = downstreamSubscriber; |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Wraps the given downstream wrapper in this. For each call to |
|
109 |
* {@link #onNext(List<ByteBuffer>) } the incoming() method is called. |
|
110 |
* |
|
111 |
* The {@code downstreamCF} from the downstream wrapper is linked to this |
|
112 |
* wrappers notifier. |
|
113 |
* |
|
114 |
* @param downstreamWrapper downstream destination |
|
115 |
*/ |
|
116 |
public SubscriberWrapper(Subscriber<? super List<ByteBuffer>> downstreamWrapper) |
|
117 |
{ |
|
118 |
this(); |
|
119 |
subscribe(downstreamWrapper); |
|
120 |
} |
|
121 |
||
122 |
/** |
|
123 |
* Delivers data to be processed by this wrapper. Generated data to be sent |
|
124 |
* downstream, must be provided to the {@link #outgoing(List, boolean)}} |
|
125 |
* method. |
|
126 |
* |
|
127 |
* @param buffers a List of ByteBuffers. |
|
128 |
* @param complete if true then no more data will be added to the list |
|
129 |
*/ |
|
130 |
protected abstract void incoming(List<ByteBuffer> buffers, boolean complete); |
|
131 |
||
132 |
/** |
|
133 |
* This method is called to determine the window size to use at any time. The |
|
134 |
* current window is supplied together with the current downstream queue size. |
|
135 |
* {@code 0} should be returned if no change is |
|
136 |
* required or a positive integer which will be added to the current window. |
|
137 |
* The default implementation maintains a downstream queue size of no greater |
|
138 |
* than 5. The method can be overridden if required. |
|
139 |
* |
|
140 |
* @param currentWindow the current upstream subscription window |
|
141 |
* @param downstreamQsize the current number of buffers waiting to be sent |
|
142 |
* downstream |
|
143 |
* |
|
144 |
* @return value to add to currentWindow |
|
145 |
*/ |
|
146 |
protected long upstreamWindowUpdate(long currentWindow, long downstreamQsize) { |
|
147 |
if (downstreamQsize > 5) { |
|
148 |
return 0; |
|
149 |
} |
|
150 |
||
151 |
if (currentWindow == 0) { |
|
152 |
return 1; |
|
153 |
} else { |
|
154 |
return 0; |
|
155 |
} |
|
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* Override this if anything needs to be done after the upstream subscriber |
|
160 |
* has subscribed |
|
161 |
*/ |
|
162 |
protected void onSubscribe() { |
|
163 |
} |
|
164 |
||
165 |
/** |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
166 |
* Override this if anything needs to be done before checking for error |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
167 |
* and processing the input queue. |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
168 |
* @return |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
169 |
*/ |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
170 |
protected SchedulingAction enterScheduling() { |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
171 |
return SchedulingAction.CONTINUE; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
172 |
} |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
173 |
|
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
174 |
protected boolean signalScheduling() { |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
175 |
if (downstreamCompleted || pushScheduler.isStopped()) { |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
176 |
return false; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
177 |
} |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
178 |
pushScheduler.runOrSchedule(); |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
179 |
return true; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
180 |
} |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
181 |
|
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
182 |
/** |
55763 | 183 |
* Delivers buffers of data downstream. After incoming() |
184 |
* has been called complete == true signifying completion of the upstream |
|
185 |
* subscription, data may continue to be delivered, up to when outgoing() is |
|
186 |
* called complete == true, after which, the downstream subscription is |
|
187 |
* completed. |
|
188 |
* |
|
189 |
* It's an error to call outgoing() with complete = true if incoming() has |
|
190 |
* not previously been called with it. |
|
191 |
*/ |
|
192 |
public void outgoing(ByteBuffer buffer, boolean complete) { |
|
193 |
Objects.requireNonNull(buffer); |
|
194 |
assert !complete || !buffer.hasRemaining(); |
|
195 |
outgoing(List.of(buffer), complete); |
|
196 |
} |
|
197 |
||
198 |
public void outgoing(List<ByteBuffer> buffers, boolean complete) { |
|
199 |
Objects.requireNonNull(buffers); |
|
200 |
if (complete) { |
|
201 |
assert Utils.remaining(buffers) == 0; |
|
202 |
logger.log(Level.DEBUG, "completionAcknowledged"); |
|
203 |
if (!upstreamCompleted) |
|
204 |
throw new IllegalStateException("upstream not completed"); |
|
205 |
completionAcknowledged = true; |
|
206 |
} else { |
|
207 |
logger.log(Level.DEBUG, () -> "Adding " |
|
208 |
+ Utils.remaining(buffers) |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
209 |
+ " to outputQ queue"); |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
210 |
outputQ.add(buffers); |
55763 | 211 |
} |
212 |
logger.log(Level.DEBUG, () -> "pushScheduler " |
|
213 |
+ (pushScheduler.isStopped() ? " is stopped!" : " is alive")); |
|
214 |
pushScheduler.runOrSchedule(); |
|
215 |
} |
|
216 |
||
217 |
/** |
|
218 |
* Returns a CompletableFuture which completes when this wrapper completes. |
|
219 |
* Normal completion happens with the following steps (in order): |
|
220 |
* 1. onComplete() is called |
|
221 |
* 2. incoming() called with complete = true |
|
222 |
* 3. outgoing() may continue to be called normally |
|
223 |
* 4. outgoing called with complete = true |
|
224 |
* 5. downstream subscriber is called onComplete() |
|
225 |
* |
|
226 |
* If the subscription is canceled or onComplete() is invoked the |
|
227 |
* CompletableFuture completes exceptionally. Exceptional completion |
|
228 |
* also occurs if downstreamCF completes exceptionally. |
|
229 |
*/ |
|
230 |
public CompletableFuture<Void> completion() { |
|
231 |
return cf; |
|
232 |
} |
|
233 |
||
234 |
/** |
|
235 |
* Invoked whenever it 'may' be possible to push buffers downstream. |
|
236 |
*/ |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
237 |
class DownstreamPusher implements Runnable { |
55763 | 238 |
@Override |
239 |
public void run() { |
|
240 |
try { |
|
241 |
run1(); |
|
242 |
} catch (Throwable t) { |
|
243 |
errorCommon(t); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
private void run1() { |
|
248 |
if (downstreamCompleted) { |
|
249 |
logger.log(Level.DEBUG, "DownstreamPusher: downstream is already completed"); |
|
250 |
return; |
|
251 |
} |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
252 |
switch (enterScheduling()) { |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
253 |
case CONTINUE: break; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
254 |
case RESCHEDULE: pushScheduler.runOrSchedule(); return; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
255 |
case RETURN: return; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
256 |
default: |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
257 |
errorRef.compareAndSet(null, |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
258 |
new InternalError("unknown scheduling command")); |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
259 |
break; |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
260 |
} |
55763 | 261 |
// If there was an error, send it downstream. |
262 |
Throwable error = errorRef.get(); |
|
263 |
if (error != null) { |
|
264 |
synchronized(this) { |
|
265 |
if (downstreamCompleted) return; |
|
266 |
downstreamCompleted = true; |
|
267 |
} |
|
268 |
logger.log(Level.DEBUG, |
|
269 |
() -> "DownstreamPusher: forwarding error downstream: " + error); |
|
270 |
pushScheduler.stop(); |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
271 |
outputQ.clear(); |
55763 | 272 |
downstreamSubscriber.onError(error); |
273 |
return; |
|
274 |
} |
|
275 |
||
276 |
// OK - no error, let's proceed |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
277 |
if (!outputQ.isEmpty()) { |
55763 | 278 |
logger.log(Level.DEBUG, |
279 |
"DownstreamPusher: queue not empty, downstreamSubscription: %s", |
|
280 |
downstreamSubscription); |
|
281 |
} else { |
|
282 |
logger.log(Level.DEBUG, |
|
283 |
"DownstreamPusher: queue empty, downstreamSubscription: %s", |
|
284 |
downstreamSubscription); |
|
285 |
} |
|
286 |
||
287 |
final boolean dbgOn = logger.isLoggable(Level.DEBUG); |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
288 |
while (!outputQ.isEmpty() && downstreamSubscription.tryDecrement()) { |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
289 |
List<ByteBuffer> b = outputQ.poll(); |
55763 | 290 |
if (dbgOn) logger.log(Level.DEBUG, |
291 |
"DownstreamPusher: Pushing " |
|
292 |
+ Utils.remaining(b) |
|
293 |
+ " bytes downstream"); |
|
294 |
downstreamSubscriber.onNext(b); |
|
295 |
} |
|
296 |
upstreamWindowUpdate(); |
|
297 |
checkCompletion(); |
|
298 |
} |
|
299 |
} |
|
300 |
||
301 |
AtomicLong upstreamWindow = new AtomicLong(0); |
|
302 |
||
303 |
void upstreamWindowUpdate() { |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
304 |
long downstreamQueueSize = outputQ.size(); |
55763 | 305 |
long n = upstreamWindowUpdate(upstreamWindow.get(), downstreamQueueSize); |
306 |
if (n > 0) |
|
307 |
upstreamRequest(n); |
|
308 |
} |
|
309 |
||
310 |
@Override |
|
311 |
public void onSubscribe(Flow.Subscription subscription) { |
|
312 |
if (upstreamSubscription != null) { |
|
313 |
throw new IllegalStateException("Single shot publisher"); |
|
314 |
} |
|
315 |
this.upstreamSubscription = subscription; |
|
316 |
upstreamRequest(upstreamWindowUpdate(0, 0)); |
|
317 |
logger.log(Level.DEBUG, |
|
318 |
"calling downstreamSubscriber::onSubscribe on %s", |
|
319 |
downstreamSubscriber); |
|
320 |
downstreamSubscriber.onSubscribe(downstreamSubscription); |
|
321 |
onSubscribe(); |
|
322 |
} |
|
323 |
||
324 |
@Override |
|
325 |
public void onNext(List<ByteBuffer> item) { |
|
326 |
logger.log(Level.DEBUG, "onNext"); |
|
327 |
long prev = upstreamWindow.getAndDecrement(); |
|
328 |
if (prev <= 0) |
|
329 |
throw new IllegalStateException("invalid onNext call"); |
|
330 |
incomingCaller(item, false); |
|
331 |
upstreamWindowUpdate(); |
|
332 |
} |
|
333 |
||
334 |
private void upstreamRequest(long n) { |
|
335 |
logger.log(Level.DEBUG, "requesting %d", n); |
|
336 |
upstreamWindow.getAndAdd(n); |
|
337 |
upstreamSubscription.request(n); |
|
338 |
} |
|
339 |
||
340 |
public long upstreamWindow() { |
|
341 |
return upstreamWindow.get(); |
|
342 |
} |
|
343 |
||
344 |
@Override |
|
345 |
public void onError(Throwable throwable) { |
|
346 |
logger.log(Level.DEBUG, () -> "onError: " + throwable); |
|
347 |
errorCommon(Objects.requireNonNull(throwable)); |
|
348 |
} |
|
349 |
||
350 |
protected boolean errorCommon(Throwable throwable) { |
|
351 |
assert throwable != null; |
|
352 |
if (errorRef.compareAndSet(null, throwable)) { |
|
353 |
logger.log(Level.DEBUG, "error", throwable); |
|
354 |
pushScheduler.runOrSchedule(); |
|
355 |
upstreamCompleted = true; |
|
356 |
cf.completeExceptionally(throwable); |
|
357 |
return true; |
|
358 |
} |
|
359 |
return false; |
|
360 |
} |
|
361 |
||
362 |
@Override |
|
363 |
public void close() { |
|
364 |
errorCommon(new RuntimeException("wrapper closed")); |
|
365 |
} |
|
366 |
||
367 |
private void incomingCaller(List<ByteBuffer> l, boolean complete) { |
|
368 |
try { |
|
369 |
incoming(l, complete); |
|
370 |
} catch(Throwable t) { |
|
371 |
errorCommon(t); |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
@Override |
|
376 |
public void onComplete() { |
|
377 |
logger.log(Level.DEBUG, () -> "upstream completed: " + toString()); |
|
378 |
upstreamCompleted = true; |
|
379 |
incomingCaller(Utils.EMPTY_BB_LIST, true); |
|
380 |
checkCompletion(); |
|
381 |
pushScheduler.runOrSchedule(); |
|
382 |
} |
|
383 |
||
384 |
/** Adds the given data to the input queue. */ |
|
385 |
public void addData(ByteBuffer l) { |
|
386 |
if (upstreamSubscription == null) { |
|
387 |
throw new IllegalStateException("can't add data before upstream subscriber subscribes"); |
|
388 |
} |
|
389 |
incomingCaller(List.of(l), false); |
|
390 |
} |
|
391 |
||
392 |
void checkCompletion() { |
|
393 |
if (downstreamCompleted || !upstreamCompleted) { |
|
394 |
return; |
|
395 |
} |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
396 |
if (!outputQ.isEmpty()) { |
55763 | 397 |
return; |
398 |
} |
|
399 |
if (errorRef.get() != null) { |
|
400 |
pushScheduler.runOrSchedule(); |
|
401 |
return; |
|
402 |
} |
|
403 |
if (completionAcknowledged) { |
|
404 |
downstreamSubscriber.onComplete(); |
|
405 |
// Fix me subscriber.onComplete.run(); |
|
406 |
downstreamCompleted = true; |
|
407 |
cf.complete(null); |
|
408 |
} |
|
409 |
} |
|
410 |
||
411 |
// called from the downstream Subscription.cancel() |
|
412 |
void downstreamCompletion() { |
|
413 |
upstreamSubscription.cancel(); |
|
414 |
cf.complete(null); |
|
415 |
} |
|
416 |
||
417 |
public void resetDownstreamDemand() { |
|
418 |
downstreamSubscription.demand.reset(); |
|
419 |
} |
|
420 |
||
421 |
@Override |
|
422 |
public String toString() { |
|
423 |
StringBuilder sb = new StringBuilder(); |
|
424 |
sb.append("SubscriberWrapper:") |
|
425 |
.append(" upstreamCompleted: ").append(Boolean.toString(upstreamCompleted)) |
|
426 |
.append(" upstreamWindow: ").append(upstreamWindow.toString()) |
|
427 |
.append(" downstreamCompleted: ").append(Boolean.toString(downstreamCompleted)) |
|
428 |
.append(" completionAcknowledged: ").append(Boolean.toString(completionAcknowledged)) |
|
55768
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
429 |
.append(" outputQ size: ").append(Integer.toString(outputQ.size())) |
8674257c75ce
http-client-branch: SSLTube should call onSubscribe in the flow
dfuchs
parents:
55763
diff
changeset
|
430 |
//.append(" outputQ: ").append(outputQ.toString()) |
55763 | 431 |
.append(" cf: ").append(cf.toString()) |
432 |
.append(" downstreamSubscription: ").append(downstreamSubscription.toString()); |
|
433 |
||
434 |
return sb.toString(); |
|
435 |
} |
|
436 |
||
437 |
public String dbgString() { |
|
438 |
return "SubscriberWrapper"; |
|
439 |
} |
|
440 |
} |