Netty 4 based transport implementation plugin for Elasticsearch providing high-performance networking layer for HTTP and node-to-node communications
—
The channel management system provides low-level networking channel implementations for both TCP transport and HTTP server operations. These channels handle connection lifecycle, data transmission, and resource management for all network communications.
Server-side TCP channel for accepting inbound connections from other Elasticsearch cluster nodes.
/**
* Netty4 server channel implementation for TCP transport
* Binds to configured address and accepts connections from cluster peers
*/
public class Netty4TcpServerChannel implements TcpServerChannel {
/**
* Adds listener to be notified when server channel closes
* Useful for cleanup and monitoring of server lifecycle
* @param listener Callback invoked when channel closes
*/
void addCloseListener(ActionListener<Void> listener);
/**
* Checks if server channel is currently open and accepting connections
* @return true if server is bound and accepting, false otherwise
*/
boolean isOpen();
/**
* Gets local socket address this server channel is bound to
* Includes IP address and port number for client connections
* @return Local InetSocketAddress for bound server socket
*/
InetSocketAddress getLocalAddress();
/**
* Closes server channel and stops accepting new connections
* Existing connections continue until naturally closed
*/
void close();
}Usage Example:
// Server channel created by transport layer during startup
Netty4TcpServerChannel serverChannel = // from transport initialization
// Monitor server lifecycle
serverChannel.addCloseListener(ActionListener.wrap(
() -> {
logger.info("Transport server channel closed");
// Perform cleanup operations
},
exception -> {
logger.error("Transport server channel close failed", exception);
// Handle close failure
}
));
// Check server status
if (serverChannel.isOpen()) {
InetSocketAddress address = serverChannel.getLocalAddress();
logger.info("Transport server listening on {}:{}",
address.getHostString(), address.getPort());
} else {
logger.warn("Transport server channel is not accepting connections");
}Client-side TCP channel for outbound connections to other cluster nodes.
/**
* Netty4 client channel implementation for TCP transport
* Handles individual connections to remote cluster nodes
*/
public class Netty4TcpChannel implements TcpChannel {
/**
* Adds listener to be notified when channel closes
* Called for both normal and exceptional channel closure
* @param listener Callback invoked on channel close
*/
void addCloseListener(ActionListener<Void> listener);
/**
* Checks if channel is currently open and connected
* @return true if channel is active, false if closed or closing
*/
boolean isOpen();
/**
* Gets local socket address for this connection
* @return Local InetSocketAddress of client socket
*/
InetSocketAddress getLocalAddress();
/**
* Gets remote socket address for this connection
* @return Remote InetSocketAddress of connected peer node
*/
InetSocketAddress getRemoteAddress();
/**
* Sends message bytes to remote peer asynchronously
* Messages are queued and sent in order
* @param reference Serialized message bytes to transmit
* @param listener Callback for send completion or failure
*/
void sendMessage(BytesReference reference, ActionListener<Void> listener);
/**
* Closes channel connection to remote peer
* Pending operations complete before channel closure
*/
void close();
}Usage Example:
// Client channel obtained from transport connection
Netty4TcpChannel clientChannel = // from transport.openConnection()
// Send cluster message to remote node
TransportMessage message = // serialized cluster message
BytesReference messageBytes = // serialized message content
clientChannel.sendMessage(messageBytes, ActionListener.wrap(
response -> {
logger.debug("Message sent successfully to {}",
clientChannel.getRemoteAddress());
},
exception -> {
logger.error("Failed to send message to {}: {}",
clientChannel.getRemoteAddress(), exception.getMessage());
// Handle send failure - may trigger connection retry
}
));
// Monitor connection health
clientChannel.addCloseListener(ActionListener.wrap(
() -> {
logger.info("Connection to {} closed", clientChannel.getRemoteAddress());
// Update node connection status
},
exception -> {
logger.warn("Connection to {} closed with error: {}",
clientChannel.getRemoteAddress(), exception.getMessage());
// Trigger connection retry if appropriate
}
));Server-side HTTP channel for accepting HTTP client connections and serving REST API requests.
/**
* Netty4 HTTP server channel implementation
* Binds to HTTP port and accepts client connections for REST API access
*/
public class Netty4HttpServerChannel implements HttpServerChannel {
/**
* Gets local socket address HTTP server is bound to
* Includes bind address and port for HTTP client connections
* @return Local InetSocketAddress for HTTP server
*/
InetSocketAddress getLocalAddress();
/**
* Adds listener to be notified when HTTP server channel closes
* Useful for monitoring HTTP service availability
* @param listener Callback invoked on server close
*/
void addCloseListener(ActionListener<Void> listener);
/**
* Checks if HTTP server is currently open and accepting connections
* @return true if server is bound and accepting HTTP requests
*/
boolean isOpen();
/**
* Closes HTTP server channel and stops accepting connections
* Existing HTTP connections complete current requests before closing
*/
void close();
}Usage Example:
// HTTP server channel created during HTTP transport startup
Netty4HttpServerChannel httpServer = // from HTTP transport initialization
// Check HTTP server status
if (httpServer.isOpen()) {
InetSocketAddress httpAddress = httpServer.getLocalAddress();
logger.info("HTTP server accepting connections on {}:{}",
httpAddress.getHostString(), httpAddress.getPort());
// HTTP server is ready for client requests
// Clients can now send REST API requests to this address
} else {
logger.error("HTTP server failed to bind - REST API unavailable");
}
// Monitor HTTP server lifecycle
httpServer.addCloseListener(ActionListener.wrap(
() -> {
logger.info("HTTP server stopped - REST API no longer available");
// Update service registry or load balancer
},
exception -> {
logger.error("HTTP server close failed", exception);
// Handle server shutdown issues
}
));Client-side HTTP channel for individual HTTP client connections.
/**
* Netty4 HTTP client channel implementation
* Handles individual HTTP connections from clients to process REST requests
*/
public class Netty4HttpChannel implements HttpChannel {
/**
* Sends HTTP response to client asynchronously
* Response is queued and transmitted to client
* @param response HTTP response object with status, headers, and body
* @param listener Callback for response transmission completion
*/
void sendResponse(HttpResponse response, ActionListener<Void> listener);
/**
* Gets local address for this HTTP connection
* @return Local InetSocketAddress of server side
*/
InetSocketAddress getLocalAddress();
/**
* Gets remote client address for this HTTP connection
* @return Remote InetSocketAddress of HTTP client
*/
InetSocketAddress getRemoteAddress();
/**
* Closes HTTP connection to client
* Connection may be kept alive for reuse depending on HTTP headers
*/
void close();
}Usage Example:
// HTTP channel created for each client connection
Netty4HttpChannel httpChannel = // from HTTP request pipeline
// Process HTTP request and send response
RestResponse restResponse = // from REST handler processing
HttpResponse httpResponse = // converted to HTTP format
httpChannel.sendResponse(httpResponse, ActionListener.wrap(
response -> {
logger.debug("HTTP response sent to client {}",
httpChannel.getRemoteAddress());
// Response successfully transmitted
},
exception -> {
logger.warn("Failed to send HTTP response to {}: {}",
httpChannel.getRemoteAddress(), exception.getMessage());
// Client may have disconnected or network error occurred
}
));
// Log client connection info
InetSocketAddress clientAddr = httpChannel.getRemoteAddress();
InetSocketAddress serverAddr = httpChannel.getLocalAddress();
logger.debug("Processing HTTP request from {} to {}", clientAddr, serverAddr);Specialized socket channel implementations providing enhanced functionality and performance optimizations.
/**
* Custom NIO socket channel with Elasticsearch-specific optimizations
* Extends Netty's NioSocketChannel with additional features
*/
public class Netty4NioSocketChannel extends NioSocketChannel {
// Enhanced socket channel with ES-specific networking optimizations
// Provides better integration with Elasticsearch's networking stack
}
/**
* Socket channel implementation that copies bytes for certain operations
* Provides additional safety for buffer management in specific scenarios
*/
public class CopyBytesSocketChannel extends Netty4NioSocketChannel {
// Specialized channel that copies bytes when needed
// Used for scenarios requiring buffer isolation or special handling
}
/**
* Server socket channel that copies bytes for connection handling
* Provides enhanced buffer management for server-side operations
*/
public class CopyBytesServerSocketChannel extends NioServerSocketChannel {
// Server-side equivalent of CopyBytesSocketChannel
// Handles incoming connections with specialized byte copying behavior
}Channel implementations provide comprehensive lifecycle management:
Connection Establishment: Proper handshake and negotiation for both TCP and HTTP protocols
Resource Allocation: Efficient allocation of buffers, threads, and system resources per connection
Error Handling: Graceful handling of network errors, timeouts, and connection failures
Connection Pooling: Reuse of connections where appropriate to minimize overhead
Graceful Shutdown: Proper cleanup and resource release during channel closure
Monitoring Integration: Detailed metrics and logging for connection health and performance
// TCP transport channel settings
Settings tcpSettings = Settings.builder()
.put("transport.tcp.port", "9300-9400") // Port range
.put("transport.bind_host", "0.0.0.0") // Bind address
.put("transport.publish_host", "192.168.1.100") // Advertised address
.put("transport.tcp.connect_timeout", "30s") // Connection timeout
.put("transport.tcp.compress", true) // Message compression
.build();// HTTP server channel settings
Settings httpSettings = Settings.builder()
.put("http.port", "9200-9300") // HTTP port range
.put("http.bind_host", "0.0.0.0") // HTTP bind address
.put("http.publish_host", "192.168.1.100") // HTTP advertised address
.put("http.max_content_length", "100mb") // Request size limit
.put("http.compression", true) // Response compression
.put("http.cors.enabled", true) // CORS support
.build();The channel management system integrates deeply with Elasticsearch's networking infrastructure:
Transport Integration: Channels are created and managed by transport implementations
Thread Pool Integration: Channel operations use appropriate Elasticsearch thread pools
Circuit Breaker Integration: Channels respect resource limits and circuit breakers
Security Integration: Channels support TLS encryption and authentication
Monitoring Integration: Channel statistics are exposed via Elasticsearch monitoring APIs
Plugin Integration: Other plugins can extend channel functionality through Elasticsearch's plugin system
The channel management system provides the foundation for all network communication in Elasticsearch, ensuring reliable, performant, and secure data transmission between cluster nodes and client applications.
Install with Tessl CLI
npx tessl i tessl/maven-org-elasticsearch-plugin--transport-netty4-client