Commit Graph

240 Commits

Author SHA1 Message Date
Trustin Lee
aa69d628f1 Add ByteToMessageCodec.isEncodable() 2013-01-09 14:26:15 +09:00
Trustin Lee
dd6b7969b7 Give a handler more control over how its buffers' read bytes are discarded.
This pull request adds two new handler methods: discardInboundReadBytes(ctx) and discardOutboundReadBytes(ctx) to ChannelInboundByteHandler and ChannelOutboundByteHandler respectively. They are called between every inboundBufferUpdated() and flush() respectively. Their default implementation is to call discardSomeReadBytes() on their buffers and a user can override this behavior easily. For example, ReplayingDecoder.discardInboundReadBytes() looks like the following:

    @Override
    public void discardInboundReadBytes(ChannelHandlerContext ctx) throws Exception {
        ByteBuf in = ctx.inboundByteBuffer();
        final int oldReaderIndex = in.readerIndex();
        super.discardInboundReadBytes(ctx);
        final int newReaderIndex = in.readerIndex();
        checkpoint -= oldReaderIndex - newReaderIndex;
    }

If a handler, which has its own buffer index variable, extends ReplayingDecoder or ByteToMessageDecoder, the handler can also override discardInboundReadBytes() and adjust its index variable accordingly.
2013-01-09 13:34:09 +09:00
kxbmap
cf2fbf7883 Fix a link in ZlibWrapper 2013-01-05 21:28:03 +01:00
Norman Maurer
5526153459 [#882] Add a PartialFlushException which will allow to notify the user that the flush/write was only partial succesful 2013-01-05 20:30:48 +01:00
Norman Maurer
ccb5409f58 [#884] Split SCTP transport into extra module 2013-01-03 22:19:06 +01:00
Norman Maurer
37a3f2e3b8 [#887] [#866] [#883] Add unified interface for Message oriented protocols and also use direct buffers for them 2013-01-03 18:15:53 +01:00
Norman Maurer
4e77bacdf7 [#873] [#868] Split ChannelFuture into ChannelFuture and ChannelPromise 2012-12-31 23:27:16 +09:00
Trustin Lee
0909878581 Read only when requested (read-on-demand)
This pull request introduces a new operation called read() that replaces the existing inbound traffic control method. EventLoop now performs socket reads only when the read() operation has been issued. Once the requested read() operation is actually performed, EventLoop triggers an inboundBufferSuspended event that tells the handlers that the requested read() operation has been performed and the inbound traffic has been suspended again. A handler can decide to continue reading or not.

Unlike other outbound operations, read() does not use ChannelFuture at all to avoid GC cost. If there's a good reason to create a new future per read at the GC cost, I'll change this.

This pull request consequently removes the readable property in ChannelHandlerContext, which means how the traffic control works changed significantly.

This pull request also adds a new configuration property ChannelOption.AUTO_READ whose default value is true. If true, Netty will call ctx.read() for you. If you need a close control over when read() is called, you can set it to false.

Another interesting fact is that non-terminal handlers do not really need to call read() at all. Only the last inbound handler will have to call it, and that's just enough. Actually, you don't even need to call it at the last handler in most cases because of the ChannelOption.AUTO_READ mentioned above.

There's no serious backward compatibility issue. If the compiler complains your handler does not implement the read() method, add the following:

public void read(ChannelHandlerContext ctx) throws Exception {
    ctx.read();
}

Note that this pull request certainly makes bounded inbound buffer support very easy, but itself does not add the bounded inbound buffer support.
2012-12-31 23:26:00 +09:00
Norman Maurer
64351ad7d6 [#861] Let SctpMessageCompletionHandler fire inboundMessageBufferUpdated() only if needed 2012-12-27 23:08:54 +01:00
Norman Maurer
a20aba87ab Remove get prefix from Sctp methods to be more inline with the rest 2012-12-27 22:53:42 +01:00
Norman Maurer
852f546b5b [#846] Tighten up visibility 2012-12-25 18:54:55 +01:00
Norman Maurer
fc4b205bc4 More javadocs 2012-12-22 15:53:01 +01:00
Norman Maurer
ff3dcffd49 Almost finish javadocs for codec module 2012-12-21 22:41:18 +01:00
Norman Maurer
b814033323 [#847] Let CompressionException extend CodecException 2012-12-21 22:36:51 +01:00
Norman Maurer
5b44fe6e65 More javadoc fixes 2012-12-21 22:32:16 +01:00
Norman Maurer
8a7bc2c606 Add a lot of javadocs to make usage more clear 2012-12-21 22:22:40 +01:00
Trustin Lee
e353540d47 Move snappy codec to netty-codec 2012-12-19 18:12:18 +09:00
Trustin Lee
def12a171c Rename ChannelBuf to Buf and ChannelBufType to BufType
- Fixes #825
2012-12-17 17:43:45 +09:00
Trustin Lee
03e68482bb Remove ChannelBuf/ByteBuf.Unsafe
- Fixes #826
Unsafe.isFreed(), free(), suspend/resumeIntermediaryAllocations() are not that dangerous. internalNioBuffer() and internalNioBuffers() are dangerous but it seems like nobody is using it even inside Netty. Removing those two methods also removes the necessity to keep Unsafe interface at all.
2012-12-17 17:41:21 +09:00
Trustin Lee
1f72e53af3 Remove redundant copyright headers added by IntelliJ 2012-12-14 12:23:24 +09:00
Trustin Lee
5a4a59406b Merge ByteBuf.hasNioBuffer() and hasNioBuffers()
- Fixes #797
2012-12-14 12:20:33 +09:00
Trustin Lee
8e1a6c6cf5 Add ByteBuf.maxWritableBytes()
- Fixes #806
2012-12-14 11:49:01 +09:00
Trustin Lee
ad10518fca Fix the incorrect snapshot version number 2012-12-13 22:49:31 +09:00
Norman Maurer
bf8345999c Fix release of buffers in ByteToMessageCodec and MessageToMessageCodec 2012-12-08 12:59:32 +01:00
Shawn Silverman
8be43903e1 Added more Javadocs to the 'replace' methods, see Netty issue 756. 2012-12-07 06:31:21 +01:00
Norman Maurer
038bcfc4ff [#792] Implement freeInboundBuffer(...) and freeOutboundBuffer(...) methods in ByteToByteCodec 2012-12-06 20:57:08 +01:00
Trustin Lee
51e6519b67 Replace UnsafeByteBuf with ByteBuf.unsafe() again
* UnsafeByteBuf is gone. I added ByteBuf.unsafe() back.
* To avoid extra instantiation, all ByteBuf implementations implement the ByteBuf.Unsafe interface.
* To hide this implementation detail, all ByteBuf implementations are package-private.
* AbstractByteBuf and SwappedByteBuf are public and they do not implement ByteBuf.Unsafe because they don't need to.
* unwrap() is not an unsafe operation anymore.
* ChannelBuf also has unsafe() and Unsafe. ByteBuf.Unsafe extends ChannelBuf.unsafe(). ChannelBuf.unsafe() provides free() operation so that a user does not need to down-cast the buffer in freeInbound/OutboundBuffer().
2012-12-05 19:28:56 +09:00
Norman Maurer
85c570505b [maven-release-plugin] prepare for next development iteration 2012-12-03 20:34:05 +01:00
Norman Maurer
17d77ed160 [maven-release-plugin] prepare release netty-4.0.0.Alpha8 2012-12-03 20:33:49 +01:00
Trustin Lee
33c0c89fef Remove unnecessary empty lines 2012-12-03 19:58:13 +09:00
Trustin Lee
5f9090a7f0 Fix invalid memory access in AIO writes
To perform writes in AioSocketChannel, we get a ByteBuffer view of the
outbound buffer and specify it as a parameter when we call
AsynchronousSocketChannel.write().

In most cases, the write() operation is finished immediately.  However,
sometimes, it is scheduled for later execution.  In such a case, there's
a chance for a user's handler to append more data to the outbound
buffer.

When more data is appended to the outbound buffer, the outbound buffer
can expand its capacity by itself.  Changing the capacity of a buffer is
basically made of the following steps:

1. Allocate a larger new internal memory region.
2. Copy the current content of the buffer to the new memory region.
3. Rewire the buffer so that it refers to the new region.
4. Deallocate the old memory region.

Because the old memory region is deallocated at the step 4, the write
operation scheduled later will access the deallocated region, leading
all sort of data corruption or even segfaults.

To prevent this situation, I added suspendIntermediaryDeallocations()
and resumeIntermediaryDeallocations() to UnsafeByteBuf.

AioSocketChannel.doFlushByteBuf() now calls suspendIntermediaryDealloc()
to defer the deallocation of the old memory regions until the completion
handler is notified.
2012-12-02 21:50:33 +09:00
Trustin Lee
bfe2a96505 Fix AssertionError from AsyncSocketChannel.beginRead()
An AssertionError is triggered by a ByteBuf when beginRead() attempts to
access the buffer which has been freed already.  This commit ensures the
buffer is not freed before performing an I/O operation.

To determine if the buffer has been freed, UnsafeByteBuf.isFreed() has
been added.
2012-12-02 20:17:53 +09:00
Trustin Lee
00c4b944e4 Fix more inspector warnings introduced by recent mergences 2012-12-01 00:10:42 +09:00
Trustin Lee
6208c62888 Fix inspector warnings introduced by recent mergences 2012-11-30 23:01:57 +09:00
Trustin Lee
089d022e03 Remove redundant exception message 2012-11-26 15:34:09 +09:00
Trustin Lee
40373526ce Remove unexpected bad text
Doh!
2012-11-26 14:41:12 +09:00
Trustin Lee
5b68f00382 Make CompatibleMarshallingDecoder discard the inbound buffer once TooLongFrameException is raised
(See #768)

Once too long object is received, CompatibleMarshallingDecoder has to
discard all input from now on, just like MarshallingDecoder does.
Otherwise, the decoder will raise more exceptions because the decoder
has no idea anymore where the object starts.

Before this fix, SerialThreadLocalCompatibleMarshallingDecoderTest
logged many additional exceptions raised by the decoder after test is
finished.
2012-11-26 14:40:18 +09:00
Norman Maurer
d7d8503f5c Add a line-based frame decoder with good performance.
Using DelimiterBasedFrameDecoder with Delimiters.lineDelimiter() has
quadratic performance in the size of the input buffer.  Needless to
say, the performance degrades pretty quickly as the size of the buffer
increases.  Larger MTUs or loopback connections can make it so bad that
it appears that the code is "busy waiting", when in fact it's spending
almost 100% of the CPU time in DelimiterBasedFrameDecoder.indexOf().

Add a new LineBasedFrameDecoder that decodes line-delimited frames
in O(n) instead of DelimiterBasedFrameDecoder's O(n^2) implementation.
In OpenTSDB's telnet-style protocol decoder this resulted in throughput
increases of an order of magnitude.

Change DelimiterBasedFrameDecoder to automatically detect when the
frames are delimited by line endings, and automatically switch to
using LineBasedFrameDecoder under the hood.  This means that all Netty
applications out there that using the combo DelimiterBasedFrameDecoder
with Delimiters.lineDelimiter() will automatically benefit from the
better performance of LineBasedFrameDecoder, without requiring a code
change.
2012-11-25 13:36:55 +01:00
Trustin Lee
81e2db10fa ByteBufAllocator API w/ ByteBuf perf improvements
This commit introduces a new API for ByteBuf allocation which fixes
issue #643 along with refactoring of ByteBuf for simplicity and better
performance. (see #62)

A user can configure the ByteBufAllocator of a Channel via
ChannelOption.ALLOCATOR or ChannelConfig.get/setAllocator().  The
default allocator is currently UnpooledByteBufAllocator.HEAP_BY_DEFAULT.

To allocate a buffer, do not use Unpooled anymore. do the following:

  ctx.alloc().buffer(...); // allocator chooses the buffer type.
  ctx.alloc().heapBuffer(...);
  ctx.alloc().directBuffer(...);

To deallocate a buffer, use the unsafe free() operation:

  ((UnsafeByteBuf) buf).free();

The following is the list of the relevant changes:

- Add ChannelInboundHandler.freeInboundBuffer() and
  ChannelOutboundHandler.freeOutboundBuffer() to let a user free the
  buffer he or she allocated. ChannelHandler adapter classes implement
  is already, so most users won't need to call free() by themselves.
  freeIn/OutboundBuffer() methods are invoked when a Channel is closed
  and deregistered.

- All ByteBuf by contract must implement UnsafeByteBuf. To access an
  unsafe operation: ((UnsafeByteBuf) buf).internalNioBuffer()

- Replace WrappedByteBuf and ByteBuf.Unsafe with UnsafeByteBuf to
  simplify overall class hierarchy and to avoid unnecesary instantiation
  of Unsafe instances on an unsafe operation.

- Remove buffer reference counting which is confusing

- Instantiate SwappedByteBuf lazily to avoid instantiation cost

- Rename ChannelFutureFactory to ChannelPropertyAccess and move common
  methods between Channel and ChannelHandlerContext there. Also made it
  package-private to hide it from a user.

- Remove unused unsafe operations such as newBuffer()

- Add DetectionUtil.canFreeDirectBuffer() so that an allocator decides
  which buffer type to use safely
2012-11-22 15:10:59 +09:00
dantran
4107b08f29 Only generate OSGi manifest only at all-in-on sub module to reduce the complexity to the build 2012-11-19 06:27:18 +01:00
dantran
105f952f5d Clean up maven-bungle-plugin warnings 2012-11-12 11:42:42 +01:00
dantran
e236f5b77d [#154] [#727] Use maven-plugin-plugin to generate OSGi manifest 2012-11-12 09:15:36 +01:00
Trustin Lee
9ac522382a Fix visibility warnings from the inspector. 2012-11-12 14:03:43 +09:00
Trustin Lee
a05064d3eb Fix more inspection warnings + compilation errors 2012-11-12 13:25:00 +09:00
Trustin Lee
6f2840193a Fix inspection warnings related with JUnit usage 2012-11-12 12:45:06 +09:00
Trustin Lee
aedf8790c3 Fix various Javadoc issues / Do not use argN parameter names 2012-11-12 12:26:19 +09:00
Trustin Lee
ea4a0e3535 Prefer {@code ...} to <code>...</code> / Fix deprecation warnings 2012-11-12 11:51:23 +09:00
Trustin Lee
aa7cd691df Remove redundant 'else' branches. 2012-11-12 09:31:40 +09:00
Trustin Lee
b4f796c5e3 Use 'x' over "x" wherever possible / String.equals("") -> isEmpty() 2012-11-10 08:03:52 +09:00
Trustin Lee
0d0eb0abfb Remove unused imports 2012-11-10 07:05:18 +09:00
Trustin Lee
a9cfde97f0 Add missing final modifiers 2012-11-10 02:19:11 +09:00
Trustin Lee
58ba0de659 Remove unnecessarily qualified static access 2012-11-10 01:32:21 +09:00
Trustin Lee
957154c005 Remove redundant no-arg constructors 2012-11-10 01:08:18 +09:00
Norman Maurer
313f777491 [maven-release-plugin] prepare for next development iteration 2012-11-05 23:08:39 +01:00
Norman Maurer
57da8222a4 [maven-release-plugin] prepare release netty-4.0.0.Alpha7 2012-11-05 23:08:28 +01:00
Norman Maurer
87cc67306f [maven-release-plugin] prepare for next development iteration 2012-10-28 18:41:25 +01:00
Norman Maurer
7315490fca [maven-release-plugin] prepare release netty-4.0.0.Alpha6 2012-10-28 18:41:17 +01:00
Norman Maurer
afc687436a Revert "[maven-release-plugin] prepare release netty-4.0.0.Alpha6"
This reverts commit 95de4db0f1.
2012-10-28 18:36:15 +01:00
Norman Maurer
16eb4ec713 Revert "[maven-release-plugin] prepare for next development iteration"
This reverts commit e3e0776c20.
2012-10-28 18:35:47 +01:00
Norman Maurer
e3e0776c20 [maven-release-plugin] prepare for next development iteration 2012-10-28 13:06:07 +01:00
Norman Maurer
95de4db0f1 [maven-release-plugin] prepare release netty-4.0.0.Alpha6 2012-10-28 13:05:59 +01:00
Norman Maurer
985fa97c9b Check if message is supported before cast. See #678 2012-10-24 07:03:02 +02:00
Norman Maurer
cbcabaf29b Add support for method chaining to ByteBuf 2012-10-18 08:57:23 +02:00
Trustin Lee
b76c39318d Make NoSuchBufferException message more useful 2012-10-16 14:23:02 -07:00
Norman Maurer
6143626427 Cleanup of sctp code based on comments in #633 2012-10-12 07:45:00 +02:00
Jestan Nirojan
6904b62c2f Resolved conflicts in SctpData/SctpMessage refactoring 2012-09-29 02:01:00 +08:00
Jestan Nirojan
64ebece730 Added SCTP Codec 2012-09-29 01:42:21 +08:00
Trustin Lee
820af50b63 [maven-release-plugin] prepare for next development iteration 2012-09-28 17:57:40 +09:00
Trustin Lee
595e1067c7 [maven-release-plugin] prepare release netty-4.0.0.Alpha5 2012-09-28 17:57:04 +09:00
Trustin Lee
94838ee274 [#441] Provide a better way to handle decoder failures
* Rename isPartial() to isPartialFailure()
* Add isCompleteFailure() and isFailure()
2012-09-28 15:46:17 +09:00
Trustin Lee
bf808b3486 Rename DecodeResult to DecoderResult 2012-09-28 15:19:08 +09:00
Trustin Lee
adebda1560 [#441] Provide a better way to handle decoder failures
* Add DecodeResult that represents the result of decoding a message
* Add HttpObject which HttpMessage and HttpChunk extend.
** HttpObject has a property 'decodeResult'
2012-09-28 13:48:17 +09:00
Trustin Lee
bd8ee64366 Pull #625 from @CruzBishop selectively 2012-09-27 19:04:35 +09:00
Trustin Lee
a156f67804 [#624] Add varargs constructor to MessageToByteEncoder, MessageToMessage(Encoder|Decoder|Codec) to implement default isEncodable/isDecodable()
.. and modify all their subtypes to take advantage of this improvement.
2012-09-23 17:01:31 +09:00
Jestan Nirojan
b268f0b333 Added SCTP Codec Handlers + minor refactoring 2012-09-23 14:12:32 +08:00
Norman Maurer
0c157a94cb Only call ByteToMessageDecoder.decode(..) if the inbound buffer is readable. See #607 2012-09-15 20:12:39 +02:00
Norman Maurer
516351b82c Add a basic unit test that I wrote while porting niosmtp to netty 4 2012-09-15 19:14:59 +02:00
norman
3295145e88 [maven-release-plugin] prepare for next development iteration 2012-09-13 10:40:52 +02:00
norman
42685759de [maven-release-plugin] prepare release netty-4.0.0.Alpha4 2012-09-13 10:40:44 +02:00
Trustin Lee
7a77903af0 Remove unused local variable 2012-09-01 17:01:55 +09:00
Trustin Lee
f2538a996d [maven-release-plugin] prepare for next development iteration 2012-08-30 16:47:52 +09:00
Trustin Lee
628c5598b3 [maven-release-plugin] prepare release netty-4.0.0.Alpha3 2012-08-30 16:46:58 +09:00
Trustin Lee
73720c422d [maven-release-plugin] prepare for next development iteration 2012-08-21 15:41:04 +09:00
Trustin Lee
68bef8cb99 [maven-release-plugin] prepare release netty-4.0.0.Alpha2 2012-08-21 15:40:45 +09:00
Trustin Lee
0a43350c66 [maven-release-plugin] prepare for next development iteration 2012-08-21 14:41:45 +09:00
Trustin Lee
56211fee59 [maven-release-plugin] prepare release netty-4.0.0.Alpha2 2012-08-21 14:39:59 +09:00
Trustin Lee
a0e34fd93a [maven-release-plugin] prepare for next development iteration 2012-08-21 14:13:38 +09:00
Trustin Lee
72ccf65093 [maven-release-plugin] prepare release netty-4.0.0.Alpha2 2012-08-21 14:13:17 +09:00
Trustin Lee
b25996d024 [#486] Make NoSuchBufferException give more useful message.
- Remove confusing exception messages
- Do not use default exception messages wherever possible
2012-08-20 21:03:23 +09:00
Trustin Lee
df0aee22cb [#540] Add a variant of ByteBuf.ensureWritableBytes() which does not throw an exception 2012-08-20 12:52:38 +09:00
Trustin Lee
0b11fb2ead [#531] Move io.netty.util.Signal to io.netty.util.internal 2012-08-18 18:50:54 +09:00
John Fallows
06fd869711 Add support for AIO scattering reads and gathering writes.
o Add ByteBuf.hasNioBuffers() method
 o Promote CompositeByteBuf.nioBuffers() methods to ByteBuf
 o Use ByteBuf.nioBuffers() methods from AioSocketChannel
2012-08-12 17:29:07 -07:00
Trustin Lee
a2aadef4da Add ByteBuf.Unsafe.discardSomeReadBytes() to reduce discardReadBytes() 2012-08-08 17:34:00 +09:00
Trustin Lee
5a613f379e Make ByteBuf dynamic / Introduce an interface for composite buffers
- Replace ByteBufferBackedByteBuf with DirectByteBuf
- Make DirectByteBuf and HeapByteBuf dynamic
- Remove DynamicByteBuf
- Replace Unpooled.dynamicBuffer() with Unpooled.buffer() and
  directBuffer()
- Remove ByteBufFactory (will be replaced with ByteBufPool later)
- Add ByteBuf.Unsafe (might change in the future)
2012-07-19 20:25:47 +09:00
norman
3447e87112 Pass the right ByteBuf to the decode(..) method. See #459 2012-07-18 09:26:11 +02:00
Trustin Lee
00106b367c Use lookupAny() instead of lookup()
- Should be OK because Netty 4.0 requires Java 6
2012-07-13 15:18:57 +09:00
Trustin Lee
6c2eba79d7 [#452] CompactObjectInputStream fails to resolve interfaces 2012-07-13 13:02:09 +09:00
Trustin Lee
d801459cb8 [maven-release-plugin] prepare for next development iteration 2012-07-10 23:11:33 +09:00
Trustin Lee
527f2f6c6e [maven-release-plugin] prepare release netty-4.0.0.Alpha1 2012-07-10 23:10:48 +09:00
Trustin Lee
6b5e3c5def Port #446 (Fix for #444 - HTTP compression error) 2012-07-10 22:13:42 +09:00