@ -32,15 +32,17 @@ import reactor.core.publisher.Operators;
/ * *
/ * *
* Abstract base class for { @code Publisher } implementations that bridge between
* Abstract base class for { @code Publisher } implementations that bridge between
* event - listener APIs and Reactive Streams . Specifically , base class for the
* event - listener read APIs and Reactive Streams . Specifically , a base class for
* Servlet 3 . 1 and Undertow support .
* reading from the HTTP request body with Servlet 3 . 1 and Undertow as well as
* handling incoming WebSocket messages with JSR - 356 , Jetty , and Undertow .
*
*
* @author Arjen Poutsma
* @author Arjen Poutsma
* @author Violeta Georgieva
* @since 5 . 0
* @since 5 . 0
* @see ServletServerHttpRequest
* @see ServletServerHttpRequest
* @see UndertowHttpHandlerAdapter
* @see UndertowHttpHandlerAdapter
* /
* /
public abstract class AbstractRequestBody Publisher < T > implements Publisher < T > {
public abstract class AbstractListenerRead Publisher < T > implements Publisher < T > {
protected final Log logger = LogFactory . getLog ( getClass ( ) ) ;
protected final Log logger = LogFactory . getLog ( getClass ( ) ) ;
@ -155,11 +157,11 @@ public abstract class AbstractRequestBodyPublisher<T> implements Publisher<T> {
}
}
private static final class RequestBody Subscription implements Subscription {
private static final class Read Subscription implements Subscription {
private final AbstractRequestBody Publisher < ? > publisher ;
private final AbstractListenerRead Publisher < ? > publisher ;
public RequestBodySubscription ( AbstractRequestBody Publisher < ? > publisher ) {
public ReadSubscription ( AbstractListenerRead Publisher < ? > publisher ) {
this . publisher = publisher ;
this . publisher = publisher ;
}
}
@ -207,15 +209,15 @@ public abstract class AbstractRequestBodyPublisher<T> implements Publisher<T> {
/ * *
/ * *
* The initial unsubscribed state . Will respond to { @link
* The initial unsubscribed state . Will respond to { @link
* # subscribe ( AbstractRequestBody Publisher , Subscriber ) } by
* # subscribe ( AbstractListenerRead Publisher , Subscriber ) } by
* changing state to { @link # NO_DEMAND } .
* changing state to { @link # NO_DEMAND } .
* /
* /
UNSUBSCRIBED {
UNSUBSCRIBED {
@Override
@Override
< T > void subscribe ( AbstractRequestBody Publisher < T > publisher , Subscriber < ? super T > subscriber ) {
< T > void subscribe ( AbstractListenerRead Publisher < T > publisher , Subscriber < ? super T > subscriber ) {
Objects . requireNonNull ( subscriber ) ;
Objects . requireNonNull ( subscriber ) ;
if ( publisher . changeState ( this , NO_DEMAND ) ) {
if ( publisher . changeState ( this , NO_DEMAND ) ) {
Subscription subscription = new RequestBody Subscription ( publisher ) ;
Subscription subscription = new Read Subscription ( publisher ) ;
publisher . subscriber = subscriber ;
publisher . subscriber = subscriber ;
subscriber . onSubscribe ( subscription ) ;
subscriber . onSubscribe ( subscription ) ;
}
}
@ -227,13 +229,13 @@ public abstract class AbstractRequestBodyPublisher<T> implements Publisher<T> {
/ * *
/ * *
* State that gets entered when there is no demand . Responds to { @link
* State that gets entered when there is no demand . Responds to { @link
* # request ( AbstractRequestBody Publisher , long ) } by increasing the demand ,
* # request ( AbstractListenerRead Publisher , long ) } by increasing the demand ,
* changing state to { @link # DEMAND } and will check whether there
* changing state to { @link # DEMAND } and will check whether there
* is data available for reading .
* is data available for reading .
* /
* /
NO_DEMAND {
NO_DEMAND {
@Override
@Override
< T > void request ( AbstractRequestBody Publisher < T > publisher , long n ) {
< T > void request ( AbstractListenerRead Publisher < T > publisher , long n ) {
if ( Operators . checkRequest ( n , publisher . subscriber ) ) {
if ( Operators . checkRequest ( n , publisher . subscriber ) ) {
Operators . addAndGet ( publisher . demand , n ) ;
Operators . addAndGet ( publisher . demand , n ) ;
if ( publisher . changeState ( this , DEMAND ) ) {
if ( publisher . changeState ( this , DEMAND ) ) {
@ -245,20 +247,20 @@ public abstract class AbstractRequestBodyPublisher<T> implements Publisher<T> {
/ * *
/ * *
* State that gets entered when there is demand . Responds to
* State that gets entered when there is demand . Responds to
* { @link # onDataAvailable ( AbstractRequestBody Publisher ) } by
* { @link # onDataAvailable ( AbstractListenerRead Publisher ) } by
* reading the available data . The state will be changed to
* reading the available data . The state will be changed to
* { @link # NO_DEMAND } if there is no demand .
* { @link # NO_DEMAND } if there is no demand .
* /
* /
DEMAND {
DEMAND {
@Override
@Override
< T > void request ( AbstractRequestBody Publisher < T > publisher , long n ) {
< T > void request ( AbstractListenerRead Publisher < T > publisher , long n ) {
if ( Operators . checkRequest ( n , publisher . subscriber ) ) {
if ( Operators . checkRequest ( n , publisher . subscriber ) ) {
Operators . addAndGet ( publisher . demand , n ) ;
Operators . addAndGet ( publisher . demand , n ) ;
}
}
}
}
@Override
@Override
< T > void onDataAvailable ( AbstractRequestBody Publisher < T > publisher ) {
< T > void onDataAvailable ( AbstractListenerRead Publisher < T > publisher ) {
if ( publisher . changeState ( this , READING ) ) {
if ( publisher . changeState ( this , READING ) ) {
try {
try {
boolean demandAvailable = publisher . readAndPublish ( ) ;
boolean demandAvailable = publisher . readAndPublish ( ) ;
@ -279,7 +281,7 @@ public abstract class AbstractRequestBodyPublisher<T> implements Publisher<T> {
READING {
READING {
@Override
@Override
< T > void request ( AbstractRequestBody Publisher < T > publisher , long n ) {
< T > void request ( AbstractListenerRead Publisher < T > publisher , long n ) {
if ( Operators . checkRequest ( n , publisher . subscriber ) ) {
if ( Operators . checkRequest ( n , publisher . subscriber ) ) {
Operators . addAndGet ( publisher . demand , n ) ;
Operators . addAndGet ( publisher . demand , n ) ;
}
}
@ -291,40 +293,40 @@ public abstract class AbstractRequestBodyPublisher<T> implements Publisher<T> {
* /
* /
COMPLETED {
COMPLETED {
@Override
@Override
< T > void request ( AbstractRequestBody Publisher < T > publisher , long n ) {
< T > void request ( AbstractListenerRead Publisher < T > publisher , long n ) {
// ignore
// ignore
}
}
@Override
@Override
< T > void cancel ( AbstractRequestBody Publisher < T > publisher ) {
< T > void cancel ( AbstractListenerRead Publisher < T > publisher ) {
// ignore
// ignore
}
}
@Override
@Override
< T > void onAllDataRead ( AbstractRequestBody Publisher < T > publisher ) {
< T > void onAllDataRead ( AbstractListenerRead Publisher < T > publisher ) {
// ignore
// ignore
}
}
@Override
@Override
< T > void onError ( AbstractRequestBody Publisher < T > publisher , Throwable t ) {
< T > void onError ( AbstractListenerRead Publisher < T > publisher , Throwable t ) {
// ignore
// ignore
}
}
} ;
} ;
< T > void subscribe ( AbstractRequestBody Publisher < T > publisher , Subscriber < ? super T > subscriber ) {
< T > void subscribe ( AbstractListenerRead Publisher < T > publisher , Subscriber < ? super T > subscriber ) {
throw new IllegalStateException ( toString ( ) ) ;
throw new IllegalStateException ( toString ( ) ) ;
}
}
< T > void request ( AbstractRequestBody Publisher < T > publisher , long n ) {
< T > void request ( AbstractListenerRead Publisher < T > publisher , long n ) {
throw new IllegalStateException ( toString ( ) ) ;
throw new IllegalStateException ( toString ( ) ) ;
}
}
< T > void cancel ( AbstractRequestBody Publisher < T > publisher ) {
< T > void cancel ( AbstractListenerRead Publisher < T > publisher ) {
publisher . changeState ( this , COMPLETED ) ;
publisher . changeState ( this , COMPLETED ) ;
}
}
< T > void onDataAvailable ( AbstractRequestBody Publisher < T > publisher ) {
< T > void onDataAvailable ( AbstractListenerRead Publisher < T > publisher ) {
// ignore
// ignore
}
}
< T > void onAllDataRead ( AbstractRequestBody Publisher < T > publisher ) {
< T > void onAllDataRead ( AbstractListenerRead Publisher < T > publisher ) {
if ( publisher . changeState ( this , COMPLETED ) ) {
if ( publisher . changeState ( this , COMPLETED ) ) {
if ( publisher . subscriber ! = null ) {
if ( publisher . subscriber ! = null ) {
publisher . subscriber . onComplete ( ) ;
publisher . subscriber . onComplete ( ) ;
@ -332,7 +334,7 @@ public abstract class AbstractRequestBodyPublisher<T> implements Publisher<T> {
}
}
}
}
< T > void onError ( AbstractRequestBody Publisher < T > publisher , Throwable t ) {
< T > void onError ( AbstractListenerRead Publisher < T > publisher , Throwable t ) {
if ( publisher . changeState ( this , COMPLETED ) ) {
if ( publisher . changeState ( this , COMPLETED ) ) {
if ( publisher . subscriber ! = null ) {
if ( publisher . subscriber ! = null ) {
publisher . subscriber . onError ( t ) ;
publisher . subscriber . onError ( t ) ;