Skip to content

Commit c7d8860

Browse files
committed
Simplify request handling of registry
1 parent bfda932 commit c7d8860

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import io.netty.channel.SimpleChannelInboundHandler;
2626
import io.netty.handler.codec.http.DefaultFullHttpRequest;
2727
import io.netty.handler.codec.http.FullHttpRequest;
28+
2829
import org.elasticsearch.common.util.concurrent.ThreadContext;
29-
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3030
import org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest;
3131
import org.elasticsearch.transport.netty4.Netty4Utils;
3232

@@ -37,15 +37,12 @@ class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<Object> {
3737
private final boolean httpPipeliningEnabled;
3838
private final boolean detailedErrorsEnabled;
3939
private final ThreadContext threadContext;
40-
private final NamedXContentRegistry xContentRegistry;
4140

42-
Netty4HttpRequestHandler(Netty4HttpServerTransport serverTransport, boolean detailedErrorsEnabled, ThreadContext threadContext,
43-
NamedXContentRegistry xContentRegistry) {
41+
Netty4HttpRequestHandler(Netty4HttpServerTransport serverTransport, boolean detailedErrorsEnabled, ThreadContext threadContext) {
4442
this.serverTransport = serverTransport;
4543
this.httpPipeliningEnabled = serverTransport.pipelining;
4644
this.detailedErrorsEnabled = detailedErrorsEnabled;
4745
this.threadContext = threadContext;
48-
this.xContentRegistry = xContentRegistry;
4946
}
5047

5148
@Override
@@ -69,7 +66,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except
6966
request.headers(),
7067
request.trailingHeaders());
7168

72-
final Netty4HttpRequest httpRequest = new Netty4HttpRequest(xContentRegistry, copy, ctx.channel());
69+
final Netty4HttpRequest httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel());
7370
serverTransport.dispatchRequest(
7471
httpRequest,
7572
new Netty4HttpChannel(serverTransport, httpRequest, pipelinedRequest, detailedErrorsEnabled, threadContext));

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.elasticsearch.common.util.concurrent.EsExecutors;
6363
import org.elasticsearch.common.util.concurrent.ThreadContext;
6464
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
65+
import org.elasticsearch.common.xcontent.XContentParser;
6566
import org.elasticsearch.http.BindHttpException;
6667
import org.elasticsearch.http.HttpInfo;
6768
import org.elasticsearch.http.HttpServerAdapter;
@@ -194,6 +195,9 @@ public class Netty4HttpServerTransport extends AbstractLifecycleComponent implem
194195

195196
protected final boolean detailedErrorsEnabled;
196197
protected final ThreadPool threadPool;
198+
/**
199+
* The registry used to construct parsers so they support {@link XContentParser#namedObject(Class, String, Object)}.
200+
*/
197201
protected final NamedXContentRegistry xContentRegistry;
198202

199203
protected final boolean tcpNoDelay;
@@ -538,7 +542,7 @@ protected void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throw
538542
}
539543

540544
public ChannelHandler configureServerChannelHandler() {
541-
return new HttpChannelHandler(this, detailedErrorsEnabled, threadPool.getThreadContext(), xContentRegistry);
545+
return new HttpChannelHandler(this, detailedErrorsEnabled, threadPool.getThreadContext());
542546
}
543547

544548
protected static class HttpChannelHandler extends ChannelInitializer<Channel> {
@@ -549,10 +553,9 @@ protected static class HttpChannelHandler extends ChannelInitializer<Channel> {
549553
protected HttpChannelHandler(
550554
final Netty4HttpServerTransport transport,
551555
final boolean detailedErrorsEnabled,
552-
final ThreadContext threadContext,
553-
final NamedXContentRegistry xContentRegistry) {
556+
final ThreadContext threadContext) {
554557
this.transport = transport;
555-
this.requestHandler = new Netty4HttpRequestHandler(transport, detailedErrorsEnabled, threadContext, xContentRegistry);
558+
this.requestHandler = new Netty4HttpRequestHandler(transport, detailedErrorsEnabled, threadContext);
556559
}
557560

558561
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private class CustomHttpChannelHandler extends Netty4HttpServerTransport.HttpCha
181181
private final ExecutorService executorService;
182182

183183
CustomHttpChannelHandler(Netty4HttpServerTransport transport, ExecutorService executorService, ThreadContext threadContext) {
184-
super(transport, randomBoolean(), threadContext, xContentRegistry());
184+
super(transport, randomBoolean(), threadContext);
185185
this.executorService = executorService;
186186
}
187187

0 commit comments

Comments
 (0)