类 AbstractListenerWriteProcessor<T>
java.lang.Object
cn.taketoday.http.server.reactive.AbstractListenerWriteProcessor<T>
- 类型参数:
T- the type of element signaled to theSubscriber
- 所有已实现的接口:
org.reactivestreams.Processor<T,,Void> org.reactivestreams.Publisher<Void>,org.reactivestreams.Subscriber<T>
- 直接已知子类:
ServletServerHttpResponse.ResponseBodyProcessor,UndertowServerHttpResponse.ResponseBodyProcessor
public abstract class AbstractListenerWriteProcessor<T>
extends Object
implements org.reactivestreams.Processor<T,Void>
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 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.
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Violeta Georgieva, Rossen Stoyanchev
-
嵌套类概要
嵌套类修饰符和类型类说明private static enumRepresents a state for theProcessorto be in. -
字段概要
字段修饰符和类型字段说明private Tprivate final Stringprivate booleanIndicates we're waiting for one last isReady-onWritePossible cycle after "onComplete" because some Servlet containers expect this to take place prior to calling AsyncContext.complete().private final WriteResultPublisherprotected static final cn.taketoday.logging.LoggerSpecial logger for debugging Reactive Streams signals.private booleanprivate final AtomicReference<AbstractListenerWriteProcessor.State>private org.reactivestreams.Subscription -
构造器概要
构造器构造器说明AbstractListenerWriteProcessor(String logPrefix) Create an instance with the given log prefix. -
方法概要
修饰符和类型方法说明voidcancel()Cancel the upstream "write" Publisher only, for example due to Servlet container error/completion notifications.(专用程序包) voidCancel the "write" Publisher and transition to COMPLETED immediately also without notifying the downstream.private booleanchangeState(AbstractListenerWriteProcessor.State oldState, AbstractListenerWriteProcessor.State newState) private voidprivate voidprotected voiddataReceived(T data) Template method invoked after a data item to write is received viaSubscriber.onNext(Object).private voidprotected 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(org.reactivestreams.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 voidprotected abstract booleanWrite the given item.private voidprotected voidInvoked after onComplete or onError notification.protected voidInvoked when an I/O error occurs during a write.protected voidInvoked after the current data has been written and before requesting the next item from the upstream, write Publisher.
-
字段详细资料
-
rsWriteLogger
protected static final cn.taketoday.logging.Logger rsWriteLoggerSpecial logger for debugging Reactive Streams signals.- 另请参阅:
-
LogDelegateFactory.getHiddenLog(Class)AbstractListenerReadPublisher.rsReadLoggerAbstractListenerWriteFlushProcessor.rsWriteFlushLoggerWriteResultPublisher.rsWriteResultLogger
-
state
-
subscription
@Nullable private org.reactivestreams.Subscription subscription -
currentData
-
sourceCompleted
private volatile boolean sourceCompleted -
readyToCompleteAfterLastWrite
private volatile boolean readyToCompleteAfterLastWriteIndicates we're waiting for one last isReady-onWritePossible cycle after "onComplete" because some Servlet containers expect this to take place prior to calling AsyncContext.complete(). See https://github.com/eclipse-ee4j/servlet-api/issues/273 -
resultPublisher
-
logPrefix
-
-
构造器详细资料
-
AbstractListenerWriteProcessor
public AbstractListenerWriteProcessor() -
AbstractListenerWriteProcessor
Create an instance with the given log prefix.
-
-
方法详细资料
-
getLogPrefix
Get the configured log prefix. -
onSubscribe
public final void onSubscribe(org.reactivestreams.Subscription subscription) - 指定者:
onSubscribe在接口中org.reactivestreams.Subscriber<T>
-
onNext
- 指定者:
onNext在接口中org.reactivestreams.Subscriber<T>
-
onError
Error signal from the upstream, write Publisher. This is also used by sub-classes to delegate error notifications from the container.- 指定者:
onError在接口中org.reactivestreams.Subscriber<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.- 指定者:
onComplete在接口中org.reactivestreams.Subscriber<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. -
cancelAndSetCompleted
void cancelAndSetCompleted()Cancel the "write" Publisher and transition to COMPLETED immediately also without notifying the downstream. For use when cancellation came from downstream. -
subscribe
- 指定者:
subscribe在接口中org.reactivestreams.Publisher<T>
-
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.
- 参数:
data- the item to write- 返回:
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- 抛出:
IOException
-
writingPaused
protected void writingPaused()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.- 参数:
data- the data to be released- 从以下版本开始:
- 4.0
-
changeState
private boolean changeState(AbstractListenerWriteProcessor.State oldState, AbstractListenerWriteProcessor.State newState) -
changeStateToReceived
-
changeStateToComplete
-
writeIfPossible
private void writeIfPossible() -
discardCurrentData
private void discardCurrentData()
-