CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-elasticsearch-plugin--transport-netty3-client

Netty 3 based transport implementation for Elasticsearch providing TCP and HTTP transport layers

Pending
Overview
Eval results
Files

http-channel-pipeline.mddocs/

HTTP Channel and Pipeline

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.

Capabilities

HTTP Channel 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 Processing

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 Support

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);
}

Pipelining Event Objects

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();
}

Usage Examples

Basic HTTP Channel Usage

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);

HTTP Pipelining Configuration

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());

Channel Information Access

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);

Architecture Notes

Pipelining Behavior

The HTTP pipelining handler ensures that:

  1. Request Order Preservation: Responses are sent in the exact order requests were received
  2. Memory Management: Limits the number of queued events to prevent memory exhaustion
  3. Connection Integrity: Aborts connections that exceed the maximum event threshold
  4. Performance Optimization: Allows multiple requests to be processed concurrently while maintaining order

Channel Lifecycle

  1. Request Reception: Netty receives HTTP request and creates Netty3HttpRequest
  2. Channel Creation: Netty3HttpChannel is created to handle the request/response cycle
  3. Processing: Request is processed by Elasticsearch's REST layer
  4. Response Generation: Response is created and sent via the channel
  5. Cleanup: Channel resources are released after response completion

Error Handling

The HTTP channel implementation includes comprehensive error handling for:

  • Malformed Requests: Invalid HTTP syntax or structure
  • Content Processing Errors: Issues with request body parsing
  • Response Generation Failures: Problems creating or sending responses
  • Connection Issues: Network problems or client disconnections
  • Resource Exhaustion: Memory or connection limit scenarios

Install with Tessl CLI

npx tessl i tessl/maven-org-elasticsearch-plugin--transport-netty3-client

docs

cors-configuration.md

http-channel-pipeline.md

http-transport.md

index.md

network-utilities.md

plugin-registration.md

tcp-transport.md

tile.json