Skip to content

Commit 682f471

Browse files
committed
Polishing
See gh-30393
1 parent c4a34fa commit 682f471

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

Diff for: spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
7272
@Nullable
7373
private volatile Subscriber<? super T> subscriber;
7474

75+
/** Flag to defer transition to COMPLETED briefly while SUBSCRIBING or READING. */
7576
private volatile boolean completionPending;
7677

78+
/** Flag to defer transition to COMPLETED briefly while SUBSCRIBING or READING. */
7779
@Nullable
7880
private volatile Throwable errorPending;
7981

@@ -123,8 +125,8 @@ public final void onDataAvailable() {
123125
}
124126

125127
/**
126-
* Subclasses can call this method to delegate a container notification when
127-
* all data has been read.
128+
* Subclasses can call this method to signal onComplete, delegating a
129+
* notification from the container when all data has been read.
128130
*/
129131
public void onAllDataRead() {
130132
State state = this.state.get();
@@ -135,7 +137,8 @@ public void onAllDataRead() {
135137
}
136138

137139
/**
138-
* Subclasses can call this to delegate container error notifications.
140+
* Subclasses can call this to signal onError, delegating a
141+
* notification from the container for an error.
139142
*/
140143
public final void onError(Throwable ex) {
141144
State state = this.state.get();
@@ -183,10 +186,10 @@ public final void onError(Throwable ex) {
183186
// Private methods for use in State...
184187

185188
/**
186-
* Read and publish data one at a time until there is no more data, no more
187-
* demand, or perhaps we completed meanwhile.
188-
* @return {@code true} if there is more demand; {@code false} if there is
189-
* no more demand or we have completed.
189+
* Read and publish data one by one until there are no more items
190+
* to read (i.e. input queue drained), or there is no more demand.
191+
* @return {@code true} if there is demand but no more to read, or
192+
* {@code false} if there is more to read but lack of demand.
190193
*/
191194
private boolean readAndPublish() throws IOException {
192195
long r;
@@ -269,15 +272,15 @@ private final class ReadSubscription implements Subscription {
269272

270273

271274
@Override
272-
public final void request(long n) {
275+
public void request(long n) {
273276
if (rsReadLogger.isTraceEnabled()) {
274277
rsReadLogger.trace(getLogPrefix() + "request " + (n != Long.MAX_VALUE ? n : "Long.MAX_VALUE"));
275278
}
276279
state.get().request(AbstractListenerReadPublisher.this, n);
277280
}
278281

279282
@Override
280-
public final void cancel() {
283+
public void cancel() {
281284
State state = AbstractListenerReadPublisher.this.state.get();
282285
if (rsReadLogger.isTraceEnabled()) {
283286
rsReadLogger.trace(getLogPrefix() + "cancel [" + state + "]");
@@ -288,7 +291,7 @@ public final void cancel() {
288291

289292

290293
/**
291-
* Represents a state for the {@link Publisher} to be in.
294+
* The states that a read {@link Publisher} transitions through.
292295
* <p><pre>
293296
* UNSUBSCRIBED
294297
* |

Diff for: spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ protected WebSocketSendProcessor getSendProcessor() {
112112

113113
@Override
114114
public Flux<WebSocketMessage> receive() {
115-
return (canSuspendReceiving() ? Flux.from(this.receivePublisher) :
115+
return (canSuspendReceiving() ?
116+
Flux.from(this.receivePublisher) :
116117
Flux.from(this.receivePublisher).onBackpressureBuffer(RECEIVE_BUFFER_SIZE));
117118
}
118119

@@ -240,6 +241,9 @@ public void onComplete() {
240241
}
241242

242243

244+
/**
245+
* Read publisher for inbound WebSocket messages.
246+
*/
243247
private final class WebSocketReceivePublisher extends AbstractListenerReadPublisher<WebSocketMessage> {
244248

245249
private volatile Queue<Object> pendingMessages = Queues.unbounded(Queues.SMALL_BUFFER_SIZE).get();
@@ -269,7 +273,7 @@ protected void readingPaused() {
269273

270274
@Override
271275
@Nullable
272-
protected WebSocketMessage read() throws IOException {
276+
protected WebSocketMessage read() {
273277
return (WebSocketMessage) this.pendingMessages.poll();
274278
}
275279

@@ -304,7 +308,7 @@ protected void discardData() {
304308

305309

306310
/**
307-
* Processor to send web socket messages.
311+
* Write processor for outbound WebSocket messages.
308312
*/
309313
protected final class WebSocketSendProcessor extends AbstractListenerWriteProcessor<WebSocketMessage> {
310314

0 commit comments

Comments
 (0)