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,
Class<? extends T> subscriberMessageType)
Create a handler publisher.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acceptInboundMessage(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,
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,
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(Subscriber<? super T> subscriber) |
bind, close, connect, deregister, disconnect, flush, read, writepublic HandlerPublisher(io.netty.util.concurrent.EventExecutor executor,
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(Subscriber<? super T> subscriber)
protected boolean acceptInboundMessage(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.ChannelHandlerhandlerAdded in class io.netty.channel.ChannelHandlerAdapterpublic void channelRegistered(io.netty.channel.ChannelHandlerContext ctx)
channelRegistered in interface io.netty.channel.ChannelInboundHandlerchannelRegistered in class io.netty.channel.ChannelInboundHandlerAdapterpublic void channelActive(io.netty.channel.ChannelHandlerContext ctx)
channelActive in interface io.netty.channel.ChannelInboundHandlerchannelActive in class io.netty.channel.ChannelInboundHandlerAdapterpublic void channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object message)
channelRead in interface io.netty.channel.ChannelInboundHandlerchannelRead in class io.netty.channel.ChannelInboundHandlerAdapterpublic void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
channelInactive in interface io.netty.channel.ChannelInboundHandlerchannelInactive in class io.netty.channel.ChannelInboundHandlerAdapterpublic void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
handlerRemoved in interface io.netty.channel.ChannelHandlerhandlerRemoved in class io.netty.channel.ChannelHandlerAdapterpublic void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause)
exceptionCaught in interface io.netty.channel.ChannelHandlerexceptionCaught in interface io.netty.channel.ChannelInboundHandlerexceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapterpublic void closeIfNoSubscriber()
HotObservablecloseIfNoSubscriber in interface HotObservable<T>