@@ -53,7 +53,7 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
53
53
private final WriteResultPublisher resultPublisher = new WriteResultPublisher ();
54
54
55
55
56
- // Subscriber methods and methods to notify of async I/O events ...
56
+ // Subscriber methods and async I/O notification methods ...
57
57
58
58
@ Override
59
59
public final void onSubscribe (Subscription subscription ) {
@@ -67,8 +67,8 @@ public final void onNext(Publisher<? extends T> publisher) {
67
67
}
68
68
69
69
/**
70
- * Notify of an error. This can come from the upstream write Publisher or
71
- * from sub-classes as a result of an I/O error .
70
+ * Error signal from the upstream, write Publisher. This is also used by
71
+ * sub-classes to delegate error notifications from the container .
72
72
*/
73
73
@ Override
74
74
public final void onError (Throwable ex ) {
@@ -79,68 +79,76 @@ public final void onError(Throwable ex) {
79
79
}
80
80
81
81
/**
82
- * Notify of completion. This can come from the upstream write Publisher or
83
- * from sub-classes as a result of an I/O completion event .
82
+ * Completion signal from the upstream, write Publisher. This is also used
83
+ * by sub-classes to delegate completion notifications from the container .
84
84
*/
85
85
@ Override
86
86
public final void onComplete () {
87
87
logger .trace ("Received onComplete" );
88
88
this .state .get ().onComplete (this );
89
89
}
90
90
91
+ /**
92
+ * Invoked when flusing is possible, either in the same thread after a check
93
+ * via {@link #isWritePossible()}, or as a callback from the underlying
94
+ * container.
95
+ */
96
+ protected final void onFlushPossible () {
97
+ this .state .get ().onFlushPossible (this );
98
+ }
99
+
100
+ /**
101
+ * Invoked during an error or completion callback from the underlying
102
+ * container to cancel the upstream subscription.
103
+ */
91
104
protected void cancel () {
92
105
this .logger .trace ("Received request to cancel" );
93
106
if (this .subscription != null ) {
94
107
this .subscription .cancel ();
95
108
}
96
109
}
97
110
98
- // Publisher method...
111
+
112
+ // Publisher implementation for result notifications...
99
113
100
114
@ Override
101
115
public final void subscribe (Subscriber <? super Void > subscriber ) {
102
116
this .resultPublisher .subscribe (subscriber );
103
117
}
104
118
105
119
106
- // Methods for sub-classes to implement or override...
120
+ // Write API methods to be implemented or template methods to override...
107
121
108
122
/**
109
- * Create a new processor for subscribing to the next flush boundary.
123
+ * Create a new processor for the current flush boundary.
110
124
*/
111
125
protected abstract Processor <? super T , Void > createWriteProcessor ();
112
126
113
127
/**
114
- * Flush the output if ready, or otherwise {@link #isFlushPending()} should
115
- * return true after that.
128
+ * Whether writing/flushing is possible.
116
129
*/
117
- protected abstract void flush () throws IOException ;
130
+ protected abstract boolean isWritePossible () ;
118
131
119
132
/**
120
- * Invoked when an error happens while flushing. Defaults to no-op.
121
- * Servlet 3.1 based implementations will receive an
122
- * {@link javax.servlet.AsyncListener#onError} event.
133
+ * Flush the output if ready, or otherwise {@link #isFlushPending()} should
134
+ * return true after.
123
135
*/
124
- protected void flushingFailed (Throwable t ) {
125
- }
136
+ protected abstract void flush () throws IOException ;
126
137
127
138
/**
128
139
* Whether flushing is pending.
129
140
*/
130
141
protected abstract boolean isFlushPending ();
131
142
132
143
/**
133
- * Listeners can call this to notify when flushing is possible.
144
+ * Invoked when an error happens while flushing. Sub-classes may choose
145
+ * to ignore this if they know the underlying API will provide an error
146
+ * notification in a container thread.
147
+ * <p>Defaults to no-op.
134
148
*/
135
- protected final void onFlushPossible () {
136
- this .state .get ().onFlushPossible (this );
149
+ protected void flushingFailed (Throwable t ) {
137
150
}
138
151
139
- /**
140
- * Whether writing is possible.
141
- */
142
- protected abstract boolean isWritePossible ();
143
-
144
152
145
153
// Private methods for use in State...
146
154
@@ -167,16 +175,16 @@ private void flushIfPossible() {
167
175
* Represents a state for the {@link Processor} to be in.
168
176
*
169
177
* <p><pre>
170
- * UNSUBSCRIBED
171
- * |
172
- * v
173
- * +--- REQUESTED <-------- > RECEIVED ---+
174
- * | | |
175
- * | | |
176
- * | FLUSHING <------+ |
177
- * | | |
178
- * | v |
179
- * +---------- > COMPLETED <--------- -----+
178
+ * UNSUBSCRIBED
179
+ * |
180
+ * v
181
+ * REQUESTED <---> RECEIVED --- ---+
182
+ * | | |
183
+ * | v |
184
+ * | FLUSHING |
185
+ * | | |
186
+ * | v |
187
+ * +--------> COMPLETED <-----+
180
188
* </pre>
181
189
*/
182
190
private enum State {
@@ -269,7 +277,7 @@ public <T> void onFlushPossible(AbstractListenerWriteFlushProcessor<T> processor
269
277
processor .state .get ().onComplete (processor );
270
278
}
271
279
}
272
- public <T > void onNext (AbstractListenerWriteFlushProcessor <T > processor , Publisher <? extends T > publisher ) {
280
+ public <T > void onNext (AbstractListenerWriteFlushProcessor <T > proc , Publisher <? extends T > pub ) {
273
281
// ignore
274
282
}
275
283
@ Override
@@ -280,7 +288,7 @@ public <T> void onComplete(AbstractListenerWriteFlushProcessor<T> processor) {
280
288
281
289
COMPLETED {
282
290
@ Override
283
- public <T > void onNext (AbstractListenerWriteFlushProcessor <T > processor , Publisher <? extends T > publisher ) {
291
+ public <T > void onNext (AbstractListenerWriteFlushProcessor <T > proc , Publisher <? extends T > pub ) {
284
292
// ignore
285
293
}
286
294
@ Override
@@ -294,11 +302,11 @@ public <T> void onComplete(AbstractListenerWriteFlushProcessor<T> processor) {
294
302
};
295
303
296
304
297
- public <T > void onSubscribe (AbstractListenerWriteFlushProcessor <T > processor , Subscription subscription ) {
305
+ public <T > void onSubscribe (AbstractListenerWriteFlushProcessor <T > proc , Subscription subscription ) {
298
306
subscription .cancel ();
299
307
}
300
308
301
- public <T > void onNext (AbstractListenerWriteFlushProcessor <T > processor , Publisher <? extends T > publisher ) {
309
+ public <T > void onNext (AbstractListenerWriteFlushProcessor <T > proc , Publisher <? extends T > pub ) {
302
310
throw new IllegalStateException (toString ());
303
311
}
304
312
@@ -326,7 +334,7 @@ public <T> void onFlushPossible(AbstractListenerWriteFlushProcessor<T> processor
326
334
327
335
/**
328
336
* Subscriber to receive and delegate completion notifications for from
329
- * the current Publisher, i.e. within the current flush boundary.
337
+ * the current Publisher, i.e. for the current flush boundary.
330
338
*/
331
339
private static class WriteResultSubscriber implements Subscriber <Void > {
332
340
0 commit comments