T
- The publisher type@Internal public class HandlerPublisher<T> extends io.netty.channel.ChannelDuplexHandler implements HotObservable<T>
This publisher supports only one subscriber.
All interactions with the subscriber are done from the handlers executor, hence, they provide the same happens before semantics that Netty provides.
The handler publishes all messages that match the type as specified by the passed in class. Any non matching messages are forwarded to the next handler.
The publisher will signal complete if it receives a channel inactive event.
The publisher will release any messages that it drops (for example, messages that are buffered when the subscriber cancels), but other than that, it does not release any messages. It is up to the subscriber to release messages.
If the subscriber cancels, the publisher will send a close event up the channel pipeline.
All errors will short circuit the buffer, and cause publisher to immediately call the subscribers onError method, dropping the buffer.
The publisher can be subscribed to or placed in a handler chain in any order.
Constructor and Description |
---|
HandlerPublisher(io.netty.util.concurrent.EventExecutor executor,
java.lang.Class<? extends T> subscriberMessageType)
Create a handler publisher.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
acceptInboundMessage(java.lang.Object msg)
Returns
true if the given message should be handled. |
protected void |
cancelled()
Override to handle when a subscriber cancels the subscription.
|
void |
channelActive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Object message) |
void |
channelRegistered(io.netty.channel.ChannelHandlerContext ctx) |
void |
closeIfNoSubscriber()
Releases buffered data if there is no subscriber.
|
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) |
protected void |
requestDemand()
Override to intercept when demand is requested.
|
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber) |
bind, close, connect, deregister, disconnect, flush, read, write
public HandlerPublisher(io.netty.util.concurrent.EventExecutor executor, java.lang.Class<? extends T> subscriberMessageType)
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.
executor
- The executor to execute asynchronous events from the subscriber on.subscriberMessageType
- The type of message this publisher accepts.public void subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
subscribe
in interface org.reactivestreams.Publisher<T>
protected boolean acceptInboundMessage(java.lang.Object msg)
true
if the given message should be handled. If false
it will be passed to the next
ChannelInboundHandler
in the ChannelPipeline
.msg
- The message to check.protected void cancelled()
By default, this method will simply close the channel.
protected void requestDemand()
By default, a channel read is invoked.
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
public void channelRegistered(io.netty.channel.ChannelHandlerContext ctx)
channelRegistered
in interface io.netty.channel.ChannelInboundHandler
channelRegistered
in class io.netty.channel.ChannelInboundHandlerAdapter
public void channelActive(io.netty.channel.ChannelHandlerContext ctx)
channelActive
in interface io.netty.channel.ChannelInboundHandler
channelActive
in class io.netty.channel.ChannelInboundHandlerAdapter
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object message)
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
channelInactive
in interface io.netty.channel.ChannelInboundHandler
channelInactive
in class io.netty.channel.ChannelInboundHandlerAdapter
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
public void closeIfNoSubscriber()
HotObservable
closeIfNoSubscriber
in interface HotObservable<T>