0
# Elasticsearch Transport Netty4 Plugin
1
2
The Elasticsearch Transport Netty4 Plugin provides a high-performance, Netty 4-based networking layer for Elasticsearch clusters. It serves as the core transport implementation for both HTTP API communications and internal node-to-node transport, enabling scalable distributed operations with non-blocking I/O capabilities.
3
4
## Package Information
5
6
- **Package Name**: org.elasticsearch.plugin:transport-netty4-client
7
- **Package Type**: maven (Elasticsearch plugin)
8
- **Language**: Java
9
- **Installation**: Plugin is included in Elasticsearch distributions, loaded via plugin system
10
- **Plugin Class**: `org.elasticsearch.transport.Netty4Plugin`
11
12
## Core Imports
13
14
```java
15
import org.elasticsearch.transport.Netty4Plugin;
16
import org.elasticsearch.transport.netty4.Netty4Transport;
17
import org.elasticsearch.http.netty4.Netty4HttpServerTransport;
18
import org.elasticsearch.transport.SharedGroupFactory;
19
import org.elasticsearch.transport.NettyAllocator;
20
```
21
22
## Basic Usage
23
24
```java
25
// Plugin is automatically loaded by Elasticsearch
26
// Main plugin class provides transport implementations
27
Netty4Plugin plugin = new Netty4Plugin();
28
29
// Access transport settings
30
List<Setting<?>> settings = plugin.getSettings();
31
32
// Plugin provides transport factory methods to Elasticsearch core
33
Map<String, Supplier<Transport>> transports = plugin.getTransports(
34
settings, threadPool, pageCacheRecycler, circuitBreakerService,
35
namedWriteableRegistry, networkService
36
);
37
38
Map<String, Supplier<HttpServerTransport>> httpTransports = plugin.getHttpTransports(
39
settings, threadPool, bigArrays, pageCacheRecycler, circuitBreakerService,
40
xContentRegistry, networkService, dispatcher, perRequestThreadContext, clusterSettings
41
);
42
```
43
44
## Architecture
45
46
The Transport Netty4 Plugin is built around several key components:
47
48
- **Plugin Framework**: Implements NetworkPlugin interface to integrate with Elasticsearch plugin system
49
- **Transport Layer**: Netty4Transport provides TCP-based node-to-node communication using Netty channels
50
- **HTTP Layer**: Netty4HttpServerTransport handles HTTP API requests with Netty HTTP codec
51
- **Resource Management**: SharedGroupFactory manages EventLoopGroup instances for efficient resource sharing
52
- **Channel Management**: Custom channel implementations handle connection lifecycle and data flow
53
- **Buffer Management**: NettyAllocator provides optimized buffer allocation strategies
54
55
## Capabilities
56
57
### Plugin Framework
58
59
Core plugin implementation that integrates Netty4 transport with Elasticsearch. Provides configuration settings and factory methods for transport implementations.
60
61
```java { .api }
62
public class Netty4Plugin extends Plugin implements NetworkPlugin {
63
public static final String NETTY_TRANSPORT_NAME = "netty4";
64
public static final String NETTY_HTTP_TRANSPORT_NAME = "netty4";
65
66
public List<Setting<?>> getSettings();
67
public Settings additionalSettings();
68
public Map<String, Supplier<Transport>> getTransports(
69
Settings settings, ThreadPool threadPool, PageCacheRecycler pageCacheRecycler,
70
CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
71
NetworkService networkService
72
);
73
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(
74
Settings settings, ThreadPool threadPool, BigArrays bigArrays,
75
PageCacheRecycler pageCacheRecycler, CircuitBreakerService circuitBreakerService,
76
NamedXContentRegistry xContentRegistry, NetworkService networkService,
77
HttpServerTransport.Dispatcher dispatcher,
78
BiConsumer<HttpPreRequest, ThreadContext> perRequestThreadContext,
79
ClusterSettings clusterSettings
80
);
81
}
82
```
83
84
[Plugin Framework](./plugin-framework.md)
85
86
### TCP Transport Layer
87
88
High-performance TCP transport implementation for node-to-node communication in Elasticsearch clusters. Handles cluster coordination, data replication, and internal messaging.
89
90
```java { .api }
91
public class Netty4Transport extends TcpTransport {
92
public static final Setting<Integer> WORKER_COUNT;
93
public static final Setting<ByteSizeValue> NETTY_RECEIVE_PREDICTOR_SIZE;
94
public static final Setting<ByteSizeValue> NETTY_RECEIVE_PREDICTOR_MIN;
95
public static final Setting<ByteSizeValue> NETTY_RECEIVE_PREDICTOR_MAX;
96
public static final Setting<Integer> NETTY_BOSS_COUNT;
97
}
98
99
public class Netty4TcpChannel implements TcpChannel {
100
void addCloseListener(ActionListener<Void> listener);
101
boolean isOpen();
102
InetSocketAddress getLocalAddress();
103
InetSocketAddress getRemoteAddress();
104
void sendMessage(BytesReference reference, ActionListener<Void> listener);
105
void close();
106
}
107
```
108
109
[TCP Transport](./tcp-transport.md)
110
111
### HTTP Server Transport
112
113
HTTP server implementation providing REST API access to Elasticsearch. Handles HTTP request/response processing with support for various content types, compression, and pipelining.
114
115
```java { .api }
116
public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
117
public static Setting<Integer> SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS;
118
public static final Setting<Integer> SETTING_HTTP_WORKER_COUNT;
119
public static final Setting<ByteSizeValue> SETTING_HTTP_NETTY_RECEIVE_PREDICTOR_SIZE;
120
}
121
122
public class Netty4HttpRequest implements HttpRequest {
123
RestRequest.Method method();
124
String uri();
125
BytesReference content();
126
Map<String, List<String>> getHeaders();
127
List<String> strictCookies();
128
HttpVersion protocolVersion();
129
Netty4HttpResponse createResponse(RestStatus status, BytesReference contentRef);
130
}
131
```
132
133
[HTTP Server Transport](./http-server-transport.md)
134
135
### Resource Management
136
137
Efficient management of Netty resources including EventLoopGroups, buffer allocation, and connection pooling. Provides shared resource pools to optimize memory usage and performance.
138
139
```java { .api }
140
public final class SharedGroupFactory {
141
public SharedGroupFactory(Settings settings);
142
public Settings getSettings();
143
public int getTransportWorkerCount();
144
public SharedGroup getTransportGroup();
145
public SharedGroup getHttpGroup();
146
}
147
148
public class NettyAllocator {
149
public static ByteBufAllocator getAllocator();
150
public static long suggestedMaxAllocationSize();
151
public static String getAllocatorDescription();
152
public static void logAllocatorDescriptionIfNeeded();
153
public static Class<? extends Channel> getChannelType();
154
public static Class<? extends ServerChannel> getServerChannelType();
155
}
156
```
157
158
[Resource Management](./resource-management.md)
159
160
### Channel Management
161
162
Low-level channel implementations providing connection management, data serialization, and network I/O operations. Handles both client and server channel lifecycle.
163
164
```java { .api }
165
public class Netty4TcpServerChannel implements TcpServerChannel {
166
void addCloseListener(ActionListener<Void> listener);
167
boolean isOpen();
168
InetSocketAddress getLocalAddress();
169
void close();
170
}
171
172
public class Netty4HttpServerChannel implements HttpServerChannel {
173
InetSocketAddress getLocalAddress();
174
void addCloseListener(ActionListener<Void> listener);
175
boolean isOpen();
176
void close();
177
}
178
```
179
180
[Channel Management](./channel-management.md)
181
182
### Utilities and Configuration
183
184
Utility classes providing Netty-specific optimizations, byte buffer management, and configuration helpers for optimal performance tuning.
185
186
```java { .api }
187
public class Netty4Utils {
188
public static void setAvailableProcessors(int availableProcessors);
189
public static ByteBuf toByteBuf(BytesReference reference);
190
public static BytesReference toBytesReference(ByteBuf byteBuf);
191
}
192
193
public class NettyByteBufSizer extends MessageToMessageDecoder<ByteBuf> {
194
// Handles byte buffer sizing for optimal memory usage
195
}
196
```
197
198
[Utilities](./utilities.md)
199
200
## Types
201
202
```java { .api }
203
// Core transport interfaces from Elasticsearch
204
interface Transport {
205
void sendRequest(DiscoveryNode node, String action, TransportRequest request,
206
TransportRequestOptions options, TransportResponseHandler<T> handler);
207
}
208
209
interface HttpServerTransport {
210
BoundTransportAddress boundAddress();
211
HttpInfo info();
212
HttpStats stats();
213
}
214
215
interface TcpChannel {
216
void addCloseListener(ActionListener<Void> listener);
217
boolean isOpen();
218
InetSocketAddress getLocalAddress();
219
InetSocketAddress getRemoteAddress();
220
void sendMessage(BytesReference reference, ActionListener<Void> listener);
221
void close();
222
}
223
224
interface HttpChannel {
225
void sendResponse(HttpResponse response, ActionListener<Void> listener);
226
InetSocketAddress getLocalAddress();
227
InetSocketAddress getRemoteAddress();
228
void close();
229
}
230
231
// Settings types
232
class Setting<T> {
233
String getKey();
234
T get(Settings settings);
235
}
236
237
// Netty buffer types (from io.netty.buffer)
238
interface ByteBufAllocator {
239
ByteBuf buffer();
240
ByteBuf directBuffer();
241
CompositeByteBuf compositeBuffer();
242
}
243
244
// Elasticsearch utility types
245
class ByteSizeValue {
246
long getBytes();
247
String toString();
248
}
249
250
class Settings {
251
<T> T get(Setting<T> setting);
252
Settings.Builder builder();
253
}
254
```