Commit Graph

336 Commits

Author SHA1 Message Date
Trustin Lee
cbd8817905 Remove MessageList from public API and change ChannelInbound/OutboundHandler accordingly
I must admit MesageList was pain in the ass.  Instead of forcing a
handler always loop over the list of messages, this commit splits
messageReceived(ctx, list) into two event handlers:

- messageReceived(ctx, msg)
- mmessageReceivedLast(ctx)

When Netty reads one or more messages, messageReceived(ctx, msg) event
is triggered for each message.  Once the current read operation is
finished, messageReceivedLast() is triggered to tell the handler that
the last messageReceived() was the last message in the current batch.

Similarly, for outbound, write(ctx, list) has been split into two:

- write(ctx, msg)
- flush(ctx, promise)

Instead of writing a list of message with a promise, a user is now
supposed to call write(msg) multiple times and then call flush() to
actually flush the buffered messages.

Please note that write() doesn't have a promise with it.  You must call
flush() to get notified on completion. (or you can use writeAndFlush())

Other changes:

- Because MessageList is completely hidden, codec framework uses
  List<Object> instead of MessageList as an output parameter.
2013-07-09 23:51:48 +09:00
Trustin Lee
75229e145a Prettier web socket log messages 2013-07-09 14:53:05 +09:00
Norman Maurer
9c1b31d20a [#1535] Remove Channel.id() and so fix the possible leakage of the previous used Channel id map
The user can still use Channel.hashCode() for logging. It's just not 100% unique but should be good enough for most cases
2013-07-08 14:07:18 +02:00
Trustin Lee
1bf2f702cb Do not use unreleaseableBuffer and duplicate
.. because it's not as fast as just creating a new direct buffer.
2013-07-07 15:28:43 +09:00
Trustin Lee
553cd034b9 Fix checkstyle 2013-07-07 12:39:29 +09:00
Trustin Lee
a4f2789e55 Add missing final modifier 2013-07-07 12:38:53 +09:00
Trustin Lee
2b2f8db5d2 Use ThreadLocalRandom where possible 2013-07-07 12:37:36 +09:00
Norman Maurer
086ae3536c [#1533] Introduce ByteBufHolder.duplicate() and make use of it in DefaultChannelGroup.write(...) 2013-07-06 21:17:51 +02:00
Norman Maurer
b63f3488b7 Add a HttpPostRequestDecoder.destory() method which should be used to destroy the decoder and free up resources
* Also make the contract more clear about who needs to call release()
2013-07-05 08:31:07 +02:00
Norman Maurer
b26e61d689 Fix broken tests 2013-07-05 07:18:33 +02:00
Norman Maurer
ea85054eab Correctly detect LastHttpContent after encoding 2013-07-05 06:41:48 +02:00
Norman Maurer
9f0f653588 Optimize HttpContentEncoder to do less memory copies as those are not needed 2013-07-05 06:38:25 +02:00
Norman Maurer
d900f8c21d [#1524] Fix resource leak in HttpContentEncoder 2013-07-05 06:27:25 +02:00
Norman Maurer
cad7c1f1b0 [#1521] Fix performance issue in AbstractHttpData 2013-07-04 11:59:30 +02:00
Norman Maurer
1fee1ef74e [#1520] Release previous set buffer when setting a new data source 2013-07-04 10:58:37 +02:00
Norman Maurer
45d20d5c9f [#1516] Fix resource leakage which was caused by the AbstractDiskHttpData which did not release the buffer after copy to disk 2013-07-04 10:41:49 +02:00
Norman Maurer
f64a121de7 [#1515] Add WebSocketFrameEncoder and WebSocketFrameDecoder interfaces and let our impls implement it 2013-07-04 06:41:22 +02:00
Norman Maurer
79576d15c2 [#1513] Use the correct names when add the websocket decoder and encoder 2013-07-03 19:54:08 +02:00
Norman Maurer
328969485c Add explaination to the javadocs to not call retain() on the request when doing the handshake. Related to [#1508] 2013-07-03 06:41:12 +02:00
Norman Maurer
a4ee2841be [#1507] Fix buffer leak in WebSocket08FrameDecoder 2013-07-02 13:46:09 +02:00
alain
9633769909 Improve performance of encodeHeader 2013-07-02 06:32:56 +02:00
Norman Maurer
5d88c423df [#1500] Remove @deprecated methods 2013-07-01 08:53:02 +02:00
Trustin Lee
cfd514d099 Add WebSocketClientHandshaker.close()
- Fixes #1470
2013-06-25 18:52:27 +09:00
Norman Maurer
e8ea98017f Fix regression introduced by 0364265f46 which could lead to corrupt attribute values 2013-06-25 09:31:51 +02:00
Trustin Lee
e0805ecea9 SPDY: handle too large header blocks
- Forward-ported 22b8a96e044b77e5fadc5a1217080a1f9c69aa9c
2013-06-25 11:07:15 +09:00
Andrej Golovnin
c07b0cac70 Adds port to the host header value. Due to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23 the port should be added if it differs from the default port. To simplify the code we just always add the port. 2013-06-25 11:07:14 +09:00
Trustin Lee
a969613540 Merge ChannelInboundConsumingHandler into SimpleChannelInboundHandler
- SimpleChannelInboundHandler now has a constructor parameter to let a
  user decide to enable automatic message release. (the default is to
  enable), which makes ChannelInboundConsumingHandler of less value.
2013-06-25 11:07:14 +09:00
Trustin Lee
dc6e2cd625 Make AbstractMemoryHttpData generate less garbage 2013-06-25 11:07:13 +09:00
Norman Maurer
6a9f965f9b Introduce new utility class calles ReferenceCountUtil and move utility methods from ByteBufUtil to it.
The ones in ByteBufUtil were marked as @deprecated
2013-06-14 07:07:33 +02:00
Trustin Lee
01d9f10af6 Remove the volatile modifiers where they are unnecessary 2013-06-13 14:43:39 +09:00
Trustin Lee
175526b6bd Move ReferenceCounted and AbstractReferenceCounted to io.netty.util
- Fixes #1441
- Also move and rename IllegalBufferAccessException to ReferenceCountException
- Prettier reference count exception messages
2013-06-13 13:14:21 +09:00
Trustin Lee
96380e756c Fix test failures introduced by 78d8f05c21 2013-06-13 11:51:03 +09:00
Norman Maurer
a403da3042 Rewrite HTTP encoder to use gathering writes 2013-06-13 11:02:31 +09:00
Trustin Lee
78d8f05c21 Make sure that HttpObjectDecoder decodes the last HTTP message without 'Content-Length' header
- Fixes #1410
- Revert 1e5f266a3c and provide a proper fix with a test
2013-06-13 10:57:06 +09:00
Norman Maurer
1e5f266a3c [#1410] Make sure we generate a Http response if the server writes back 200 response with empty body and and close the connection 2013-06-12 09:56:00 +02:00
Norman Maurer
e3ec124ccd Make sure WebSocketFrameAggregator and HttpObjectAggregator don't leak ByteBufs 2013-06-11 08:53:14 +02:00
Norman Maurer
92bd4d2fe0 Remove MessageList.remove(*) , MessageList.set(*) and MessageList.add(i,*) 2013-06-10 13:44:01 +02:00
Norman Maurer
e71a521284 [#1414] Use gathering writes in AbstractMemoryHttpData if the buffer is backed by multiple ByteBuffers
* This fix the bug which caused an UnsupportedOperationException when renameTo(...) was called and the underlying ByteBuf was backed by multiple ByteBuffers
2013-06-10 09:25:03 +02:00
Trustin Lee
14158070bf 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-06-10 16:10:39 +09:00
Norman Maurer
aa96b4b286 No need to create temporary arrays 2013-05-24 19:58:55 +02:00
Norman Maurer
0e8fb21554 Some optimizations to the http codec 2013-05-24 09:07:17 +02:00
Norman Maurer
83dcf829d6 [#1384] Cache HttpHeaderDateFormat in ThreadLocal 2013-05-23 11:39:50 +02:00
shreyharia
1801ecfe30 Update HttpHeaderDateFormat.java
Output for "E, dd-MMM-y HH:mm:ss z"
on java 1.6 I get: Wed, 22-May-13 09:11:41 GM
on java 1.7 I get: Wed, 22-May-2013 09:11:14 GMT

To be uniform on both jdks.. modified it to
"E, dd-MMM-yy HH:mm:ss z"

learnt from - http://stackoverflow.com/questions/16687298/simpledateformat-different-behaviour-depending-on-java-version
2013-05-22 13:36:03 +02:00
Norman Maurer
bd2230961d Fix checkstyle 2013-05-17 22:09:11 +02:00
Norman Maurer
aaca9df99a @Deprecate a method as it's not needed anymore 2013-05-17 22:00:55 +02:00
Norman Maurer
8a5e249d6f [#1374] Allow users to all all subprotocols by using * as wildcard 2013-05-17 21:57:47 +02:00
Norman Maurer
a331c87a7a [#1358] Fix Encoding of multipart attribute names and filenames for non ASCII chars 2013-05-14 15:24:01 +02:00
Norman Maurer
3268d6fc2e [#1352] WebSocketFrameAggregator should only throw TooLongFrameException once per complete frame 2013-05-09 21:12:36 +02:00
Norman Maurer
c8de4f03f1 [#1007] Make sure the current message is only reset on LastHttpContent 2013-05-09 20:11:34 +02:00
Norman Maurer
268b059ebb [#1007] HttpObjectAggregator should only throw one TooLongFrameException per full HTTP message 2013-05-09 19:44:39 +02:00