Class AbstractListenerWriteProcessor<T>
java.lang.Object
org.springframework.http.server.reactive.AbstractListenerWriteProcessor<T>
- Type Parameters:
T- the type of element signaled to theSubscriber
- All Implemented Interfaces:
Processor<T,,Void> Publisher<Void>,Subscriber<T>
- Direct Known Subclasses:
AbstractListenerWebSocketSession.WebSocketSendProcessor
Abstract base class for
Processor implementations that bridge between
event-listener write APIs and Reactive Streams.
Specifically a base class for writing to the HTTP response body with Servlet non-blocking I/O and Undertow XNIO as well for writing WebSocket messages through the Java WebSocket API (JSR-356), Jetty, and Undertow.
- Since:
- 5.0
- Author:
- Arjen Poutsma, Violeta Georgieva, Rossen Stoyanchev
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final LogSpecial logger for debugging Reactive Streams signals. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractListenerWriteProcessor(String logPrefix) Create an instance with the given log prefix. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancel the upstream "write" Publisher only, for example due to Servlet container error/completion notifications.protected voiddataReceived(T data) Template method invoked after a data item to write is received viaSubscriber.onNext(Object).protected abstract voiddiscardData(T data) Invoked after any error (either from the upstream write Publisher, or from I/O operations to the underlying server) and cancellation to discard in-flight data that was in the process of being written when the error took place.Get the configured log prefix.protected abstract booleanisDataEmpty(T data) Whether the given data item has any content to write.protected abstract booleanWhether writing is possible.final voidCompletion signal from the upstream, write Publisher.final voidError signal from the upstream, write Publisher.final voidfinal voidonSubscribe(Subscription subscription) final voidInvoked when writing is possible, either in the same thread after a check viaisWritePossible(), or as a callback from the underlying container.final voidsubscribe(Subscriber<? super Void> subscriber) protected abstract booleanWrite the given item.protected voidInvoked after onComplete or onError notification.protected voidInvoked when an I/O error occurs during a write.protected voidDeprecated.originally introduced for Undertow to stop write notifications when no data is available, but deprecated as of 5.0.6 since constant switching on every requested item causes a significant slowdown.
-
Field Details
-
rsWriteLogger
Special logger for debugging Reactive Streams signals.- See Also:
-
LogDelegateFactory.getHiddenLog(Class)AbstractListenerReadPublisher.rsReadLoggerAbstractListenerWriteFlushProcessor.rsWriteFlushLoggerWriteResultPublisher.rsWriteResultLogger
-
-
Constructor Details
-
AbstractListenerWriteProcessor
public AbstractListenerWriteProcessor() -
AbstractListenerWriteProcessor
Create an instance with the given log prefix.- Since:
- 5.1
-
-
Method Details
-
getLogPrefix
Get the configured log prefix.- Since:
- 5.1
-
onSubscribe
- Specified by:
onSubscribein interfaceSubscriber<T>
-
onNext
- Specified by:
onNextin interfaceSubscriber<T>
-
onError
Error signal from the upstream, write Publisher. This is also used by sub-classes to delegate error notifications from the container.- Specified by:
onErrorin interfaceSubscriber<T>
-
onComplete
public final void onComplete()Completion signal from the upstream, write Publisher. This is also used by sub-classes to delegate completion notifications from the container.- Specified by:
onCompletein interfaceSubscriber<T>
-
onWritePossible
public final void onWritePossible()Invoked when writing is possible, either in the same thread after a check viaisWritePossible(), or as a callback from the underlying container. -
cancel
public void cancel()Cancel the upstream "write" Publisher only, for example due to Servlet container error/completion notifications. This should usually be followed up with a call to eitheronError(Throwable)oronComplete()to notify the downstream chain, that is unless cancellation came from downstream. -
subscribe
-
isDataEmpty
Whether the given data item has any content to write. If false the item is not written. -
dataReceived
Template method invoked after a data item to write is received viaSubscriber.onNext(Object). The default implementation saves the data item for writing once that is possible. -
isWritePossible
protected abstract boolean isWritePossible()Whether writing is possible. -
write
Write the given item.Note: Sub-classes are responsible for releasing any data buffer associated with the item, once fully written, if pooled buffers apply to the underlying container.
- Parameters:
data- the item to write- Returns:
trueif the current data item was written completely and a new item requested, orfalseif it was written partially and we'll need more write callbacks before it is fully written- Throws:
IOException
-
writingPaused
Deprecated.originally introduced for Undertow to stop write notifications when no data is available, but deprecated as of 5.0.6 since constant switching on every requested item causes a significant slowdown.Invoked after the current data has been written and before requesting the next item from the upstream, write Publisher.The default implementation is a no-op.
-
writingComplete
protected void writingComplete()Invoked after onComplete or onError notification.The default implementation is a no-op.
-
writingFailed
Invoked when an I/O error occurs during a write. Sub-classes may choose to ignore this if they know the underlying API will provide an error notification in a container thread.Defaults to no-op.
-
discardData
Invoked after any error (either from the upstream write Publisher, or from I/O operations to the underlying server) and cancellation to discard in-flight data that was in the process of being written when the error took place.- Parameters:
data- the data to be released- Since:
- 5.0.11
-