Skip to content

Commit 0461e12

Browse files
committed
Simplify Netty 4 transport implementations
The Netty 4 transport implementations have an unnecessary dependency on SocketChannels, and can instead just use plain Channels.
1 parent 6def10c commit 0461e12

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public ChannelHandler configureServerChannelHandler() {
525525
return new HttpChannelHandler(this, detailedErrorsEnabled, threadPool.getThreadContext());
526526
}
527527

528-
protected static class HttpChannelHandler extends ChannelInitializer<SocketChannel> {
528+
protected static class HttpChannelHandler extends ChannelInitializer<Channel> {
529529

530530
private final Netty4HttpServerTransport transport;
531531
private final Netty4HttpRequestHandler requestHandler;
@@ -539,7 +539,7 @@ protected HttpChannelHandler(
539539
}
540540

541541
@Override
542-
protected void initChannel(SocketChannel ch) throws Exception {
542+
protected void initChannel(Channel ch) throws Exception {
543543
ch.pipeline().addLast("openChannels", transport.serverOpenChannels);
544544
final HttpRequestDecoder decoder = new HttpRequestDecoder(
545545
Math.toIntExact(transport.maxInitialLineLength.bytes()),

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.netty.channel.Channel;
2626
import io.netty.channel.ChannelFuture;
2727
import io.netty.channel.ChannelFutureListener;
28+
import io.netty.channel.ChannelHandler;
2829
import io.netty.channel.ChannelHandlerContext;
2930
import io.netty.channel.ChannelInitializer;
3031
import io.netty.channel.ChannelOption;
@@ -310,11 +311,11 @@ private void createServerBootstrap(String name, Settings settings) {
310311
serverBootstraps.put(name, serverBootstrap);
311312
}
312313

313-
protected ChannelInitializer<SocketChannel> getServerChannelInitializer(String name, Settings settings) {
314+
protected ChannelHandler getServerChannelInitializer(String name, Settings settings) {
314315
return new ServerChannelInitializer(name, settings);
315316
}
316317

317-
protected ChannelInitializer<SocketChannel> getClientChannelInitializer() {
318+
protected ChannelHandler getClientChannelInitializer() {
318319
return new ClientChannelInitializer();
319320
}
320321

@@ -506,18 +507,18 @@ protected void stopInternal() {
506507
});
507508
}
508509

509-
protected class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {
510+
protected class ClientChannelInitializer extends ChannelInitializer<Channel> {
510511

511512
@Override
512-
protected void initChannel(SocketChannel ch) throws Exception {
513+
protected void initChannel(Channel ch) throws Exception {
513514
ch.pipeline().addLast("size", new Netty4SizeHeaderFrameDecoder());
514515
// using a dot as a prefix means this cannot come from any settings parsed
515516
ch.pipeline().addLast("dispatcher", new Netty4MessageChannelHandler(Netty4Transport.this, ".client"));
516517
}
517518

518519
}
519520

520-
protected class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
521+
protected class ServerChannelInitializer extends ChannelInitializer<Channel> {
521522

522523
protected final String name;
523524
protected final Settings settings;
@@ -528,10 +529,11 @@ protected ServerChannelInitializer(String name, Settings settings) {
528529
}
529530

530531
@Override
531-
protected void initChannel(SocketChannel ch) throws Exception {
532+
protected void initChannel(Channel ch) throws Exception {
532533
ch.pipeline().addLast("open_channels", Netty4Transport.this.serverOpenChannels);
533534
ch.pipeline().addLast("size", new Netty4SizeHeaderFrameDecoder());
534535
ch.pipeline().addLast("dispatcher", new Netty4MessageChannelHandler(Netty4Transport.this, name));
535536
}
536537
}
538+
537539
}

modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.netty.buffer.ByteBuf;
2323
import io.netty.buffer.Unpooled;
24+
import io.netty.channel.Channel;
2425
import io.netty.channel.ChannelHandler;
2526
import io.netty.channel.ChannelHandlerContext;
2627
import io.netty.channel.SimpleChannelInboundHandler;
@@ -179,7 +180,7 @@ private class CustomHttpChannelHandler extends Netty4HttpServerTransport.HttpCha
179180
}
180181

181182
@Override
182-
protected void initChannel(SocketChannel ch) throws Exception {
183+
protected void initChannel(Channel ch) throws Exception {
183184
super.initChannel(ch);
184185
ch.pipeline().replace("handler", "handler", new PossiblySlowUpstreamHandler(executorService));
185186
}

0 commit comments

Comments
 (0)