/** * Initializes the src buffer. Should only be called by InboundHandler * implementations that have a ByteBuffer as source. * * @param sizeBytes the size of the srcBuffer in bytes. */ protected final void initSrcBuffer(int sizeBytes) { ChannelOptions config = channel.options(); src = (S) newByteBuffer(sizeBytes, config.getOption(DIRECT_BUF)); } }
/** * Initializes the src buffer. Should only be called by InboundHandler * implementations that have a ByteBuffer as source. * * @param sizeBytes the size of the srcBuffer in bytes. */ protected final void initSrcBuffer(int sizeBytes) { ChannelOptions config = channel.options(); src = (S) newByteBuffer(sizeBytes, config.getOption(DIRECT_BUF)); } }
/** * Initializes the dst ByteBuffer with the configured size. * * The buffer created is reading mode. * * @param sizeBytes the size of the dst ByteBuffer. * @param bytes the bytes added to the buffer. Can be null if nothing * should be added. * @throws IllegalArgumentException if the size of the buffer is too small. */ protected final void initDstBuffer(int sizeBytes, byte[] bytes) { if (bytes != null && bytes.length > sizeBytes) { throw new IllegalArgumentException("Buffer overflow. Can't initialize dstBuffer for " + this + " and channel" + channel + " because too many bytes, sizeBytes " + sizeBytes + ". bytes.length " + bytes.length); } ChannelOptions config = channel.options(); ByteBuffer buffer = newByteBuffer(sizeBytes, config.getOption(DIRECT_BUF)); if (bytes != null) { buffer.put(bytes); } buffer.flip(); dst = (D) buffer; } }
/** * Initializes the dst ByteBuffer with the configured size. * * The buffer created is reading mode. * * @param sizeBytes the size of the dst ByteBuffer. * @param bytes the bytes added to the buffer. Can be null if nothing * should be added. * @throws IllegalArgumentException if the size of the buffer is too small. */ protected final void initDstBuffer(int sizeBytes, byte[] bytes) { if (bytes != null && bytes.length > sizeBytes) { throw new IllegalArgumentException("Buffer overflow. Can't initialize dstBuffer for " + this + " and channel" + channel + " because too many bytes, sizeBytes " + sizeBytes + ". bytes.length " + bytes.length); } ChannelOptions config = channel.options(); ByteBuffer buffer = newByteBuffer(sizeBytes, config.getOption(DIRECT_BUF)); if (bytes != null) { buffer.put(bytes); } buffer.flip(); dst = (D) buffer; } }
private void initChannelForText(String protocol) { ChannelOptions config = channel.options(); config.setOption(SO_RCVBUF, clientRcvBuf()); TcpIpConnection connection = (TcpIpConnection) channel.attributeMap().get(TcpIpConnection.class); connection.getConnectionManager().incrementTextConnections(); TextEncoder encoder = new TextEncoder(connection); channel.attributeMap().put(TextEncoder.TEXT_ENCODER, encoder); TextDecoder decoder = new TextDecoder(connection, encoder); decoder.src(newByteBuffer(config.getOption(SO_RCVBUF), config.getOption(DIRECT_BUF))); // we need to restore whatever is read decoder.src().put(stringToBytes(protocol)); channel.inboundPipeline().replace(this, decoder); }
private void initChannelForText(String protocol, boolean restApi) { ChannelOptions config = channel.options(); config.setOption(SO_RCVBUF, clientRcvBuf()); TcpIpConnection connection = (TcpIpConnection) channel.attributeMap().get(TcpIpConnection.class); connection.getConnectionManager().incrementTextConnections(); TextEncoder encoder = new TextEncoder(connection); channel.attributeMap().put(TextEncoder.TEXT_ENCODER, encoder); TextDecoder decoder = restApi ? new RestApiTextDecoder(connection, encoder) : new MemcacheTextDecoder(connection, encoder); decoder.src(newByteBuffer(config.getOption(SO_RCVBUF), config.getOption(DIRECT_BUF))); // we need to restore whatever is read decoder.src().put(stringToBytes(protocol)); channel.inboundPipeline().replace(this, decoder); }