public abstract class AbstractGenericHandler<RESPONSE,ENCODED,REQUEST extends CouchbaseRequest>
extends io.netty.handler.codec.MessageToMessageCodec<RESPONSE,REQUEST>
Generic handler which acts as the common base type for all implementing handlers.
Modifier and Type | Field and Description |
---|---|
protected static java.nio.charset.Charset |
CHARSET
The default charset to use for all requests and responses.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractGenericHandler(AbstractEndpoint endpoint,
com.lmax.disruptor.EventSink<ResponseEvent> responseBuffer)
Creates a new
AbstractGenericHandler with the default queue. |
protected |
AbstractGenericHandler(AbstractEndpoint endpoint,
com.lmax.disruptor.EventSink<ResponseEvent> responseBuffer,
java.util.Queue<REQUEST> queue)
Creates a new
AbstractGenericHandler with a custom queue. |
Modifier and Type | Method and Description |
---|---|
void |
channelActive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) |
protected REQUEST |
currentRequest()
Returns the current request if set.
|
protected void |
decode(io.netty.channel.ChannelHandlerContext ctx,
RESPONSE msg,
java.util.List<java.lang.Object> out) |
protected abstract CouchbaseResponse |
decodeResponse(io.netty.channel.ChannelHandlerContext ctx,
RESPONSE msg)
Decodes the incoming response and transforms it into a
CouchbaseResponse . |
protected void |
encode(io.netty.channel.ChannelHandlerContext ctx,
REQUEST msg,
java.util.List<java.lang.Object> out) |
protected abstract ENCODED |
encodeRequest(io.netty.channel.ChannelHandlerContext ctx,
REQUEST msg)
Encode the outgoing request and return it in encoded format.
|
protected CoreEnvironment |
env()
Returns environment.
|
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Throwable cause) |
protected void |
finishedDecoding()
Notify that decoding is finished.
|
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
protected static java.lang.String |
logIdent(io.netty.channel.ChannelHandlerContext ctx,
Endpoint endpoint)
Simple log helper to give logs a common prefix.
|
protected void |
publishResponse(CouchbaseResponse response,
rx.subjects.Subject<CouchbaseResponse,CouchbaseResponse> observable)
Publishes a response with the attached observable.
|
acceptInboundMessage, acceptOutboundMessage, channelRead, write
bind, close, connect, deregister, disconnect, flush, read
channelReadComplete, channelRegistered, channelUnregistered, userEventTriggered
protected static final java.nio.charset.Charset CHARSET
The default charset to use for all requests and responses.
protected AbstractGenericHandler(AbstractEndpoint endpoint, com.lmax.disruptor.EventSink<ResponseEvent> responseBuffer)
Creates a new AbstractGenericHandler
with the default queue.
endpoint
- the endpoint reference.responseBuffer
- the response buffer.protected AbstractGenericHandler(AbstractEndpoint endpoint, com.lmax.disruptor.EventSink<ResponseEvent> responseBuffer, java.util.Queue<REQUEST> queue)
Creates a new AbstractGenericHandler
with a custom queue.
endpoint
- the endpoint reference.responseBuffer
- the response buffer.queue
- the queue.protected abstract ENCODED encodeRequest(io.netty.channel.ChannelHandlerContext ctx, REQUEST msg) throws java.lang.Exception
Encode the outgoing request and return it in encoded format.
This method needs to be implemented by the child handler and is responsible for the actual conversion.
ctx
- the context passed in.msg
- the outgoing message.java.lang.Exception
- as a generic error.protected abstract CouchbaseResponse decodeResponse(io.netty.channel.ChannelHandlerContext ctx, RESPONSE msg) throws java.lang.Exception
Decodes the incoming response and transforms it into a CouchbaseResponse
.
Note that the actual notification is handled by this generic handler, the implementing class only is concerned about the conversion itself.
ctx
- the context passed in.msg
- the incoming message.java.lang.Exception
- as a generic error.protected void encode(io.netty.channel.ChannelHandlerContext ctx, REQUEST msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
encode
in class io.netty.handler.codec.MessageToMessageCodec<RESPONSE,REQUEST extends CouchbaseRequest>
java.lang.Exception
protected void decode(io.netty.channel.ChannelHandlerContext ctx, RESPONSE msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
decode
in class io.netty.handler.codec.MessageToMessageCodec<RESPONSE,REQUEST extends CouchbaseRequest>
java.lang.Exception
protected void publishResponse(CouchbaseResponse response, rx.subjects.Subject<CouchbaseResponse,CouchbaseResponse> observable)
Publishes a response with the attached observable.
response
- the response to publish.observable
- pushing into the event sink.protected void finishedDecoding()
Notify that decoding is finished. This needs to be called by the child handlers in order to signal that operations are done.
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
channelInactive
in interface io.netty.channel.ChannelInboundHandler
channelInactive
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
channelActive
in interface io.netty.channel.ChannelInboundHandler
channelActive
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
channelWritabilityChanged
in interface io.netty.channel.ChannelInboundHandler
channelWritabilityChanged
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
java.lang.Exception
protected REQUEST currentRequest()
Returns the current request if set.
protected CoreEnvironment env()
Returns environment.
protected static java.lang.String logIdent(io.netty.channel.ChannelHandlerContext ctx, Endpoint endpoint)
Simple log helper to give logs a common prefix.
ctx
- the context.endpoint
- the endpoint.