Elffuss BraidHub

kikocis/java-driver public

Use Netty's pooled ByteBufAllocator by default (JAVA-756).
Changeset5b2ba50eec1f86641ae0076b1bb37299f130cf2c26e2015cf0ae18c877e87dc5
Authorolim7t <omichallat+github@gmail.com> · 2015-05-08 11:56 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-05-08 11:57 +02:00
Parents7a8f1020e6b4

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -4,6 +4,8 @@
44 2.0.11:
55 -------
66
7+- [improvement] Use Netty's pooled ByteBufAllocator by default (JAVA-756)
8+
79
810 2.0.10:
911 -------
modified driver-core/src/main/java/com/datastax/driver/core/NettyOptions.java +14 −6
@@ -21,6 +21,9 @@
2121 import static java.util.concurrent.TimeUnit.SECONDS;
2222
2323 import io.netty.bootstrap.Bootstrap;
24+import io.netty.buffer.ByteBufAllocator;
25+import io.netty.buffer.PooledByteBufAllocator;
26+import io.netty.channel.ChannelOption;
2427 import io.netty.channel.EventLoopGroup;
2528 import io.netty.channel.nio.NioEventLoopGroup;
2629 import io.netty.channel.socket.SocketChannel;
@@ -122,18 +125,25 @@
122125 * {@link SocketOptions}s.
123126 * <p>
124127 * This is a good place to add extra {@link io.netty.channel.ChannelHandler ChannelOption}s to the boostrap; e.g.
125- * to replace the default {@link io.netty.buffer.ByteBufAllocator ByteBufAllocator} implementation with a custom one,
126- * do the following:
128+ * plug a custom {@link io.netty.buffer.ByteBufAllocator ByteBufAllocator} implementation:
127129 *
128130 * <pre>
129131 * ByteBufAllocator myCustomByteBufAllocator = ...
130- * boostrap.option(ChannelOption.ALLOCATOR, myCustomByteBufAllocator);
132+ *
133+ * public void afterBootstrapInitialized(Bootstrap bootstrap) {
134+ * bootstrap.option(ChannelOption.ALLOCATOR, myCustomByteBufAllocator);
135+ * }
131136 * </pre>
132137 *
138+ * Note that the default implementation of this method configures a pooled {@code ByteBufAllocator} (Netty 4.0
139+ * defaults to unpooled). If you override this method to set unrelated options, make sure you call
140+ * {@code super.afterBootstrapInitialized(bootstrap)}.
141+ *
133142 * @param bootstrap the {@link Bootstrap} being initialized.
134143 */
135144 public void afterBootstrapInitialized(Bootstrap bootstrap) {
136- //noop
145+ // In Netty 4.1.x, pooled will be the default, so this won't be necessary anymore
146+ bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
137147 }
138148
139149 /**
@@ -189,6 +199,4 @@
189199 // it is safe to reduce the quiet period to 0 seconds
190200 eventLoopGroup.shutdownGracefully(0, 15, SECONDS).syncUninterruptibly();
191201 }
192-
193-
194202 }