List of usage examples for io.netty.channel ChannelHandlerContext attr
@Deprecated @Override <T> Attribute<T> attr(AttributeKey<T> key);
From source file:com.ebay.jetstream.http.netty.server.KeepAliveHandler.java
License:MIT License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Attribute<AtomicInteger> attr = ctx.attr(REQUEST_COUNT); if (attr.get() == null) { attr.setIfAbsent(new AtomicInteger()); }//from www . j a v a 2 s. c o m attr.get().incrementAndGet(); ctx.fireChannelRead(msg); }
From source file:com.ebay.jetstream.http.netty.server.KeepAliveHandler.java
License:MIT License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (maxKeepAliveTimeoutInNanoTime > 0 && ((System.nanoTime() - ctx.attr(CREATION_TIME).get()) > maxKeepAliveTimeoutInNanoTime)) { closeConnection(msg, promise);// w w w .j a v a 2s . c om } else if (maxKeepAliveRequests > 0 && (ctx.attr(REQUEST_COUNT).get() != null && ctx.attr(REQUEST_COUNT).get().get() >= maxKeepAliveRequests)) { closeConnection(msg, promise); } ctx.write(msg, promise); }
From source file:com.ebay.jetstream.messaging.transport.netty.eventconsumer.EventProducerSessionHandler.java
License:MIT License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (EventProducerSessionHandler.BATCH_START_EVENT == msg) { ctx.attr(BATCH_FLAG).set(Boolean.TRUE); return;/*from w ww .ja v a 2s. com*/ } if (EventProducerSessionHandler.BATCH_END_EVENT == msg) { ctx.attr(BATCH_FLAG).remove(); List<JetstreamMessage> msgs = ctx.attr(BATCH_CONTAINER).get(); if (msgs != null && !msgs.isEmpty()) { try { m_eventConsumer.receive(msgs); } finally { msgs.clear(); } } return; } Boolean flag = ctx.attr(BATCH_FLAG).get(); if (flag != null) { List<JetstreamMessage> msgs = ctx.attr(BATCH_CONTAINER).get(); if (msgs == null) { ctx.attr(BATCH_CONTAINER).setIfAbsent(new ArrayList<JetstreamMessage>(MAX_INBOUND_BATCH_SIZE)); msgs = ctx.attr(BATCH_CONTAINER).get(); } msgs.add((JetstreamMessage) msg); if (msgs.size() == MAX_INBOUND_BATCH_SIZE) { try { m_eventConsumer.receive(msgs); } finally { msgs.clear(); } } } else { JetstreamMessage tm = (JetstreamMessage) msg; m_eventConsumer.receive(tm); // now dispatch upstream } }
From source file:com.eightkdata.mongowp.mongoserver.api.callback.MessageReplier.java
License:Open Source License
public MessageReplier(@Nonnull ChannelHandlerContext channelHandlerContext) { Preconditions.checkNotNull(channelHandlerContext); this.channelHandlerContext = channelHandlerContext; this.requestId = channelHandlerContext.attr(REQUEST_ID).get(); }
From source file:com.eightkdata.mongowp.mongoserver.RequestMessageObjectHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { RequestMessage requestMessage = (RequestMessage) msg; ctx.attr(MessageReplier.REQUEST_ID).set(requestMessage.getBaseMessage().getRequestId()); LOGGER.debug("Received message type: {}, data: {}", requestMessage.getOpCode(), requestMessage); MessageReplier messageReplier = new MessageReplier(ctx); ctx.attr(REQUEST_OP_CODE).set(requestMessage.getOpCode()); switch (requestMessage.getOpCode()) { case OP_QUERY: assert requestMessage instanceof QueryMessage; requestProcessor.queryMessage((QueryMessage) requestMessage, messageReplier); break;//from w w w . j a v a 2 s. co m case OP_GET_MORE: assert requestMessage instanceof GetMoreMessage; requestProcessor.getMore((GetMoreMessage) requestMessage, messageReplier); break; case OP_KILL_CURSORS: assert requestMessage instanceof KillCursorsMessage; requestProcessor.killCursors((KillCursorsMessage) requestMessage, messageReplier); break; case OP_INSERT: assert requestMessage instanceof InsertMessage; requestProcessor.insert((InsertMessage) requestMessage, messageReplier); break; case OP_UPDATE: assert requestMessage instanceof UpdateMessage; requestProcessor.update((UpdateMessage) requestMessage, messageReplier); break; case OP_DELETE: assert requestMessage instanceof DeleteMessage; requestProcessor.delete((DeleteMessage) requestMessage, messageReplier); break; // TODO: implement missing cases default: throw new UnsupportedOperationException( "Message replier not implemented for " + requestMessage.getOpCode() + " opCode"); } }
From source file:com.eightkdata.mongowp.mongoserver.RequestMessageObjectHandler.java
License:Open Source License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { LOGGER.error("Error while processing request", cause); MessageReplier messageReplier = new MessageReplier(ctx); requestProcessor.handleError(ctx.attr(REQUEST_OP_CODE).get(), messageReplier, cause); }
From source file:com.eightkdata.mongowp.server.wp.RequestMessageObjectHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { try (RequestMessage requestMessage = (RequestMessage) msg) { ctx.attr(NettyMessageReplier.REQUEST_ID).set(requestMessage.getBaseMessage().getRequestId()); LOGGER.debug("Received message type: {}, data: {}", requestMessage.getOpCode(), requestMessage); MessageReplier messageReplier = new NettyMessageReplier(ctx); ctx.attr(REQUEST_OP_CODE).set(requestMessage.getOpCode()); switch (requestMessage.getOpCode()) { case OP_QUERY: assert requestMessage instanceof QueryMessage; requestProcessor.queryMessage((QueryMessage) requestMessage, messageReplier); break; case OP_GET_MORE: assert requestMessage instanceof GetMoreMessage; requestProcessor.getMore((GetMoreMessage) requestMessage, messageReplier); break; case OP_KILL_CURSORS: assert requestMessage instanceof KillCursorsMessage; requestProcessor.killCursors((KillCursorsMessage) requestMessage, messageReplier); break; case OP_INSERT: assert requestMessage instanceof InsertMessage; requestProcessor.insert((InsertMessage) requestMessage, messageReplier); break; case OP_UPDATE: assert requestMessage instanceof UpdateMessage; requestProcessor.update((UpdateMessage) requestMessage, messageReplier); break; case OP_DELETE: assert requestMessage instanceof DeleteMessage; requestProcessor.delete((DeleteMessage) requestMessage, messageReplier); break; default://from w w w .jav a 2s.c o m throw new UnsupportedOperationException( "Message replier not implemented for " + requestMessage.getOpCode() + " opCode"); } } }
From source file:com.eightkdata.mongowp.server.wp.RequestMessageObjectHandler.java
License:Open Source License
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { logCaughtException(cause);/*w ww .j a v a2 s. c o m*/ MessageReplier messageReplier = new NettyMessageReplier(ctx); requestProcessor.handleError(ctx.attr(REQUEST_OP_CODE).get(), messageReplier, cause); }
From source file:com.facebook.nifty.core.NiftyDispatcher.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.attr(READ_BLOCKED_STATE_KEY).set(ReadBlockedState.NOT_BLOCKED); super.channelActive(ctx); }
From source file:com.facebook.nifty.core.NiftyDispatcher.java
License:Apache License
private boolean isChannelReadBlocked(ChannelHandlerContext ctx) { return ctx.attr(READ_BLOCKED_STATE_KEY).get() == ReadBlockedState.BLOCKED; }