T - the type of element signaled to the Subscriberpublic abstract class AbstractListenerWriteProcessor<T> extends Object implements org.reactivestreams.Processor<T,Void>
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 3.1 non-blocking I/O and Undertow XNIO as well for writing WebSocket messages through the Java WebSocket API (JSR-356), Jetty, and Undertow.
| Modifier and Type | Field and Description |
|---|---|
protected static Log |
rsWriteLogger
Special logger for debugging Reactive Streams signals.
|
| Constructor and Description |
|---|
AbstractListenerWriteProcessor() |
AbstractListenerWriteProcessor(String logPrefix)
Create an instance with the given log prefix.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Invoked during an error or completion callback from the underlying
container to cancel the upstream subscription.
|
protected void |
dataReceived(T data)
Template method invoked after a data item to write is received via
Subscriber.onNext(Object). |
protected abstract void |
discardData(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.
|
String |
getLogPrefix()
Get the configured log prefix.
|
protected abstract boolean |
isDataEmpty(T data)
Whether the given data item has any content to write.
|
protected abstract boolean |
isWritePossible()
Whether writing is possible.
|
void |
onComplete()
Completion signal from the upstream, write Publisher.
|
void |
onError(Throwable ex)
Error signal from the upstream, write Publisher.
|
void |
onNext(T data) |
void |
onSubscribe(org.reactivestreams.Subscription subscription) |
void |
onWritePossible()
Invoked when writing is possible, either in the same thread after a check
via
isWritePossible(), or as a callback from the underlying
container. |
void |
subscribe(org.reactivestreams.Subscriber<? super Void> subscriber) |
protected abstract boolean |
write(T data)
Write the given item.
|
protected void |
writingComplete()
Invoked after onComplete or onError notification.
|
protected void |
writingFailed(Throwable ex)
Invoked when an I/O error occurs during a write.
|
protected void |
writingPaused()
Deprecated.
originally introduced for Undertow to stop write notifications
when no data is available, but deprecated as of as of 5.0.6 since constant
switching on every requested item causes a significant slowdown.
|
protected static final Log rsWriteLogger
LogDelegateFactory.getHiddenLog(Class),
AbstractListenerReadPublisher.rsReadLogger,
AbstractListenerWriteFlushProcessor.rsWriteFlushLogger,
WriteResultPublisher.rsWriteResultLoggerpublic AbstractListenerWriteProcessor()
public AbstractListenerWriteProcessor(String logPrefix)
public String getLogPrefix()
public final void onSubscribe(org.reactivestreams.Subscription subscription)
onSubscribe in interface org.reactivestreams.Subscriber<T>public final void onNext(T data)
onNext in interface org.reactivestreams.Subscriber<T>public final void onError(Throwable ex)
onError in interface org.reactivestreams.Subscriber<T>public final void onComplete()
onComplete in interface org.reactivestreams.Subscriber<T>public final void onWritePossible()
isWritePossible(), or as a callback from the underlying
container.public void cancel()
public final void subscribe(org.reactivestreams.Subscriber<? super Void> subscriber)
subscribe in interface org.reactivestreams.Publisher<Void>protected abstract boolean isDataEmpty(T data)
protected void dataReceived(T data)
Subscriber.onNext(Object). The default implementation saves the
data item for writing once that is possible.protected abstract boolean isWritePossible()
protected abstract boolean write(T data) throws IOException
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.
data - the item to writetrue if the current data item was written completely and
a new item requested, or false if it was written partially and
we'll need more write callbacks before it is fully writtenIOException@Deprecated protected void writingPaused()
The default implementation is a no-op.
protected void writingComplete()
The default implementation is a no-op.
protected void writingFailed(Throwable ex)
Defaults to no-op.
protected abstract void discardData(T data)
data - the data to be released