public abstract class AbstractGenericHandler<RESPONSE,ENCODED,REQUEST extends CouchbaseRequest> extends MessageToMessageCodec<RESPONSE,REQUEST>
Generic handler which acts as the common base type for all implementing handlers.
ChannelHandler.Sharable
Modifier and Type | Field and Description |
---|---|
protected static 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,
Queue<REQUEST> queue)
Creates a new
AbstractGenericHandler with a custom queue. |
Modifier and Type | Method and Description |
---|---|
void |
channelActive(ChannelHandlerContext ctx) |
void |
channelInactive(ChannelHandlerContext ctx) |
void |
channelWritabilityChanged(ChannelHandlerContext ctx) |
protected REQUEST |
currentRequest()
Returns the current request if set.
|
protected void |
decode(ChannelHandlerContext ctx,
RESPONSE msg,
List<Object> out) |
protected abstract CouchbaseResponse |
decodeResponse(ChannelHandlerContext ctx,
RESPONSE msg)
Decodes the incoming response and transforms it into a
CouchbaseResponse . |
protected void |
encode(ChannelHandlerContext ctx,
REQUEST msg,
List<Object> out) |
protected abstract ENCODED |
encodeRequest(ChannelHandlerContext ctx,
REQUEST msg)
Encode the outgoing request and return it in encoded format.
|
protected CoreEnvironment |
env()
Returns environment.
|
void |
exceptionCaught(ChannelHandlerContext ctx,
Throwable cause) |
protected void |
finishedDecoding()
Notify that decoding is finished.
|
void |
handlerRemoved(ChannelHandlerContext ctx) |
protected static String |
logIdent(ChannelHandlerContext ctx,
Endpoint endpoint)
Simple log helper to give logs a common prefix.
|
protected void |
publishResponse(CouchbaseResponse response,
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
handlerAdded, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded
protected static final 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, 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(ChannelHandlerContext ctx, REQUEST msg) throws 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.Exception
- as a generic error.protected abstract CouchbaseResponse decodeResponse(ChannelHandlerContext ctx, RESPONSE msg) throws 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.Exception
- as a generic error.protected void encode(ChannelHandlerContext ctx, REQUEST msg, List<Object> out) throws Exception
encode
in class MessageToMessageCodec<RESPONSE,REQUEST extends CouchbaseRequest>
Exception
protected void decode(ChannelHandlerContext ctx, RESPONSE msg, List<Object> out) throws Exception
decode
in class MessageToMessageCodec<RESPONSE,REQUEST extends CouchbaseRequest>
Exception
protected void publishResponse(CouchbaseResponse response, 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(ChannelHandlerContext ctx) throws Exception
channelInactive
in interface ChannelInboundHandler
channelInactive
in class ChannelInboundHandlerAdapter
Exception
public void channelActive(ChannelHandlerContext ctx) throws Exception
channelActive
in interface ChannelInboundHandler
channelActive
in class ChannelInboundHandlerAdapter
Exception
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
channelWritabilityChanged
in interface ChannelInboundHandler
channelWritabilityChanged
in class ChannelInboundHandlerAdapter
Exception
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
exceptionCaught
in interface ChannelHandler
exceptionCaught
in interface ChannelInboundHandler
exceptionCaught
in class ChannelInboundHandlerAdapter
Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
handlerRemoved
in interface ChannelHandler
handlerRemoved
in class ChannelHandlerAdapter
Exception
protected REQUEST currentRequest()
Returns the current request if set.
protected CoreEnvironment env()
Returns environment.
protected static String logIdent(ChannelHandlerContext ctx, Endpoint endpoint)
Simple log helper to give logs a common prefix.
ctx
- the context.endpoint
- the endpoint.Copyright © 2014 Couchbase, Inc.