类 AbstractListenerReadPublisher<T>
java.lang.Object
cn.taketoday.http.server.reactive.AbstractListenerReadPublisher<T>
- 类型参数:
T- the type of element signaled
- 所有已实现的接口:
org.reactivestreams.Publisher<T>
- 直接已知子类:
ServletServerHttpRequest.RequestBodyPublisher,UndertowServerHttpRequest.RequestBodyPublisher
public abstract class AbstractListenerReadPublisher<T>
extends Object
implements org.reactivestreams.Publisher<T>
Abstract base class for
Publisher implementations that bridge between
event-listener read APIs and Reactive Streams.
Specifically a base class for reading from the HTTP request body with Servlet 3.1 non-blocking I/O and Undertow XNIO as well as handling incoming WebSocket messages with standard Java WebSocket (JSR-356), Jetty, and Undertow.
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Violeta Georgieva, Rossen Stoyanchev
-
嵌套类概要
嵌套类修饰符和类型类说明private final classSubscription that delegates signals to State.private static enumRepresents a state for thePublisherto be in. -
字段概要
字段修饰符和类型字段说明private booleanprivate longprivate static final AtomicLongFieldUpdater<AbstractListenerReadPublisher>(专用程序包) static final cn.taketoday.core.io.buffer.DataBufferprivate Throwableprivate final Stringprotected static cn.taketoday.logging.LoggerSpecial logger for debugging Reactive Streams signals.private final AtomicReference<AbstractListenerReadPublisher.State>private org.reactivestreams.Subscriber<? super T> -
构造器概要
构造器构造器说明AbstractListenerReadPublisher(String logPrefix) Create an instance with the given log prefix. -
方法概要
修饰符和类型方法说明private booleanchangeState(AbstractListenerReadPublisher.State oldState, AbstractListenerReadPublisher.State newState) private voidprotected abstract voidCheck if data is available and either callonDataAvailable()immediately or schedule a notification.private org.reactivestreams.Subscriptionprotected abstract voidInvoked after an I/O read error from the underlying server or after a cancellation signal from the downstream consumer to allow sub-classes to discard any current cached data they might have.Return the configured log message prefix.private booleanvoidSub-classes can call this method to delegate a contain notification when all data has been read.final voidInvoked when reading is possible, either in the same thread after a check viacheckOnDataAvailable(), or as a callback from the underlying container.final voidSub-classes can call this to delegate container error notifications.protected abstract Tread()Read once from the input, if possible.private booleanRead and publish data one at a time until there is no more data, no more demand, or perhaps we completed meanwhile.protected abstract voidInvoked when reading is paused due to a lack of demand.void
-
字段详细资料
-
rsReadLogger
protected static cn.taketoday.logging.Logger rsReadLoggerSpecial logger for debugging Reactive Streams signals.- 另请参阅:
-
LogDelegateFactory.getHiddenLog(Class)AbstractListenerWriteProcessor.rsWriteLoggerAbstractListenerWriteFlushProcessor.rsWriteFlushLoggerWriteResultPublisher.rsWriteResultLogger
-
EMPTY_BUFFER
static final cn.taketoday.core.io.buffer.DataBuffer EMPTY_BUFFER -
state
-
demand
private volatile long demand -
DEMAND_FIELD_UPDATER
-
subscriber
-
completionPending
private volatile boolean completionPending -
errorPending
-
logPrefix
-
-
构造器详细资料
-
AbstractListenerReadPublisher
public AbstractListenerReadPublisher() -
AbstractListenerReadPublisher
Create an instance with the given log prefix.
-
-
方法详细资料
-
getLogPrefix
Return the configured log message prefix. -
subscribe
- 指定者:
subscribe在接口中org.reactivestreams.Publisher<T>
-
onDataAvailable
public final void onDataAvailable()Invoked when reading is possible, either in the same thread after a check viacheckOnDataAvailable(), or as a callback from the underlying container. -
onAllDataRead
public void onAllDataRead()Sub-classes can call this method to delegate a contain notification when all data has been read. -
onError
Sub-classes can call this to delegate container error notifications. -
checkOnDataAvailable
protected abstract void checkOnDataAvailable()Check if data is available and either callonDataAvailable()immediately or schedule a notification. -
read
Read once from the input, if possible.- 返回:
- the item that was read; or
null - 抛出:
IOException
-
readingPaused
protected abstract void readingPaused()Invoked when reading is paused due to a lack of demand.Note: This method is guaranteed not to compete with
checkOnDataAvailable()so it can be used to safely suspend reading, if the underlying API supports it, i.e. without competing with an implicit call to resume viacheckOnDataAvailable(). -
discardData
protected abstract void discardData()Invoked after an I/O read error from the underlying server or after a cancellation signal from the downstream consumer to allow sub-classes to discard any current cached data they might have. -
readAndPublish
Read and publish data one at a time until there is no more data, no more demand, or perhaps we completed meanwhile.- 返回:
trueif there is more demand;falseif there is no more demand or we have completed.- 抛出:
IOException
-
changeState
private boolean changeState(AbstractListenerReadPublisher.State oldState, AbstractListenerReadPublisher.State newState) -
changeToDemandState
-
handlePendingCompletionOrError
private boolean handlePendingCompletionOrError() -
createSubscription
private org.reactivestreams.Subscription createSubscription()
-