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,
boolean isTransient)
Creates a new
AbstractGenericHandler with the default queue. |
protected |
AbstractGenericHandler(AbstractEndpoint endpoint,
com.lmax.disruptor.EventSink<ResponseEvent> responseBuffer,
Queue<REQUEST> queue,
boolean isTransient)
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) |
void |
connect(ChannelHandlerContext ctx,
SocketAddress remoteAddress,
SocketAddress localAddress,
ChannelPromise future) |
protected CouchbaseRequest |
createKeepAliveRequest()
Override to return a non-null request to be fired in the pipeline in case a keep alive is triggered.
|
protected REQUEST |
currentRequest()
Returns the current request if set.
|
protected void |
currentRequest(REQUEST request)
Sets current request.
|
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 AbstractEndpoint |
endpoint()
The parent endpoint.
|
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 |
onKeepAliveFired(ChannelHandlerContext ctx,
CouchbaseRequest keepAliveRequest)
Override to customize the behavior when a keep alive has been triggered and a keep alive request sent.
|
protected void |
onKeepAliveResponse(ChannelHandlerContext ctx,
CouchbaseResponse keepAliveResponse)
Override to customize the behavior when a keep alive has been responded to.
|
protected void |
publishResponse(CouchbaseResponse response,
Subject<CouchbaseResponse,CouchbaseResponse> observable)
Publishes a response with the attached observable.
|
protected String |
remoteHostname() |
protected abstract ServiceType |
serviceType()
Returns the
ServiceType associated with this handler. |
protected void |
sideEffectRequestToCancel(REQUEST request)
This method can be overridden as it is called every time an operation is cancelled.
|
void |
userEventTriggered(ChannelHandlerContext ctx,
Object evt) |
acceptInboundMessage, acceptOutboundMessage, channelRead, writebind, close, deregister, disconnect, flush, readchannelReadComplete, channelRegistered, channelUnregisteredhandlerAdded, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAddedprotected static final Charset CHARSET
The default charset to use for all requests and responses.
protected AbstractGenericHandler(AbstractEndpoint endpoint, com.lmax.disruptor.EventSink<ResponseEvent> responseBuffer, boolean isTransient)
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, boolean isTransient)
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. It will be bubbled up to the user (wrapped in a CouchbaseException) in the onError of the request’s Observable.protected abstract ServiceType serviceType()
Returns the ServiceType associated with this handler.
protected void encode(ChannelHandlerContext ctx, REQUEST msg, List<Object> out) throws Exception
encode in class MessageToMessageCodec<RESPONSE,REQUEST extends CouchbaseRequest>Exceptionprotected void decode(ChannelHandlerContext ctx, RESPONSE msg, List<Object> out) throws Exception
decode in class MessageToMessageCodec<RESPONSE,REQUEST extends CouchbaseRequest>Exceptionprotected 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 ChannelInboundHandlerchannelInactive in class ChannelInboundHandlerAdapterExceptionpublic void channelActive(ChannelHandlerContext ctx) throws Exception
channelActive in interface ChannelInboundHandlerchannelActive in class ChannelInboundHandlerAdapterExceptionpublic void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
channelWritabilityChanged in interface ChannelInboundHandlerchannelWritabilityChanged in class ChannelInboundHandlerAdapterExceptionpublic void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise future) throws Exception
connect in interface ChannelOutboundHandlerconnect in class ChannelDuplexHandlerExceptionpublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
exceptionCaught in interface ChannelHandlerexceptionCaught in interface ChannelInboundHandlerexceptionCaught in class ChannelInboundHandlerAdapterExceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
handlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionprotected void sideEffectRequestToCancel(REQUEST request)
This method can be overridden as it is called every time an operation is cancelled.
Overriding implementations may do some custom logic with them, for example freeing resources they know of to avoid leaking.
request - the request to side effect on.public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
userEventTriggered in interface ChannelInboundHandleruserEventTriggered in class ChannelInboundHandlerAdapterExceptionprotected CouchbaseRequest createKeepAliveRequest()
Override to return a non-null request to be fired in the pipeline in case a keep alive is triggered.
protected void onKeepAliveFired(ChannelHandlerContext ctx, CouchbaseRequest keepAliveRequest)
Override to customize the behavior when a keep alive has been triggered and a keep alive request sent.
The default behavior is to log the event at debug level.
ctx - the channel context.keepAliveRequest - the keep alive request that was sent when keep alive was triggeredprotected void onKeepAliveResponse(ChannelHandlerContext ctx, CouchbaseResponse keepAliveResponse)
Override to customize the behavior when a keep alive has been responded to.
The default behavior is to log the event and the response status at trace level.
ctx - the channel context.keepAliveResponse - the keep alive request that was sent when keep alive was triggeredprotected REQUEST currentRequest()
Returns the current request if set.
protected void currentRequest(REQUEST request)
Sets current request.
FIXME this is temporary solution for DCPHandler
request - request to become the current oneprotected String remoteHostname()
protected CoreEnvironment env()
Returns environment.
protected AbstractEndpoint endpoint()
The parent endpoint.
protected static String logIdent(ChannelHandlerContext ctx, Endpoint endpoint)
Simple log helper to give logs a common prefix.
ctx - the context.endpoint - the endpoint.Copyright © 2016 Couchbase, Inc.. All rights reserved.