Netty 3 based transport implementation for Elasticsearch providing TCP and HTTP transport layers
—
HTTP channel management and pipelining functionality for the Netty 3 transport layer. This capability provides comprehensive HTTP request/response processing, pipelining support, and channel lifecycle management.
HTTP channel implementation that bridges Elasticsearch's REST layer with Netty 3's HTTP handling.
/**
* HTTP channel implementation for handling REST requests and responses
* Extends AbstractRestChannel to provide Netty 3-specific HTTP processing
*/
public final class Netty3HttpChannel extends AbstractRestChannel {
/**
* Constructor for creating an HTTP channel
* @param transport The parent HTTP server transport
* @param request The HTTP request being processed
* @param orderedUpstreamMessageEvent Optional pipelining event for request ordering
* @param detailedErrorsEnabled Whether to include detailed error information
* @param threadContext Thread context for request processing
*/
public Netty3HttpChannel(Netty3HttpServerTransport transport, Netty3HttpRequest request,
OrderedUpstreamMessageEvent orderedUpstreamMessageEvent,
boolean detailedErrorsEnabled, ThreadContext threadContext);
/**
* Creates a new bytes output stream for response content
* @return BytesStreamOutput for writing response data
*/
public BytesStreamOutput newBytesOutput();
/**
* Sends the REST response to the client
* @param response RestResponse containing status, headers, and content
*/
public void sendResponse(RestResponse response);
}HTTP request wrapper that adapts Netty HTTP requests to Elasticsearch's REST request model.
/**
* HTTP request implementation that wraps Netty HttpRequest for Elasticsearch processing
* Provides access to request method, URI, headers, content, and connection information
*/
public class Netty3HttpRequest extends RestRequest {
/**
* Constructor for wrapping a Netty HTTP request
* @param xContentRegistry Registry for parsing request content
* @param request The underlying Netty HTTP request
* @param channel The Netty channel for this request
*/
public Netty3HttpRequest(NamedXContentRegistry xContentRegistry, HttpRequest request, Channel channel);
/**
* Returns the underlying Netty HTTP request
* @return HttpRequest the original Netty request object
*/
public HttpRequest request();
/**
* Returns the HTTP method for this request
* @return Method enum value (GET, POST, PUT, DELETE, etc.)
*/
public Method method();
/**
* Returns the request URI including query parameters
* @return String containing the full request URI
*/
public String uri();
/**
* Checks if the request has content body
* @return boolean true if request contains content
*/
public boolean hasContent();
/**
* Returns the request content as bytes
* @return BytesReference containing the request body
*/
public BytesReference content();
/**
* Returns the remote client address
* @return SocketAddress of the client connection
*/
public SocketAddress getRemoteAddress();
/**
* Returns the local server address
* @return SocketAddress of the server connection
*/
public SocketAddress getLocalAddress();
/**
* Returns the underlying Netty channel
* @return Channel object for direct channel operations
*/
public Channel getChannel();
}HTTP pipelining handler that ensures responses are sent in the same order as requests were received.
/**
* Implements HTTP pipelining ordering to ensure responses are served
* in the same order as their corresponding requests. This is critical
* for HTTP/1.1 pipelining compliance and performance.
*/
public class HttpPipeliningHandler extends SimpleChannelHandler {
/**
* Initial number of events held in the pipelining queue
*/
public static final int INITIAL_EVENTS_HELD = 3;
/**
* Constructor for HTTP pipelining handler
* @param maxEventsHeld Maximum number of events to hold before aborting connection
* This prevents memory exhaustion from unlimited queueing
*/
public HttpPipeliningHandler(int maxEventsHeld);
/**
* Handles upstream channel events for request ordering
* @param ctx Channel handler context
* @param e Channel event to process
*/
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e);
/**
* Handles downstream channel events for response ordering
* @param ctx Channel handler context
* @param e Channel event to process
*/
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e);
}Event objects used for maintaining request/response ordering in HTTP pipelining.
/**
* Upstream message event with ordering information for pipelining
*/
public class OrderedUpstreamMessageEvent {
/**
* Returns the sequence number for this request
* @return int sequence number for ordering
*/
public int getSequence();
/**
* Returns the subsequence number for this request
* @return int subsequence number for fine-grained ordering
*/
public int getSubsequence();
}
/**
* Downstream channel event with ordering information for pipelining
*/
public class OrderedDownstreamChannelEvent {
/**
* Returns the sequence number for this response
* @return int sequence number matching the original request
*/
public int getSequence();
/**
* Returns the subsequence number for this response
* @return int subsequence number for fine-grained ordering
*/
public int getSubsequence();
/**
* Checks if this is the last event in the sequence
* @return boolean true if this completes the response sequence
*/
public boolean isLast();
}import org.elasticsearch.http.netty3.Netty3HttpChannel;
import org.elasticsearch.http.netty3.Netty3HttpRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus;
// HTTP request processing (typically handled internally)
Netty3HttpRequest httpRequest = new Netty3HttpRequest(xContentRegistry, nettyRequest, channel);
Netty3HttpChannel httpChannel = new Netty3HttpChannel(transport, httpRequest, null, false, threadContext);
// Create and send response
RestResponse response = new RestResponse(RestStatus.OK, "application/json", "{\"status\":\"ok\"}");
httpChannel.sendResponse(response);import org.elasticsearch.http.netty3.pipelining.HttpPipeliningHandler;
// Configure pipelining handler in channel pipeline
ChannelPipeline pipeline = Channels.pipeline();
// Add pipelining handler with maximum 100 held events
HttpPipeliningHandler pipeliningHandler = new HttpPipeliningHandler(100);
pipeline.addLast("pipelining", pipeliningHandler);
// Add other HTTP handlers
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("handler", new HttpRequestHandler());import org.elasticsearch.http.netty3.Netty3HttpRequest;
// Access connection information
Netty3HttpRequest request = // ... obtained from processing
SocketAddress clientAddress = request.getRemoteAddress();
SocketAddress serverAddress = request.getLocalAddress();
Channel nettyChannel = request.getChannel();
// Check request properties
String method = request.method().name();
String uri = request.uri();
boolean hasBody = request.hasContent();
BytesReference content = request.content();
System.out.println("Request: " + method + " " + uri + " from " + clientAddress);The HTTP pipelining handler ensures that:
The HTTP channel implementation includes comprehensive error handling for:
Install with Tessl CLI
npx tessl i tessl/maven-org-elasticsearch-plugin--transport-netty3-client