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:
|
|
|
|
*
|
2020-10-23 14:44:18 +02:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2012-06-11 13:24:44 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-09-17 16:28:14 +02:00
|
|
|
package io.net5.buffer;
|
2012-06-11 13:24:44 +02:00
|
|
|
|
2019-02-04 10:32:25 +01:00
|
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
|
2021-09-17 16:28:14 +02:00
|
|
|
import io.net5.util.ByteProcessor;
|
2015-04-01 01:23:52 +02:00
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.ByteOrder;
|
2016-02-05 04:02:40 +01:00
|
|
|
import java.nio.channels.FileChannel;
|
2012-06-11 13:24:44 +02:00
|
|
|
import java.nio.channels.GatheringByteChannel;
|
|
|
|
import java.nio.channels.ScatteringByteChannel;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
2013-07-14 16:02:03 +02:00
|
|
|
/**
|
|
|
|
* Wrapper which swap the {@link ByteOrder} of a {@link ByteBuf}.
|
2015-11-16 22:20:16 +01:00
|
|
|
*
|
|
|
|
* @deprecated use the Little Endian accessors, e.g. {@code getShortLE}, {@code getIntLE}
|
|
|
|
* instead.
|
2013-07-14 16:02:03 +02:00
|
|
|
*/
|
2016-04-14 21:11:07 +02:00
|
|
|
@Deprecated
|
2014-06-04 07:04:19 +02:00
|
|
|
public 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) {
|
2019-02-04 10:32:25 +01:00
|
|
|
requireNonNull(buf, "buf");
|
2012-06-11 13:24:44 +02:00
|
|
|
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) {
|
2019-02-04 10:32:25 +01:00
|
|
|
requireNonNull(endianness, "endianness");
|
2012-06-11 13:24:44 +02:00
|
|
|
if (endianness == order) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf unwrap() {
|
2016-11-24 14:01:13 +01:00
|
|
|
return buf;
|
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
|
|
|
}
|
|
|
|
|
2016-04-13 11:21:17 +02:00
|
|
|
@Override
|
|
|
|
public boolean isReadOnly() {
|
|
|
|
return buf.isReadOnly();
|
|
|
|
}
|
|
|
|
|
2016-04-13 15:25:15 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf asReadOnly() {
|
|
|
|
return Unpooled.unmodifiableBuffer(this);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-05-22 20:11:24 +02:00
|
|
|
@Override
|
|
|
|
public int maxFastWritableBytes() {
|
|
|
|
return buf.maxFastWritableBytes();
|
|
|
|
}
|
|
|
|
|
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 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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public short getShortLE(int index) {
|
|
|
|
return buf.getShort(index);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public int getUnsignedShort(int index) {
|
|
|
|
return getShort(index) & 0xFFFF;
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int getUnsignedShortLE(int index) {
|
|
|
|
return getShortLE(index) & 0xFFFF;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int getMediumLE(int index) {
|
|
|
|
return buf.getMedium(index);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public int getUnsignedMedium(int index) {
|
|
|
|
return getMedium(index) & 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int getUnsignedMediumLE(int index) {
|
|
|
|
return getMediumLE(index) & 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int getIntLE(int index) {
|
|
|
|
return buf.getInt(index);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public long getUnsignedInt(int index) {
|
|
|
|
return getInt(index) & 0xFFFFFFFFL;
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public long getUnsignedIntLE(int index) {
|
|
|
|
return getIntLE(index) & 0xFFFFFFFFL;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public long getLongLE(int index) {
|
|
|
|
return 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);
|
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int getBytes(int index, FileChannel out, long position, int length) throws IOException {
|
|
|
|
return buf.getBytes(index, out, position, length);
|
|
|
|
}
|
|
|
|
|
2016-04-11 11:47:35 +02:00
|
|
|
@Override
|
|
|
|
public CharSequence getCharSequence(int index, int length, Charset charset) {
|
|
|
|
return buf.getCharSequence(index, length, charset);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf setShortLE(int index, int value) {
|
|
|
|
buf.setShort(index, (short) value);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf setMediumLE(int index, int value) {
|
|
|
|
buf.setMedium(index, value);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf setIntLE(int index, int value) {
|
|
|
|
buf.setInt(index, value);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf setLongLE(int index, long value) {
|
|
|
|
buf.setLong(index, value);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int setBytes(int index, FileChannel in, long position, int length) throws IOException {
|
|
|
|
return buf.setBytes(index, in, position, length);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2016-04-11 11:47:35 +02:00
|
|
|
@Override
|
|
|
|
public int setCharSequence(int index, CharSequence sequence, Charset charset) {
|
|
|
|
return buf.setCharSequence(index, sequence, charset);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public short readShortLE() {
|
2020-10-29 10:35:47 +01:00
|
|
|
return buf.readShortLE();
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public int readUnsignedShort() {
|
|
|
|
return readShort() & 0xFFFF;
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int readUnsignedShortLE() {
|
|
|
|
return readShortLE() & 0xFFFF;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int readMediumLE() {
|
2020-10-29 10:35:47 +01:00
|
|
|
return buf.readMediumLE();
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public int readUnsignedMedium() {
|
|
|
|
return readMedium() & 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int readUnsignedMediumLE() {
|
|
|
|
return readMediumLE() & 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public int readIntLE() {
|
2020-10-29 10:35:47 +01:00
|
|
|
return buf.readIntLE();
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public long readUnsignedInt() {
|
|
|
|
return readInt() & 0xFFFFFFFFL;
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public long readUnsignedIntLE() {
|
|
|
|
return readIntLE() & 0xFFFFFFFFL;
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public long readLongLE() {
|
2020-10-29 10:35:47 +01:00
|
|
|
return buf.readLongLE();
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-08-06 12:22:22 +02:00
|
|
|
return buf.readSlice(length).order(order);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 10:31:48 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf readRetainedSlice(int length) {
|
|
|
|
return buf.readRetainedSlice(length).order(order);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int readBytes(FileChannel out, long position, int length) throws IOException {
|
|
|
|
return buf.readBytes(out, position, length);
|
|
|
|
}
|
|
|
|
|
2016-04-11 11:47:35 +02:00
|
|
|
@Override
|
|
|
|
public CharSequence readCharSequence(int length, Charset charset) {
|
|
|
|
return buf.readCharSequence(length, charset);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf writeShortLE(int value) {
|
2020-10-29 10:35:47 +01:00
|
|
|
buf.writeShortLE((short) value);
|
2015-11-16 22:20:16 +01: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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf writeMediumLE(int value) {
|
2020-10-29 10:35:47 +01:00
|
|
|
buf.writeMediumLE(value);
|
2015-11-16 22:20:16 +01: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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf writeIntLE(int value) {
|
2020-10-29 10:35:47 +01:00
|
|
|
buf.writeIntLE(value);
|
2015-11-16 22:20:16 +01: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
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf writeLongLE(long value) {
|
2020-10-29 10:35:47 +01:00
|
|
|
buf.writeLongLE(value);
|
2015-11-16 22:20:16 +01: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);
|
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int writeBytes(FileChannel in, long position, int length) throws IOException {
|
|
|
|
return buf.writeBytes(in, position, length);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2016-04-11 11:47:35 +02:00
|
|
|
@Override
|
|
|
|
public int writeCharSequence(CharSequence sequence, Charset charset) {
|
|
|
|
return buf.writeCharSequence(sequence, charset);
|
|
|
|
}
|
|
|
|
|
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
|
2015-04-01 01:23:52 +02:00
|
|
|
public int forEachByte(ByteProcessor processor) {
|
2013-06-28 13:29:00 +02:00
|
|
|
return buf.forEachByte(processor);
|
2013-06-27 06:55:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-01 01:23:52 +02:00
|
|
|
public int forEachByte(int index, int length, ByteProcessor processor) {
|
2013-06-28 13:29:00 +02:00
|
|
|
return buf.forEachByte(index, length, processor);
|
2013-06-27 11:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-01 01:23:52 +02:00
|
|
|
public int forEachByteDesc(ByteProcessor processor) {
|
2013-06-28 13:29:00 +02:00
|
|
|
return buf.forEachByteDesc(processor);
|
2013-06-27 11:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-01 01:23:52 +02:00
|
|
|
public int forEachByteDesc(int index, int length, ByteProcessor processor) {
|
2013-06-28 13:29:00 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-04-14 10:31:48 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf retainedSlice() {
|
2016-07-26 21:50:56 +02:00
|
|
|
return buf.retainedSlice().order(order);
|
2016-04-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf slice(int index, int length) {
|
|
|
|
return buf.slice(index, length).order(order);
|
|
|
|
}
|
|
|
|
|
2016-04-14 10:31:48 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf retainedSlice(int index, int length) {
|
2016-07-26 21:50:56 +02:00
|
|
|
return buf.retainedSlice(index, length).order(order);
|
2016-04-14 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf duplicate() {
|
|
|
|
return buf.duplicate().order(order);
|
|
|
|
}
|
|
|
|
|
2016-04-14 10:31:48 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf retainedDuplicate() {
|
|
|
|
return buf.retainedDuplicate().order(order);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@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) {
|
2013-08-30 09:51:12 +02:00
|
|
|
return nioBuffer(index, length);
|
2013-06-13 05:40:26 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-11-06 12:06:25 +01:00
|
|
|
@Override
|
|
|
|
public boolean isContiguous() {
|
|
|
|
return buf.isContiguous();
|
|
|
|
}
|
|
|
|
|
2013-03-06 10:22:16 +01:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
2019-02-28 20:40:42 +01:00
|
|
|
@Override
|
|
|
|
final boolean isAccessible() {
|
|
|
|
return buf.isAccessible();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-28 12:00:28 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf touch() {
|
|
|
|
buf.touch();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-01-29 03:44:59 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf touch(Object hint) {
|
|
|
|
buf.touch(hint);
|
|
|
|
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 (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() {
|
2014-01-28 12:00:28 +01:00
|
|
|
return "Swapped(" + buf + ')';
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
}
|