Commit Graph

762 Commits

Author SHA1 Message Date
Trustin Lee
a03bc6ea1d Fix a bug where freeInbound/OutboundBuffer() is not called when a handler is removed from a pipeline. 2013-01-14 20:54:12 +09:00
Norman Maurer
eb91a6d4e6 [#924] [#914] Fix high CPU usage which was caused because the OP_CONNECT flag was not cleared after the connect was complete 2013-01-11 19:42:21 +01:00
Trustin Lee
64ae8b6a37 Replace and merge DetectionUtil and DirectByteBufUtil into PlatformDependent and PlatformDependent0
PlatformDependent delegates the operations requires sun.misc.* to PlatformDependent0 to avoid runtime errors due to missing sun.misc.* classes.
2013-01-11 14:03:27 +09:00
Trustin Lee
8975406b86 Ensure the outbound buffer is not freed on write completion
- Fixes #919
2013-01-10 21:05:51 +09:00
Trustin Lee
665d022e82 Use a heap buffer from the allocator because it doesn't seem to cause OOME anymore 2013-01-10 16:23:40 +09:00
Trustin Lee
eb337ff5a7 Fix various inspection warnings 2013-01-10 15:23:58 +09:00
Trustin Lee
3c9d912355 Use InetSocketAddress wherever possible / Tighten the return type of Channel.parent() 2013-01-10 14:17:54 +09:00
Trustin Lee
793a571465 Fix a runtime type cast exception when calling RxtxChannel.local/remoteAddress() 2013-01-10 14:01:17 +09:00
Trustin Lee
137f29ba65 Do not read if a channel is inactive 2013-01-09 21:28:31 +09:00
Trustin Lee
46e364e7b7 Remove unnecessary parameters 2013-01-09 20:36:16 +09:00
Trustin Lee
b9352ded13 Fix a bug where prev/next context is not always set 2013-01-09 20:34:22 +09:00
Trustin Lee
8586d43b23 Fix DefaultChannelPipeline.toString() / Remove unnecessary conditions 2013-01-09 19:16:09 +09:00
Trustin Lee
b6fcf3acc4 Simplify DefaultChannelPipeline 2013-01-09 19:13:43 +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
Trustin Lee
7277536ca6 Remove unnecessary finally block 2013-01-09 13:30:25 +09:00
Norman Maurer
26595471fb Call Freeable.free() if a Freeable message reaches the end of the ChannelPipeline to guard against resource leakage 2013-01-07 12:34:18 +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
Courtney Robinson
3a52cc410a Add some of the metrics mentioned in #718
use single static initialization of available metrics monitor registries

* This changes the original implementation to work in a similar way to
how slf4j selects and loads an implementation.
* Uses a single static instance so intialization is done only once.
* Doesn't throw IllegalStateException if multiple implementations are
found on the classpath. It instead selects and uses the first
implementation returned by iterator()
* Class left as an iterable to keep the API the same

add yammer metrics to examples to allow them to publish metrics

publish the number of threads used in an EventLoopGroup see issue #718

* seems like the better place to put this because it sets the default
thread count if the MultithreadEventLoopGroup uses super(0,...)
* It also happens to be the common parent class amongst all the
MultiThreadedEventLoopGroup implementations
* Count is reported for
io.netty.channel.{*,.local,.socket.aio,.socket.nio}

fix cosmetic issues pointed out in pull request and updated notice.txt

see https://github.com/netty/netty/pull/780

count # of channels registered in single threaded event loop

measure how many times Selector.select return before SELECT_TIME
2013-01-04 11:27:49 +01:00
Norman Maurer
2f6e17f681 Make sure we catch UnsupportedOperationException for derived buffers 2013-01-03 22:49:54 +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
Trustin Lee
0abfaf20e4 Revert 5161ca733c 2013-01-03 17:05:18 +09:00
Trustin Lee
923dde7a5f Do not auto-start read operation 2013-01-03 16:01:41 +09:00
Trustin Lee
103edc4467 Make ChannelConfig.setAutoRead() triggers Channel.read() if autoRead was previously false
- also rename JDK socket and channel variables so that they are less ambiguous
2013-01-01 16:49:21 +09:00
Norman Maurer
5161ca733c Move utility method to abstract base class and correctly handle expand of buffer also for OIO 2012-12-31 22:09:27 +01:00
Trustin Lee
89a16fe01e Fix a bug in NIO transport where inboundBufferSuspended() is triggered even if the channel is closed.
- No non-static wildcard import
2013-01-01 00:35:44 +09:00
Trustin Lee
93fd73fbbf Fix a bug in AioSocketChannel where inboundBufferSuspended() is triggered even if the channel is closed. 2013-01-01 00:27:30 +09:00
Norman Maurer
8cf9f52919 Add new ChanelFuureListener impl that mimic the old behavior of Netty 3 and so allow to also call fireException for outbound operations 2012-12-31 16:17:08 +01:00
Trustin Lee
1e9652b47a Fix a bug in AioSocketChannel where recursive doBeginRead() is allowed unexpectedly 2013-01-01 00:08:58 +09:00
Norman Maurer
e0a6dc0ac3 Remove ChannelFutureProgressListener 2012-12-31 23:27:37 +09: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
b49b3d9c56 [#879] Notify correct ChannelFuture for queued FileRegions 2012-12-31 11:35:25 +01:00
Norman Maurer
c80b1bb66e [#872] AbstractNioByteChannel and AbstractNioMessageChannel should be public 2012-12-30 12:48:32 +01:00
Norman Maurer
0fb0037eab Rename IpAddresses to NetUtil 2012-12-29 18:25:32 +01:00
Norman Maurer
5d13c7d27b Merge IPUtil and NetworkConstants into IpAddresses and also make naming of methods consistent 2012-12-29 18:17:33 +01:00
Norman Maurer
e2b240799c [#857] Check if the SelectionKey is valid before access readyOps() 2012-12-29 18:07:02 +01:00
Norman Maurer
88838413c7 Javadocs and cleanup intellij warnings 2012-12-27 23:02:13 +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
6db7250ed9 Javadocs added for SCTP stuff 2012-12-27 22:46:46 +01:00
Norman Maurer
5a4a52a817 [#857] Correctly handle CancelledKeyException 2012-12-27 22:24:07 +01:00
Norman Maurer
852f546b5b [#846] Tighten up visibility 2012-12-25 18:54:55 +01:00
Norman Maurer
a9fdb682be Add javadocs and some small cleanups 2012-12-23 20:58:49 +01:00
Norman Maurer
71b089cb3b Add javadocs and cleanup 2012-12-23 19:24:20 +01:00
Norman Maurer
ae859c2de9 Fix checkstyle 2012-12-23 19:24:05 +01:00
Norman Maurer
e0d42df77b ServerBootstrap needs to have a localAddress defined 2012-12-23 16:05:43 +01:00
Norman Maurer
6ef1729d06 Fix javadocs for ChannelPipeline 2012-12-23 15:54:30 +01:00
Norman Maurer
7d79587ade Make package private 2012-12-23 15:54:14 +01:00
Norman Maurer
e05b071b41 Javadocs update 2012-12-22 19:27:09 +01:00
Norman Maurer
fc4b205bc4 More javadocs 2012-12-22 15:53:01 +01:00
Trustin Lee
9098d069b0 Make FailedChannelFuture and SucceededChannelFuture final 2012-12-22 15:10:38 +09:00
Norman Maurer
b004066f37 Javadoc fixes and remove some uncessary casts + checks 2012-12-21 17:59:37 +01:00
Norman Maurer
a819d26f5c Remove ChannelHandlerLifeCycleException and just use ChannelPipelineException as replacement 2012-12-21 17:10:36 +01:00
Norman Maurer
ef555d268c Add more javadocs and replace some abstract methods with noops as we often implemented them as noops 2012-12-21 17:06:24 +01:00
Norman Maurer
3e31af68e4 More javadocs cleanup 2012-12-21 11:03:35 +01:00
Norman Maurer
e4ed551490 Move shared methods to the AbstractEmbeddedChannel class and add javadocs 2012-12-21 10:41:27 +01:00
Norman Maurer
42a77eda9b And again javadocs cleanup 2012-12-21 07:35:42 +01:00
Norman Maurer
62bf98af8c More javadoc fixes 2012-12-21 07:13:31 +01:00
Norman Maurer
7a9d9d6a88 Fix checkstyle 2012-12-20 19:11:17 +01:00
Norman Maurer
5d6d849acd Mark final, add javadocs, add checks 2012-12-20 16:13:26 +01:00
Norman Maurer
d2060ee3f1 Add more javadocs 2012-12-20 15:45:49 +01:00
Norman Maurer
43d13064d1 [#837] CombinedChannelHandler must pass sendFile(...) to the wrapped ChannelOutboundHandler 2012-12-20 12:25:13 +01:00
Norman Maurer
94dc09c33d Tighten up visibility as the user should use Channel.new*Future 2012-12-20 10:45:12 +01:00
Norman Maurer
35c01660da Merge branch 'master' of github.com:netty/netty 2012-12-19 09:27:18 +01:00
Norman Maurer
fdeff3855d Move ChannelInputShutdownEvent to socket package as this is where it belongs to. Also added some javadocs 2012-12-19 09:27:01 +01:00
Trustin Lee
0e017db89a Return the new buffer's capacity is same with the requested capacity
- Rename capacity variables to reqCapacity or normCapacity to distinguish if its the request capacity or the normalized capacity
- Do not reallocate on ByteBuf.capacity(int) if reallocation is unnecessary; just update the index range.
- Revert the workaround in DefaultChannelHandlerContext
2012-12-19 16:50:05 +09:00
Norman Maurer
b6e83dff4f Add javadocs and also some parameter checks in DefaultFileRegion 2012-12-19 08:24:32 +01:00
Jestan Nirojan
44142efe55 Fixed OioSctpChannel event loop issue #632 by using 3 different selectors 2012-12-19 06:54:06 +01:00
Trustin Lee
3fc3401c08 Remove bad Javadoc in SCTP classes. 2012-12-19 11:58:54 +09:00
Norman Maurer
f6735f8cc9 Add javadocs to AIO and also fix a few warnings 2012-12-18 15:27:52 +01:00
Norman Maurer
7b0ec599d6 Fix config 2012-12-18 11:38:38 +01:00
Norman Maurer
8d89e48177 Add javadocs in the oio package and also fix some intellij warnings 2012-12-18 11:24:25 +01:00
Norman Maurer
6d93c3fb25 more javadocs 2012-12-18 07:55:39 +01:00
Norman Maurer
b7b17209ea Next round of javadocs cleanup and fixes. Also limit the visibility of FailedChannelFuture 2012-12-18 07:23:42 +01:00
Trustin Lee
310a87a51d Fix #814 - Prevent IllegalBufferAccessException on write() and flush()
- Also fixed a incorrect port of SpdySessionHandler
  - Previously, it closed the connection too early when sending a GOAWAY frame
  - After this fix, SpdySessionHandlerTest now passes again without the previous fix
2012-12-18 04:53:37 +09:00
Norman Maurer
5a467b69bf DatagramPacket should be final 2012-12-17 20:37:10 +01:00
Trustin Lee
949435d105 Fix checkstyle 2012-12-18 03:08:01 +09:00
Trustin Lee
e59ac8e79b Do not call inbound event methods directly
- Fixes #831

This commit ensures the following events are never triggered as a direct
invocation if they are triggered via ChannelPipeline.fire*():

- channelInactive
- channelUnregistered
- exceptionCaught

This commit also fixes the following issues surfaced by this fix:

- Embedded channel implementations run scheduled tasks too early
- SpdySessionHandlerTest tries to generate inbound data even after the
  channel is closed.
- AioSocketChannel enters into an infinite loop on I/O error.
2012-12-18 03:04:26 +09:00
Norman Maurer
39250873ae Add some javadocs 2012-12-17 16:01:58 +01:00
Trustin Lee
8b82ff5ce0 Fix checkstyle 2012-12-17 18:28:31 +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
Norman Maurer
ba3c795fdf Adjust ChannelPipeline to support method-chaining in a consistent way 2012-12-14 17:06:31 +01:00
Norman Maurer
caa698f235 [#819] Allow for easy method-chaining in ChannelConfig and its sub-types
This commit also introduce a new interface which is called AioSocketChannelConfig to expose AIO only config options with the right visibility.
Also it change the ChannelConfig.setAllocator(..) to return the ChannelConfig to be more consistent with the other methods.
2012-12-14 16:59:23 +01:00
Norman Maurer
6eb7de04e7 Allow to access localAddress and remoteAddress even if the channel is not registered yet 2012-12-14 15:19:03 +01:00
Norman Maurer
42f6a27235 Allow modify the config even before the channel is registered to the eventLoop 2012-12-14 15:10:10 +01:00
Trustin Lee
d8c569a71b Make ChannelFutureNotifier accept multiple ChannelFutures 2012-12-14 20:09:40 +09:00
Trustin Lee
eb23c9d27c Add missing 'operation(args, future)' for 'operation(args)'
- Fixes #818
- Fix inspector warnings
2012-12-14 19:42:58 +09:00
Norman Maurer
96dc3f983f Refactor AIO Transport to allow to use Bootstrap without the ugly hack 2012-12-14 09:51:36 +01:00
Trustin Lee
02a6e85feb Add methods that add/remove multiple ChannelFutureListeners to ChannelFuture
- Fixes #811
2012-12-14 12:45:43 +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
9e973bbffc Port rebuildSelectors() from 3.6 to 4.0
- Fix #813
2012-12-14 11:43:04 +09:00
Trustin Lee
be6cc9c324 Fix inspection warnings 2012-12-14 11:23:30 +09:00
Trustin Lee
d1d9f131da Tell NioTask the cause of unregistration
- Add the 'cause' parameter to the channelUnregistered method
2012-12-14 11:18:03 +09:00
Norman Maurer
c4db51e85d Refactor AIO Transport to allow to use Bootstrap without the ugly hack 2012-12-13 19:54:39 +01:00
Trustin Lee
ad10518fca Fix the incorrect snapshot version number 2012-12-13 22:49:31 +09:00
Trustin Lee
b47fc77522 Add PooledByteBufAllocator + microbenchmark module
This pull request introduces the new default ByteBufAllocator implementation based on jemalloc, with a some differences:

* Minimum possible buffer capacity is 16 (jemalloc: 2)
* Uses binary heap with random branching (jemalloc: red-black tree)
* No thread-local cache yet (jemalloc has thread-local cache)
* Default page size is 8 KiB (jemalloc: 4 KiB)
* Default chunk size is 16 MiB (jemalloc: 2 MiB)
* Cannot allocate a buffer bigger than the chunk size (jemalloc: possible) because we don't have control over memory layout in Java. A user can work around this issue by creating a composite buffer, but it's not always a feasible option. Although 16 MiB is a pretty big default, a user's handler might need to deal with the bounded buffers when the user wants to deal with a large message.

Also, to ensure the new allocator performs good enough, I wrote a microbenchmark for it and made it a dedicated Maven module. It uses Google's Caliper framework to run and publish the test result (example)

Miscellaneous changes:

* Made some ByteBuf implementations public so that those who implements a new allocator can make use of them.
* Added ByteBufAllocator.compositeBuffer() and its variants.
* ByteBufAllocator.ioBuffer() creates a buffer with 0 capacity.
2012-12-13 22:35:06 +09:00
Norman Maurer
9d42acbc2a [#803] Make sure the right EventExecutor is used after re-register a Channel to another EventLoop 2012-12-13 10:38:44 +01:00
Norman Maurer
2903b91e66 [#798] Not call fireExceptionCaught(..) for outbound operations as the future will get notified anyway and so it is redundant.
Outbound operations are those which are part of the ChannelOutboundInvoker interface.
2012-12-10 20:12:59 +01:00
Norman Maurer
3e783e1b5e Fix bug in DefaultChannelHandlerContext where ByteBridge does not handle bounded buffers well 2012-12-10 16:47:24 +01:00
Trustin Lee
321b18d4d1 Fix test failures n LocalTransportThreadModelTest
testConcurrentMessageBufferAccess() assumes the outbound/inbound byte buffers are unbounded.  Because PooledByteBuf is bounded, the test did not pass.

The fix makes an assumption that ctx.flush() or fireInboundBufferUpdated() will make the next buffer consumed immediately, which is not the case in the real world.  Under network congestion, a user will see IndexOutOfBoundsException if the user's handler implementation writes boundlessly into inbound/outbound buffers.
2012-12-10 16:38:20 +01:00
Shawn Silverman
e5a8958ed6 Fixed some 120-character line checkstyle problems. 2012-12-07 06:31:21 +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
16b05def59 Fix possible NPE which accour if the inbound/outbound buffer was not lazy allocated yet 2012-12-06 19:36:53 +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
Trustin Lee
9c0b2ad75c Update netty-build to the latest version
From this commit, checkstyle considers an unnecessary empty line as a
violation.
2012-12-04 16:46:46 +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
Norman Maurer
f9225df0a9 Add back support for FileRegion. See #668 2012-12-03 12:08:17 +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
72e0acbe84 Use correct timeout in AioSocketChannel.beginRead() 2012-12-02 20:38:59 +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
95e8ec1db9 Handle the case where JDK notifies aync I/O handler immediately
After some debugging, I found that JDK AIO implementation often performs
I/O immediately from the caller thread if the caller thread is the I/O
thread, and notifies the completion handler also immediately.  This
commit handles such a case correctly during reads and writes.

Additionally, this commit also changes SingleThreadEventExecutor to let
it handle unexpected exceptions such as AssertionError in a robus
manner.
2012-12-02 20:03:35 +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
818a7b42a3 Fix all Xlint:unchecked warnings 2012-11-30 22:49:51 +09:00
Trustin Lee
c661c344ed Add proper toString() implementation for internal ChannelFactory impls 2012-11-26 17:15:14 +09:00
Trustin Lee
918666481e Ensure lazily instantiated outbound buffers are instantiated from the event loop 2012-11-26 17:14:21 +09:00
Trustin Lee
74749ec15d Implement Bootstrap.toString() and use it in the testsuite
By implementing Bootstrap.toString() and printing it for each test case helps us figure out which transport is causing a trouble.
2012-11-26 16:14:24 +09:00
Trustin Lee
dbbc6ad73f Reduce the chance of RejectedExecutionException
When a Netty application shuts down, a user often sees a REE
(RejectedExecutionException).

A REE is raised due to various reasons we don't have control over, such
as:

- A client connects to a server while the server is shutting down.

- An event is triggered for a closed Channel while its event loop is
  also shutting down.  Some of them are:
  - channelDeregistered (triggered after a channel is closed)
  - freeIn/OutboundBuffer (triggered after channelDeregistered)
  - userEventTriggered (triggered anytime)

To address this issue, a new method called confirmShutdown() has been
added to SingleThreadEventExecutor.  After a user calls shutdown(),
confirmShutdown() runs any remaining tasks in the task queue and ensures
no events are triggered for last 2 seconds.  If any task are added to
the task queue before 2 seconds passes, confirmShutdown() prevents the
event loop from terminating by returning false.

Now that SingleThreadEventExecutor needs to accept tasks even after
shutdown(), its execute() method only rejects the task after the event
loop is terminated (i.e. isTerminated() returns true.)  Except that,
there's no change in semantics.

SingleThreadEventExecutor also checks if its subclass called
confirmShutdown() in its run() implementation, so that Netty developers
can make sure they shut down their event loop impementation correctly.

It also fixes a bug in AioSocketChannel, revealed by delayed shutdown,
where an inboundBufferUpdated() event is triggered on a closed Channel
with deallocated buffers.

Caveats:

Because SingleThreadEventExecutor.takeTask() does not have a notion of
timeout, confirmShutdown() adds a dummy task (WAKEUP_TASK) to wake up
takeTask() immediately and instead sleeps hard-coded 100ms.  I'll
address this issue later by modifying takeTask() times out dynamically.

Miscellaneous changes:

SingleThreadEventExecutor.wakeup() now has the default implementation.
Instead of interrupting the current thread, it simply adds a dummy task
(WAKEUP_TASK) to the task queue, which is more elegant and efficient.
NioEventLoop is the only implementation that overrides it. All other
implementations' wakeup()s were removed thanks to this change.
2012-11-22 20:36:13 +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
Mike Heath
40e53b9b68 Fixed exception handling to call the exceptionCaught method in the current handler. By default the handler will call ctx.fireExceptionCaught which is what was happening before. 2012-11-20 10:00:27 +01: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
coltnz
fea7475080 [#749] Report non @Shareable handler name that has been re-added. 2012-11-18 11:40:01 +01:00
Evans Yang
a0da613e86 [#743] Make the "tail" point to the last channel handler context. And add several cases for DefaultChannelPipeline. 2012-11-16 07:33:32 +01:00
Evans Yang
37d04c26a8 [#739] Potential NullPointException without checking the initialCtx's status 2012-11-16 07:08:45 +01:00
Shawn Silverman
0bd73b8d80 [#732] [#672] Allow replacing an inbound or outbound buffer of a handler 2012-11-13 21:17:42 +01:00
Norman Maurer
d177fd5a17 [#735] Make sure the handshake ChannelFuture is notified after the right encoder is present in the ChannelPipeline 2012-11-13 09:25:19 +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
45de76f58d More helpful IllegalArgumentException message 2012-11-12 16:02:30 +09:00
Trustin Lee
b3be15204d Fix 'channelFactory already set' error 2012-11-12 15:59:25 +09:00
Trustin Lee
a05064d3eb Fix more inspection warnings + compilation errors 2012-11-12 13:25:00 +09:00
Trustin Lee
36c8eb02e8 Fix parameter namings + some more 2012-11-12 12:59:37 +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
15642f2cd8 Do not call static methods via instances 2012-11-12 11:23:06 +09:00
Trustin Lee
d78f5a4f76 Optimize imports / Remove britspace 2012-11-12 09:51:59 +09:00
Trustin Lee
9746bb2036 Make a member field final wherever possible 2012-11-12 09:43:55 +09:00
Trustin Lee
4dce19b814 Replace a variable with a constant wherever possible 2012-11-12 09:43:14 +09:00
Trustin Lee
1cb589a950 Replace a loop that runs only once with a single statement (Second take)
Fix potential NoSuchElementException
2012-11-12 09:39:16 +09:00
Trustin Lee
18f1b1f1d0 Replace a loop that runs only once with a single statement 2012-11-12 09:35:50 +09:00
Trustin Lee
aa7cd691df Remove redundant 'else' branches. 2012-11-12 09:31:40 +09:00
Trustin Lee
91a61d7f43 Remove unnecessary qualifiers 2012-11-12 09:11:48 +09:00
Norman Maurer
fa805c4c13 Allow easier use of AIO transport via bootstrap. Related to [#725] 2012-11-10 20:43:53 +01:00
Trustin Lee
1cc104e1c0 Fix a compilation error 2012-11-10 08:51:59 +09:00
Trustin Lee
b4f796c5e3 Use 'x' over "x" wherever possible / String.equals("") -> isEmpty() 2012-11-10 08:03:52 +09:00