Commit Graph

321 Commits

Author SHA1 Message Date
Trustin Lee
a507ea97ef Move some logic from DefaultChannelPipeline to DefaultChannelHandlerContext
- Using the fact that head is always non-null, we can remove some code
  in DefaultChannelPipeline and move some to
  DefaultChannelHandlerContext
2012-06-08 23:11:15 +09:00
Trustin Lee
468a3228a4 Fit every line into 120 columns 2012-06-08 19:28:12 +09:00
Trustin Lee
353357fbd5 Moved AsyncPipelineModification to a new file 2012-06-08 12:44:47 +09:00
Trustin Lee
493e77a5a7 Remove trailing whitespace 2012-06-08 11:14:47 +09:00
Trustin Lee
8970ee751c Fix a weird compilation error in DefaultChannelPipeline
probably a compiler bug - working around
2012-06-08 10:57:38 +09:00
Trustin Lee
50fafdc3d3 Rewrite SslHandler / Reduce the chance of OIO-OIO dead lock
- SslHandler always begins handshake unless startTls is true
  - Removed issueHandshake property
  - If a user wants to start handshake later, he/she has to add 
    SslHandler later.
- Removed enableRenegotiation property
  - JDK upgrade fixes the security vulnerability - no need to complicate
    our code
- Some property name changes
  - getSSLEngineInboundCloseFuture() -> sslCloseFuture() 
- Updated securechat example
- Added timeout for handshake and close_notify for better security
  - However, it's currently hard-coded.  Will make it a property later.
2012-06-08 01:22:35 +09:00
Trustin Lee
4a23c2a6eb Fix checkstyle errors 2012-06-07 22:01:59 +09:00
Trustin Lee
10f7a31908 Fixed SpdySessionHandlerTest / Fixed NPE in EmbeddedChannel
- Some tests like SpdySessionHandlerTest accesses outbound buffer
  even before the outbound buffer is initialized by
  AbstractEmbeddedChannel's subclasses, leading to NPE at <init>.
  To fix this problem, subclasses now pass the outbound buffer as
  a constructor parameter to AbstractEmbeddedChannel.
2012-06-07 21:33:31 +09:00
Trustin Lee
994038975a Port HttpContentEncoder/Decoder to use EmbeddedStreamChannel / Cleanup
- Removed unused constructor parameter in AbstractChannel
- Re-enabled GZIP encoding in HTTP snoop example
2012-06-07 21:06:56 +09:00
Trustin Lee
3442ff90e8 Ported all tests in netty-codec to the new embedder 2012-06-07 20:17:26 +09:00
Trustin Lee
7bc10f2eba Replace codec embedder with EmbeddedChannel which can test any handlers
- Added EventExecutor.inEventLoop(Thread) and replaced executor identity
  comparison in DefaultChannelPipeline with it - more elegant IMO
- Removed the test classes that needs rewrite or is of no use
2012-06-07 19:39:37 +09:00
Trustin Lee
8701e24b9a Add back Channel(Inbound|Outbound)(Message|Stream)HandlerAdapter
- they are useful when creating an anonymous class
- Also added back CombinedChannelHandler with extra constraints
2012-06-07 17:49:45 +09:00
Trustin Lee
aab71ccd8a Remove Channel(Inbound|Outbound)HandlerAdapter which does nothing
- Thanks to the recent refactoring, Channel(Inbound|Outbound)Handler-
  Adapter ended up having empty body.  No need to keep.
2012-06-07 17:25:15 +09:00
Trustin Lee
09570db091 Fixed a bug where ChannelInitializer can trigger the same event twice 2012-06-07 17:06:13 +09:00
Trustin Lee
6b819fb993 Fix a NPE in DefaultChannelPipeline.write(...)
- Also re-enabled logging handler in the echo example
2012-06-07 17:00:21 +09:00
Trustin Lee
ea0c9cfe79 Post-overhaul fixes / Split LoggingHandler into three
- LoggingHandler now only logs state and operations
- StreamLoggingHandler and MessageLoggingHandler log the buffer content
- Added ChannelOperationHandlerAdapter
  - Used by WriteTimeoutHandler
2012-06-07 16:56:21 +09:00
Trustin Lee
5e93d206ff Overhaul - Split ChannelHandler & Merge ChannelHandlerContext
- Extracted some handler methods from ChannelInboundHandler into
  ChannelStateHandler
