public int getRequestId() { return requestBaseMessage.getRequestId(); }
@Nullable public InetAddress getClientAddress() { return requestBaseMessage.getClientAddress(); }
@Nullable public String getClientAddressString() { return requestBaseMessage.getClientAddressString(); }
public int getClientPort() { return requestBaseMessage.getClientPort(); }
/** * Method that constructs a RequestBaseMessage object based on a correctly-positioned ByteBuf. * This method modifies the internal state of the ByteBuf. It expects the ByteBuf to be positioned * just before the start of the requestId field. After running, the method will leave the ByteBuf * positioned just after the responseTo field, i.e., just before reading the opCode. * * @param channelHandlerContext * @param byteBuf * @return */ public static RequestBaseMessage decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) { InetSocketAddress socketAddress = (InetSocketAddress) channelHandlerContext.channel() .remoteAddress(); return new RequestBaseMessage(socketAddress.getAddress(), socketAddress.getPort(), byteBuf .readInt()); } }
@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);
@Override public String toString() { return "clientAddress=" + requestBaseMessage.getClientAddressString() + ", clientPort=" + getClientPort() + ", requestId=" + getRequestId(); } }