2012-06-11 13:24:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2012 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
package io.netty.buffer;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.ByteOrder;
|
|
|
|
import java.nio.channels.GatheringByteChannel;
|
|
|
|
import java.nio.channels.ScatteringByteChannel;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
2013-07-08 06:32:33 +02:00
|
|
|
public final class SwappedByteBuf extends ByteBuf {
|
2012-06-11 13:24:44 +02:00
|
|
|
|
2012-12-05 11:28:56 +01:00
|
|
|
private final ByteBuf buf;
|
2012-06-11 13:24:44 +02:00
|
|
|
private final ByteOrder order;
|
|
|
|
|
2012-12-05 11:28:56 +01:00
|
|
|
public SwappedByteBuf(ByteBuf buf) {
|
2012-06-11 13:24:44 +02:00
|
|
|
if (buf == null) {
|
|
|
|
throw new NullPointerException("buf");
|
|
|
|
}
|
|
|
|
this.buf = buf;
|
|
|
|
if (buf.order() == ByteOrder.BIG_ENDIAN) {
|
|
|
|
order = ByteOrder.LITTLE_ENDIAN;
|
|
|
|
} else {
|
|
|
|
order = ByteOrder.BIG_ENDIAN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteOrder order() {
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf order(ByteOrder endianness) {
|
|
|
|
if (endianness == null) {
|
|
|
|
throw new NullPointerException("endianness");
|
|
|
|
}
|
|
|
|
if (endianness == order) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf unwrap() {
|
2013-01-17 04:05:43 +01:00
|
|
|
return buf.unwrap();
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBufAllocator alloc() {
|
|
|
|
return buf.alloc();
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-07-19 13:23:55 +02:00
|
|
|
public int capacity() {
|
|
|
|
return buf.capacity();
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf capacity(int newCapacity) {
|
2012-07-19 13:23:55 +02:00
|
|
|
buf.capacity(newCapacity);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-07-19 13:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int maxCapacity() {
|
|
|
|
return buf.maxCapacity();
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDirect() {
|
|
|
|
return buf.isDirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int readerIndex() {
|
|
|
|
return buf.readerIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readerIndex(int readerIndex) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readerIndex(readerIndex);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int writerIndex() {
|
|
|
|
return buf.writerIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writerIndex(int writerIndex) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writerIndex(writerIndex);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setIndex(int readerIndex, int writerIndex) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setIndex(readerIndex, writerIndex);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int readableBytes() {
|
|
|
|
return buf.readableBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int writableBytes() {
|
|
|
|
return buf.writableBytes();
|
|
|
|
}
|
|
|
|
|
2012-12-14 03:49:01 +01:00
|
|
|
@Override
|
|
|
|
public int maxWritableBytes() {
|
|
|
|
return buf.maxWritableBytes();
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
2013-01-31 15:28:08 +01:00
|
|
|
public boolean isReadable() {
|
|
|
|
return buf.isReadable();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isReadable(int size) {
|
|
|
|
return buf.isReadable(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWritable() {
|
|
|
|
return buf.isWritable();
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2013-01-31 15:28:08 +01:00
|
|
|
@Override
|
|
|
|
public boolean isWritable(int size) {
|
|
|
|
return buf.isWritable(size);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf clear() {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.clear();
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf markReaderIndex() {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.markReaderIndex();
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf resetReaderIndex() {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.resetReaderIndex();
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf markWriterIndex() {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.markWriterIndex();
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf resetWriterIndex() {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.resetWriterIndex();
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf discardReadBytes() {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.discardReadBytes();
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2012-12-17 09:41:21 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf discardSomeReadBytes() {
|
|
|
|
buf.discardSomeReadBytes();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
2013-01-31 15:28:08 +01:00
|
|
|
public ByteBuf ensureWritable(int writableBytes) {
|
|
|
|
buf.ensureWritable(writableBytes);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-08-20 05:52:38 +02:00
|
|
|
@Override
|
2013-01-31 15:28:08 +01:00
|
|
|
public int ensureWritable(int minWritableBytes, boolean force) {
|
|
|
|
return buf.ensureWritable(minWritableBytes, force);
|
2012-08-20 05:52:38 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public boolean getBoolean(int index) {
|
|
|
|
return buf.getBoolean(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public byte getByte(int index) {
|
|
|
|
return buf.getByte(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getUnsignedByte(int index) {
|
|
|
|
return buf.getUnsignedByte(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getShort(int index) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapShort(buf.getShort(index));
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getUnsignedShort(int index) {
|
|
|
|
return getShort(index) & 0xFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMedium(int index) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapMedium(buf.getMedium(index));
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getUnsignedMedium(int index) {
|
|
|
|
return getMedium(index) & 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInt(int index) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapInt(buf.getInt(index));
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getUnsignedInt(int index) {
|
|
|
|
return getInt(index) & 0xFFFFFFFFL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getLong(int index) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapLong(buf.getLong(index));
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public char getChar(int index) {
|
|
|
|
return (char) getShort(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getFloat(int index) {
|
|
|
|
return Float.intBitsToFloat(getInt(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getDouble(int index) {
|
|
|
|
return Double.longBitsToDouble(getLong(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, ByteBuf dst) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.getBytes(index, dst);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, ByteBuf dst, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.getBytes(index, dst, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.getBytes(index, dst, dstIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, byte[] dst) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.getBytes(index, dst);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.getBytes(index, dst, dstIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, ByteBuffer dst) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.getBytes(index, dst);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.getBytes(index, out, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
|
|
|
|
return buf.getBytes(index, out, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBoolean(int index, boolean value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setBoolean(index, value);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setByte(int index, int value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setByte(index, value);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setShort(int index, int value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.setShort(index, ByteBufUtil.swapShort((short) value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setMedium(int index, int value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.setMedium(index, ByteBufUtil.swapMedium(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setInt(int index, int value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.setInt(index, ByteBufUtil.swapInt(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setLong(int index, long value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.setLong(index, ByteBufUtil.swapLong(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setChar(int index, int value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
setShort(index, value);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setFloat(int index, float value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
setInt(index, Float.floatToRawIntBits(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setDouble(int index, double value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
setLong(index, Double.doubleToRawLongBits(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBytes(int index, ByteBuf src) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setBytes(index, src);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBytes(int index, ByteBuf src, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setBytes(index, src, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setBytes(index, src, srcIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBytes(int index, byte[] src) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setBytes(index, src);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setBytes(index, src, srcIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBytes(int index, ByteBuffer src) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setBytes(index, src);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int setBytes(int index, InputStream in, int length) throws IOException {
|
|
|
|
return buf.setBytes(index, in, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
|
|
|
|
return buf.setBytes(index, in, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setZero(int index, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.setZero(index, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean readBoolean() {
|
|
|
|
return buf.readBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public byte readByte() {
|
|
|
|
return buf.readByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short readUnsignedByte() {
|
|
|
|
return buf.readUnsignedByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short readShort() {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapShort(buf.readShort());
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int readUnsignedShort() {
|
|
|
|
return readShort() & 0xFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int readMedium() {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapMedium(buf.readMedium());
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int readUnsignedMedium() {
|
|
|
|
return readMedium() & 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int readInt() {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapInt(buf.readInt());
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long readUnsignedInt() {
|
|
|
|
return readInt() & 0xFFFFFFFFL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long readLong() {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.swapLong(buf.readLong());
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public char readChar() {
|
|
|
|
return (char) readShort();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float readFloat() {
|
|
|
|
return Float.intBitsToFloat(readInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double readDouble() {
|
|
|
|
return Double.longBitsToDouble(readLong());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf readBytes(int length) {
|
2012-11-15 22:04:37 +01:00
|
|
|
return buf.readBytes(length).order(order());
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf readSlice(int length) {
|
|
|
|
return buf.readSlice(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readBytes(ByteBuf dst) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readBytes(dst);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readBytes(ByteBuf dst, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readBytes(dst, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readBytes(dst, dstIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readBytes(byte[] dst) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readBytes(dst);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readBytes(byte[] dst, int dstIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readBytes(dst, dstIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readBytes(ByteBuffer dst) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readBytes(dst);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf readBytes(OutputStream out, int length) throws IOException {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.readBytes(out, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int readBytes(GatheringByteChannel out, int length) throws IOException {
|
|
|
|
return buf.readBytes(out, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf skipBytes(int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.skipBytes(length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeBoolean(boolean value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeBoolean(value);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeByte(int value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeByte(value);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeShort(int value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.writeShort(ByteBufUtil.swapShort((short) value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeMedium(int value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.writeMedium(ByteBufUtil.swapMedium(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeInt(int value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.writeInt(ByteBufUtil.swapInt(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeLong(long value) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
buf.writeLong(ByteBufUtil.swapLong(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeChar(int value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
writeShort(value);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeFloat(float value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
writeInt(Float.floatToRawIntBits(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeDouble(double value) {
|
2012-06-11 13:24:44 +02:00
|
|
|
writeLong(Double.doubleToRawLongBits(value));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeBytes(ByteBuf src) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeBytes(src);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeBytes(ByteBuf src, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeBytes(src, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeBytes(ByteBuf src, int srcIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeBytes(src, srcIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeBytes(byte[] src) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeBytes(src);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeBytes(byte[] src, int srcIndex, int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeBytes(src, srcIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeBytes(ByteBuffer src) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeBytes(src);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int writeBytes(InputStream in, int length) throws IOException {
|
|
|
|
return buf.writeBytes(in, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
|
|
|
|
return buf.writeBytes(in, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf writeZero(int length) {
|
2012-06-11 13:24:44 +02:00
|
|
|
buf.writeZero(length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int indexOf(int fromIndex, int toIndex, byte value) {
|
|
|
|
return buf.indexOf(fromIndex, toIndex, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int bytesBefore(byte value) {
|
|
|
|
return buf.bytesBefore(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int bytesBefore(int length, byte value) {
|
|
|
|
return buf.bytesBefore(length, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int bytesBefore(int index, int length, byte value) {
|
|
|
|
return buf.bytesBefore(index, length, value);
|
|
|
|
}
|
|
|
|
|
2013-06-27 06:55:42 +02:00
|
|
|
@Override
|
|
|
|
public int forEachByte(ByteBufProcessor processor) {
|
2013-06-28 13:29:00 +02:00
|
|
|
return buf.forEachByte(processor);
|
2013-06-27 06:55:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-28 13:29:00 +02:00
|
|
|
public int forEachByte(int index, int length, ByteBufProcessor processor) {
|
|
|
|
return buf.forEachByte(index, length, processor);
|
2013-06-27 11:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int forEachByteDesc(ByteBufProcessor processor) {
|
2013-06-28 13:29:00 +02:00
|
|
|
return buf.forEachByteDesc(processor);
|
2013-06-27 11:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-28 13:29:00 +02:00
|
|
|
public int forEachByteDesc(int index, int length, ByteBufProcessor processor) {
|
|
|
|
return buf.forEachByteDesc(index, length, processor);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf copy() {
|
|
|
|
return buf.copy().order(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf copy(int index, int length) {
|
|
|
|
return buf.copy(index, length).order(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf slice() {
|
|
|
|
return buf.slice().order(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf slice(int index, int length) {
|
|
|
|
return buf.slice(index, length).order(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf duplicate() {
|
|
|
|
return buf.duplicate().order(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-12-14 04:20:33 +01:00
|
|
|
public int nioBufferCount() {
|
|
|
|
return buf.nioBufferCount();
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuffer nioBuffer() {
|
|
|
|
return buf.nioBuffer().order(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuffer nioBuffer(int index, int length) {
|
|
|
|
return buf.nioBuffer(index, length).order(order);
|
|
|
|
}
|
|
|
|
|
2013-06-13 05:40:26 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuffer internalNioBuffer(int index, int length) {
|
|
|
|
// Do not mess with the internal buffer's byte order.
|
|
|
|
return buf.nioBuffer(index, length).order(order);
|
|
|
|
}
|
|
|
|
|
2012-08-13 02:29:07 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuffer[] nioBuffers() {
|
|
|
|
ByteBuffer[] nioBuffers = buf.nioBuffers();
|
|
|
|
for (int i = 0; i < nioBuffers.length; i++) {
|
|
|
|
nioBuffers[i] = nioBuffers[i].order(order);
|
|
|
|
}
|
|
|
|
return nioBuffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-12-05 22:11:48 +01:00
|
|
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
|
|
|
ByteBuffer[] nioBuffers = buf.nioBuffers(index, length);
|
2012-08-13 02:29:07 +02:00
|
|
|
for (int i = 0; i < nioBuffers.length; i++) {
|
|
|
|
nioBuffers[i] = nioBuffers[i].order(order);
|
|
|
|
}
|
|
|
|
return nioBuffers;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasArray() {
|
|
|
|
return buf.hasArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public byte[] array() {
|
|
|
|
return buf.array();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int arrayOffset() {
|
|
|
|
return buf.arrayOffset();
|
|
|
|
}
|
|
|
|
|
2013-03-06 10:22:16 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasMemoryAddress() {
|
|
|
|
return buf.hasMemoryAddress();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long memoryAddress() {
|
|
|
|
return buf.memoryAddress();
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public String toString(Charset charset) {
|
|
|
|
return buf.toString(charset);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString(int index, int length, Charset charset) {
|
|
|
|
return buf.toString(index, length, charset);
|
|
|
|
}
|
|
|
|
|
2012-12-17 09:41:21 +01:00
|
|
|
@Override
|
2013-02-10 05:10:09 +01:00
|
|
|
public int refCnt() {
|
|
|
|
return buf.refCnt();
|
2012-12-17 09:41:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-02-13 08:09:33 +01:00
|
|
|
public ByteBuf retain() {
|
2013-02-10 05:10:09 +01:00
|
|
|
buf.retain();
|
2013-02-13 08:09:33 +01:00
|
|
|
return this;
|
2013-02-10 05:10:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-02-13 08:09:33 +01:00
|
|
|
public ByteBuf retain(int increment) {
|
2013-02-10 05:10:09 +01:00
|
|
|
buf.retain(increment);
|
2013-02-13 08:09:33 +01:00
|
|
|
return this;
|
2013-02-10 05:10:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean release() {
|
|
|
|
return buf.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean release(int decrement) {
|
|
|
|
return buf.release(decrement);
|
2012-12-17 09:41:21 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return buf.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (obj instanceof ByteBuf) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.equals(this, (ByteBuf) obj);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(ByteBuf buffer) {
|
Revamp the core API to reduce memory footprint and consumption
The API changes made so far turned out to increase the memory footprint
and consumption while our intention was actually decreasing them.
Memory consumption issue:
When there are many connections which does not exchange data frequently,
the old Netty 4 API spent a lot more memory than 3 because it always
allocates per-handler buffer for each connection unless otherwise
explicitly stated by a user. In a usual real world load, a client
doesn't always send requests without pausing, so the idea of having a
buffer whose life cycle if bound to the life cycle of a connection
didn't work as expected.
Memory footprint issue:
The old Netty 4 API decreased overall memory footprint by a great deal
in many cases. It was mainly because the old Netty 4 API did not
allocate a new buffer and event object for each read. Instead, it
created a new buffer for each handler in a pipeline. This works pretty
well as long as the number of handlers in a pipeline is only a few.
However, for a highly modular application with many handlers which
handles connections which lasts for relatively short period, it actually
makes the memory footprint issue much worse.
Changes:
All in all, this is about retaining all the good changes we made in 4 so
far such as better thread model and going back to the way how we dealt
with message events in 3.
To fix the memory consumption/footprint issue mentioned above, we made a
hard decision to break the backward compatibility again with the
following changes:
- Remove MessageBuf
- Merge Buf into ByteBuf
- Merge ChannelInboundByte/MessageHandler and ChannelStateHandler into ChannelInboundHandler
- Similar changes were made to the adapter classes
- Merge ChannelOutboundByte/MessageHandler and ChannelOperationHandler into ChannelOutboundHandler
- Similar changes were made to the adapter classes
- Introduce MessageList which is similar to `MessageEvent` in Netty 3
- Replace inboundBufferUpdated(ctx) with messageReceived(ctx, MessageList)
- Replace flush(ctx, promise) with write(ctx, MessageList, promise)
- Remove ByteToByteEncoder/Decoder/Codec
- Replaced by MessageToByteEncoder<ByteBuf>, ByteToMessageDecoder<ByteBuf>, and ByteMessageCodec<ByteBuf>
- Merge EmbeddedByteChannel and EmbeddedMessageChannel into EmbeddedChannel
- Add SimpleChannelInboundHandler which is sometimes more useful than
ChannelInboundHandlerAdapter
- Bring back Channel.isWritable() from Netty 3
- Add ChannelInboundHandler.channelWritabilityChanges() event
- Add RecvByteBufAllocator configuration property
- Similar to ReceiveBufferSizePredictor in Netty 3
- Some existing configuration properties such as
DatagramChannelConfig.receivePacketSize is gone now.
- Remove suspend/resumeIntermediaryDeallocation() in ByteBuf
This change would have been impossible without @normanmaurer's help. He
fixed, ported, and improved many parts of the changes.
2013-05-28 13:40:19 +02:00
|
|
|
return ByteBufUtil.compare(this, buffer);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "Swapped(" + buf.toString() + ')';
|
|
|
|
}
|
|
|
|
}
|