- Extracted some handler methods from ChannelOutboundHandler into
  ChannelOperationHandler
- Moved exceptionCaught and userEventTriggered are now in
  ChannelHandler
  
- Channel(Inbound|Outbound)HandlerContext is merged into
  ChannelHandlerContext
- ChannelHandlerContext adds direct access methods for inboud and
  outbound buffers
  - The use of ChannelBufferHolder is minimal now.
    - Before: inbound().byteBuffer()
    - After: inboundByteBuffer()
    - Simpler and better performance
    
- Bypass buffer types were removed because it just does not work at all
  with the thread model.
  - All handlers that uses a bypass buffer are broken.  Will fix soon.

- CombinedHandlerAdapter does not make sense anymore either because
  there are four handler interfaces to consider and often the two
  handlers will implement the same handler interface such as
  ChannelStateHandler.  Thinking of better ways to provide this feature
2012-06-07 14:52:33 +09:00
Trustin Lee
4831eb49da Fix a test failure in LocalChannelRegistryTest 2012-06-07 08:54:37 +09:00
Trustin Lee
843a94b989 Fix compilation errors (#384)
- ECJ worked fine with the old code, but the official compiler does not
2012-06-06 23:02:47 +09:00
norman
caa35c9772 Rethrow the Throwable which accoured while execution the modification in the EventExecutor 2012-06-05 11:34:47 +02:00
norman
4eb42125a7 Make sure we can't deadlock even if the ChannelPipeline modification is executed by the EventExecutor 2012-06-05 11:21:44 +02:00
Trustin Lee
c2e65016fd Fixed some checkstyle errors 2012-06-04 13:43:02 -07:00
Trustin Lee
1eced1e9e3 Update license headers 2012-06-04 13:31:44 -07:00
Trustin Lee
36dbbc4867 Fix a test failure 2012-06-04 12:14:42 -07:00
Trustin Lee
4630905b92 Do not wrap exceptions if possible 2012-06-04 12:10:13 -07:00
Trustin Lee
b9fc67c9b8 Get the executor of the context earlier if possible. 2012-06-04 11:59:31 -07:00
Trustin Lee
b322e98712 Remove unnecessary parameters and fields / Clean-up 2012-06-04 11:56:00 -07:00
Norman Maurer
6b637ab22f No need for a custom Runnable implementation, just use EventExecutor.submit(..).get(). Thanks @trusting for review 2012-06-04 20:49:31 +02:00
Norman Maurer
ecea558e03 Add missing synchronized 2012-06-04 20:40:17 +02:00
Norman Maurer
0e74b089c2 Merge branch 'master' of github.com:netty/netty 2012-06-04 20:34:16 +02:00
Norman Maurer
c31fbc67c2 Let DefaultChannelPipeline call lifecycle methods of ChannelHandler with respect to the new ThreadModel 2012-06-04 20:34:09 +02:00
Norman Maurer
aac5586428 Fix NPE in test 2012-06-04 20:32:12 +02:00
Trustin Lee
1a9c0fd569 Make use of the existance of bridge references to find a buffer 2012-06-04 11:18:48 -07:00
Trustin Lee
c8c577efc5 Remove an unused field 2012-06-04 09:25:39 -07:00
Trustin Lee
0aa99606d9 Fix a race where 2 handlers in different threads access the same buffer
- DefaultChannelPipeline detects such cases and creates an object called
  'bridge' that works as a man-in-the-middle to deal with a race
  condition
- Slight performance drop is observed but still faster than v3. 
  Couldn't find much from a profiler yet.
2012-06-04 00:24:34 -07:00
Trustin Lee
c1afe3d8c3 Exchanging messages between two handlers is now thread safe
- (not byte buffers yet)
2012-06-03 19:39:35 -07:00
Trustin Lee
f3734e1eb9 Simplified DefaultChannelPipeline by making its list head final
- Previously, head was a volatile field which is null at the beginning.
  While iterating over the pipeline, if the loop hits null, it called
  Channel.Unsafe explicitly.
- Instead, I created an outbound handler that redirects all requests
  to the unsafe and made it a final field of the pipeline.
- As a result, DefaultChannelPipeline code became much simpler.
2012-06-03 18:51:42 -07:00
Trustin Lee
f6e14b636f Improve concurrent message buffer access test to reproduce known issue 2012-06-03 13:21:57 -07:00
Trustin Lee
4d8e2198fa Fix a bug where LocalServerChannel's localAddress is unregistered 2012-06-03 13:20:56 -07:00
Trustin Lee
1cd3156eba Make test case more robust 2012-06-03 13:12:29 -07:00
Trustin Lee
234c4c70db Ensure LocalChannel fire channelActive after peers's channelRegistered
- Also:
  - Made the test case more robust
  - Added a simple concurrent buffer modification test (needs more work)
2012-06-03 12:54:26 -07:00
Trustin Lee
d48973b0ff Add ChannelHandlerContext.hasNext(In|Out)bound(Byte|Message)Buffer 2012-06-03 04:35:38 -07:00
Trustin Lee
bbed0602c1 Use NoSuchBufferException instead of IllegalArgumentException 2012-06-03 04:26:11 -07:00
Trustin Lee
13d7ee1b2f Optimized DefaultChannelPipeline.write(...)
- Also replaced unnecessary function calls with field accesses
2012-06-03 04:25:03 -07:00
Trustin Lee
f991a8c7d4 Fix a bug where DefaultChannelPipeline.write() doesn't find the buffer
- Also fixed failures in SpdySessionHandlerTest
2012-06-03 04:10:32 -07:00
Trustin Lee
ada61d4985 Ported multicast test / Fixed bugs in NioDatagramChannelConfig 2012-06-03 02:57:52 -07:00
Trustin Lee
e6ceb91a85 Add AbstractDatagramTest / Port unicast test / Ignore 'Socket closed' 2012-06-03 02:40:58 -07:00
Trustin Lee
955c89fcf1 Add SocketEchoTest that will simplify a lot of socket testing
- SocketTestCombination generates all possible test combinations of
  socket transports.
- SocketEchoTest iterates over the combinations and runs all tests
  using reflection.
2012-06-03 01:52:39 -07:00
Trustin Lee
3b2c25e8ed Rename (Server)Bootstrap.(child)initializer to (child)handler
- The handler you specify with initializer() is actually simply added
  to the pipeline and that's all.  It's ChannelInitializer which does
  additional work.  For example, a user can specify just a single
  handler with initializer() and it will still work.  This is especially
  common for Bootstrap, so I renamed initializer to handler, which makes
  more sense.
2012-06-03 01:00:16 -07:00
Trustin Lee
19dcb81727 Add comments for easier understanding 2012-06-02 02:43:26 -07:00
Trustin Lee
01a5bd41f0 Add Channel.type() which tells if stream-oriented or message-oriented
- DefaultChannelPipeline uses this information to reject invalid buffer
  access in inbound(Message|Byte)Buffer.  Otherwise, a user can access
  a message buffer when the channel is stream-oriented.
- Because ChannelType cannot be both STREAM and MESSAGE, catch-all
  buffer has been removed to avoid confusion and unexpected behavior
  (it's already causing headache.)
- As a result, codec embedder needs rework.
2012-06-02 01:58:15 -07:00
Trustin Lee
cc4f705029 Replace ChannelBuffer.toByteBuffer() with hasNioBuffer() and nioBuffer()
... just like we do with byte arrays.  toByteBuffer() and
toByteBuffers() had an indeterministic behavior and thus it could not
tell when the returned NIO buffer is shared or not.  nioBuffer() always
returns a view buffer of the Netty buffer.  The only case where
hasNioBuffer() returns false and nioBuffer() fails is the
CompositeChannelBuffer, which is not very commonly used and *slow*.
2012-06-02 01:30:55 -07:00
Trustin Lee
04cf1c8199 Use custom thread factory by default to better recognize the threads
... from their names
2012-06-01 22:57:54 -07:00
Trustin Lee
61e169e53a Remove EventExecutor.parent(), which is of no use 2012-06-01 22:33:53 -07:00
Trustin Lee
4440386494 Little bit of optimization 2012-06-01 18:34:19 -07:00
Trustin Lee
141a05c831 Strict thread model / Allow assign an executor to a handler
- Add EventExecutor and make EventLoop extend it
- Add SingleThreadEventExecutor and MultithreadEventExecutor
- Add EventExecutor's default implementation
- Fixed an API design problem where there is no way to get non-bypass
  buffer of desired type
2012-06-01 17:51:19 -07:00
Trustin Lee
ab5043b3c7 Fixed LocalAddressTest 2012-05-31 21:22:03 -07:00
Trustin Lee
5243d3d0f0 Add @Sharable annotation to ChannelInitializer 2012-05-31 17:05:34 -07:00
Trustin Lee
f2eddda5a4 Call discardReadBytes() on outbound byte buffers when possible
- Also fixed a test failure in codec-http
2012-05-31 16:59:54 -07:00
Trustin Lee
d626561b59 Define a dedicated exception for performing blocking ops in event loop 2012-05-31 16:47:00 -07:00
Trustin Lee
468918227a Remove unnecessary parameter in AttributeKey and ChannelOption
- Removed UniqueKey which does nothing
- The valueType parameter was not needed at all because we do not need
  type information in runtime at all.
2012-05-31 16:03:57 -07:00
Trustin Lee
7ddc93bed8 Ported IdleStateHandler / Forward-ported the UptimeClient example
- Add ChannelHandlerContext.eventLoop() for convenience
- Bootstrap and ServerBootstrap handles channel initialization failure
  better
- More strict checks for missing @Sharable annotation
  - A handler without @Sharable annotation cannot be added more than
    once now.
2012-05-31 14:54:48 -07:00
Trustin Lee
49bda34a5d Fix a bug where ChannelBufferHolder.isEmpty() returns a wrong value
.. when it has a byte buffer
2012-05-31 09:14:39 -07:00
Trustin Lee
0fd824c3bb Fix UnsupportedOperationException 2012-05-31 09:11:07 -07:00
Trustin Lee
2a63acef4d More convenient inbound stream handler / Smarter inbound buffer cleanup
- Added a new convenience method to ChannelInboundstreamHandlerAdapter 
- EchoServerHandler uses the new method
- DefaultChannelPipeline calls inboundByteBuffer.discardReadBytes()
  when it is sure there's no memory copy involved
2012-05-31 09:03:31 -07:00
Trustin Lee
665777e6f9 Add InternetProtocolFamily and use it with NioDatagramChannel 2012-05-31 02:49:39 -07:00
Trustin Lee
7ac89ace4f Finished forward-porting SPDY codec 2012-05-31 01:53:58 -07:00
Trustin Lee
32c982b478 Fix NPE in OioChildEventLoop 2012-05-31 01:19:54 -07:00
Trustin Lee
53f16ce003 Add more convenience methods to Bootstrap and ServerBootstrap 2012-05-30 23:47:15 -07:00
Trustin Lee
67ec4429cc Implement NIO.2 multicast options 2012-05-30 19:03:45 -07:00
Trustin Lee
42abb6df3a QueueFactory cleanup
- Really attempt to create a queue to determine LTQ can be initialized
  in runtime, and cache the result
- Remove unnecessary Class<T> parameter in createQueue()
- Remove unused createQueue(Collection)
2012-05-30 16:19:22 -07:00
Trustin Lee
e3431db547 Use logger instead of System.err 2012-05-30 15:46:38 -07:00
Trustin Lee
e5bcc74cd5 Warn if the last inbound handler forwarded an exceptionCaught() event 2012-05-30 11:48:04 -07:00
Trustin Lee
cca35454d2 Ensure channelInboundBufferUpdated is fired after channelActive 2012-05-30 11:32:39 -07:00
Trustin Lee
47fa2ef2e8 Use LinkedHashSet instead of HashSet to preserve order of execution 2012-05-30 10:17:45 -07:00
Trustin Lee
9f9045c3b4 Add EventLoop implementation for the local transport 2012-05-30 04:33:43 -07:00
Trustin Lee
c17e5b458a Typo 2012-05-30 04:28:01 -07:00
Trustin Lee
4154f42520 Less restriction in shutdown hook modification 2012-05-30 04:27:19 -07:00
Trustin Lee
078a502c5f Add shutdown hooks to SingleThreadEventLoop
- LocalChannel and LocalServerChannel uses it to close themselves on
  shutdown
- LocalEcho example does not call close() anymore because the channels
  are closed automatically on shutdown
2012-05-30 04:23:15 -07:00
Trustin Lee
243f6581c6 Safer shutdown 2012-05-30 04:06:15 -07:00
Trustin Lee
65e224f149 Safer shutdown 2012-05-30 04:05:10 -07:00
Trustin Lee
a53ecbf5f1 Implement the local transport
- Replace the old local example with localecho example
- Channel's outbound buffer is guaranteed to be created on construction
  time.
2012-05-30 03:58:14 -07:00
Trustin Lee
392623749e Fix compilation errors 2012-05-30 02:01:48 -07:00
Trustin Lee
78974e85c5 AbstractUnsafe.out() -> directOutbound()
- to avoid confusion between Channel.outbound()
2012-05-30 00:38:23 -07:00
Trustin Lee
f4c6bcafaf Keep channel's outbound buffer in AbstractChannel
- Replace firstOut() with newOutboundBuffer()
2012-05-30 00:35:53 -07:00
Trustin Lee
a9948d681e Throw NoSuchBufferException instead of returning null
- Exception in this case makes a user less confusing
- To reduce the overhead of filling the stack trace,
  NoSuchBufferException has a public pre-constructed instance.
  - This is necessary because codec framework sometimes need to support
    both type of outbound buffers.
- Fixed a bug where SpdyFrameEncoder did not handle ping messages
- Reduced memory copy in codec embedder (EmbeddedChannel)
2012-05-29 17:25:09 -07:00
Trustin Lee
8237afff64 Ported most examples
- Renamed ChannelBootstrap to Bootstrap
- Renamed ServerChannelBootstrap to ServerBootstrap
- Moved bootstrap classes to io.netty.bootstrap as before
- Moved unfoldAndAdd() to a separate utility class
- Fixed a bug in unfoldAndAdd() where it did not handle ChannelBuffer
  correctly
2012-05-29 16:41:26 -07:00
Trustin Lee
026715e818 Refactor the pipeline API to support stacked codecs
- Previous API did not support the pipeline which contains multiple
  MessageToStreamEncoders because there was no way to find the closest
  outbound byte buffer.  Now you always get the correct buffer even if
  the handler that provides the buffer is placed distantly.
  For example:
  
    Channel -> MsgAEncoder -> MsgBEncoder -> MsgCEncoder
  
  Msg(A|B|C)Encoder will all have access to the channel's outbound
  byte buffer.  Previously, it was simply impossible.

- Improved ChannelBufferHolder.toString()
2012-05-29 12:09:29 -07:00
Trustin Lee
6d39c342b6 Add FIXME 2012-05-28 05:20:32 -07:00
Trustin Lee
e48281471b Limit future notification stack depth / Robost writeCounter management
- Also ported the discard example while testing this commit
2012-05-28 05:05:49 -07:00
Trustin Lee
a2698e65fb Added more convenience methods to bootstraps 2012-05-28 01:23:58 -07:00
Trustin Lee
626c5ef9c9 Remove the classes that are not part of Netty 4.0.0.Alpha1
- Will add them back before Beta1
2012-05-27 19:39:10 -07:00
Trustin Lee
f4a19886d3 Reorder methods / Move buffer expansion logic in OIO 2012-05-27 05:31:18 -07:00
Trustin Lee
7b05f34171 Split AbstractOioChannel into its subtypes
- AbstractOioMessageChannel and AbstractOioStreamChannel
- Replaced 'if' with polymorphism
- Better performance
2012-05-27 05:19:45 -07:00
Trustin Lee
064b3dc9e5 Split AbstractNioChannel into two subtypes
- AbstractNioMessageChannel and AbstractNioStreamChannel
- Better performance
- Replaced 'if' checks with polymorphism
2012-05-27 05:07:23 -07:00
Trustin Lee
7327bb3522 Add SingleThreadEventLoop.runAllTasks()
- Removed duplicated processTaskQueue() in child event loops
- Simplified the cleanup of cancelled keys in NIO transport
2012-05-27 04:43:48 -07:00
Trustin Lee
f29b6ae29a Fix performance issue in OioSocketChannel since previous refactoring 2012-05-26 23:29:23 -07:00
Trustin Lee
6206d82b2c Split AbstractChannel into AbstractOioChannel and AbstractNioChannel
- Simpler OIO transport
- Suits better for other transports such as AIO, RXTX, IOStream
- Add ChannelBufferHolders.discardBuffer()
2012-05-26 22:48:48 -07:00
Trustin Lee
a1bdf671f1 Simplified EventLoop implementation names
- Also
  - Fixed a test failure
  - Fixed compiler warnings related with ChannelInitializer type
    parameters
2012-05-25 15:51:22 -07:00
Trustin Lee
61314ef51b Split AbstractChannel.doFlush() into two variants for simpler user impl
- Also renamed doRead() to doReadMessages() and doReadBytes()
2012-05-25 15:32:28 -07:00