Package org.playframework.netty
Class HandlerSubscriber<T>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- org.playframework.netty.HandlerSubscriber<T>
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
,org.reactivestreams.Subscriber<T>
public class HandlerSubscriber<T> extends io.netty.channel.ChannelDuplexHandler implements org.reactivestreams.Subscriber<T>
Subscriber that publishes received messages to the handler pipeline.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
HandlerSubscriber.State
-
Field Summary
Fields Modifier and Type Field Description private io.netty.channel.ChannelHandlerContext
ctx
(package private) static long
DEFAULT_HIGH_WATERMARK
(package private) static long
DEFAULT_LOW_WATERMARK
private long
demandHighWatermark
private long
demandLowWatermark
private io.netty.util.concurrent.EventExecutor
executor
private java.util.concurrent.atomic.AtomicBoolean
hasSubscription
private io.netty.channel.ChannelFuture
lastWriteFuture
private long
outstandingDemand
private HandlerSubscriber.State
state
private org.reactivestreams.Subscription
subscription
-
Constructor Summary
Constructors Constructor Description HandlerSubscriber(io.netty.util.concurrent.EventExecutor executor)
Create a new handler subscriber with the default low and high watermarks.HandlerSubscriber(io.netty.util.concurrent.EventExecutor executor, long demandLowWatermark, long demandHighWatermark)
Create a new handler subscriber.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
cancel()
void
channelActive(io.netty.channel.ChannelHandlerContext ctx)
void
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
void
channelRegistered(io.netty.channel.ChannelHandlerContext ctx)
void
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)
protected void
complete()
Override for custom completion handling.private void
doClose()
protected void
error(java.lang.Throwable error)
Override for custom error handling.void
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)
void
handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
void
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
private void
maybeRequestMore()
private void
maybeStart()
void
onComplete()
void
onError(java.lang.Throwable error)
void
onNext(T t)
void
onSubscribe(org.reactivestreams.Subscription subscription)
private void
provideSubscription()
private void
verifyRegisteredWithRightExecutor(io.netty.channel.ChannelHandlerContext ctx)
-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read, write
-
-
-
-
Field Detail
-
DEFAULT_LOW_WATERMARK
static final long DEFAULT_LOW_WATERMARK
- See Also:
- Constant Field Values
-
DEFAULT_HIGH_WATERMARK
static final long DEFAULT_HIGH_WATERMARK
- See Also:
- Constant Field Values
-
executor
private final io.netty.util.concurrent.EventExecutor executor
-
demandLowWatermark
private final long demandLowWatermark
-
demandHighWatermark
private final long demandHighWatermark
-
hasSubscription
private final java.util.concurrent.atomic.AtomicBoolean hasSubscription
-
subscription
private volatile org.reactivestreams.Subscription subscription
-
ctx
private volatile io.netty.channel.ChannelHandlerContext ctx
-
state
private HandlerSubscriber.State state
-
outstandingDemand
private long outstandingDemand
-
lastWriteFuture
private io.netty.channel.ChannelFuture lastWriteFuture
-
-
Constructor Detail
-
HandlerSubscriber
public HandlerSubscriber(io.netty.util.concurrent.EventExecutor executor, long demandLowWatermark, long demandHighWatermark)
Create a new handler subscriber. The supplied executor must be the same event loop as the event loop that this handler is eventually registered with, if not, an exception will be thrown when the handler is registered.- Parameters:
executor
- The executor to execute asynchronous events from the publisher on.demandLowWatermark
- The low watermark for demand. When demand drops below this, more will be requested.demandHighWatermark
- The high watermark for demand. This is the maximum that will be requested.
-
HandlerSubscriber
public HandlerSubscriber(io.netty.util.concurrent.EventExecutor executor)
Create a new handler subscriber with the default low and high watermarks. The supplied executor must be the same event loop as the event loop that this handler is eventually registered with, if not, an exception will be thrown when the handler is registered.- Parameters:
executor
- The executor to execute asynchronous events from the publisher on.- See Also:
HandlerSubscriber(EventExecutor, long, long)
-
-
Method Detail
-
error
protected void error(java.lang.Throwable error)
Override for custom error handling. By default, it closes the channel.- Parameters:
error
- The error to handle.
-
complete
protected void complete()
Override for custom completion handling. By default, it closes the channel.
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
java.lang.Exception
-
channelRegistered
public void channelRegistered(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelRegistered
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRegistered
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
verifyRegisteredWithRightExecutor
private void verifyRegisteredWithRightExecutor(io.netty.channel.ChannelHandlerContext ctx)
-
channelWritabilityChanged
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelWritabilityChanged
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelWritabilityChanged
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
channelActive
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelActive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelActive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
handlerRemoved
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerRemoved
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
java.lang.Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
cancel
private void cancel()
-
onSubscribe
public void onSubscribe(org.reactivestreams.Subscription subscription)
- Specified by:
onSubscribe
in interfaceorg.reactivestreams.Subscriber<T>
-
provideSubscription
private void provideSubscription()
-
maybeStart
private void maybeStart()
-
onError
public void onError(java.lang.Throwable error)
- Specified by:
onError
in interfaceorg.reactivestreams.Subscriber<T>
-
onComplete
public void onComplete()
- Specified by:
onComplete
in interfaceorg.reactivestreams.Subscriber<T>
-
doClose
private void doClose()
-
maybeRequestMore
private void maybeRequestMore()
-
-