Skip to content

Commit baf4f2f

Browse files
authored
Add HTTP transport startup hook (elastic#130812)
This commit introduces a `startInternal()` method to `AbstractHttpServerTransport` and makes `doStart()` a final method so that we can customize the startup behaviour of the HTTP transport in a follow-up without needing cooperation from subclasses. Relates ES-12223
1 parent da9bd23 commit baf4f2f

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public Settings settings() {
165165
}
166166

167167
@Override
168-
protected void doStart() {
168+
protected void startInternal() {
169169
boolean success = false;
170170
try {
171171
sharedGroup = sharedGroupFactory.getHttpGroup();

server/src/main/java/org/elasticsearch/http/AbstractHttpServerTransport.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ private TransportAddress bindAddress(final InetAddress hostAddress) {
235235

236236
protected abstract HttpServerChannel bind(InetSocketAddress hostAddress) throws Exception;
237237

238+
@Override
239+
protected final void doStart() {
240+
startInternal();
241+
}
242+
243+
protected abstract void startInternal();
244+
238245
/**
239246
* Gracefully shut down. If {@link HttpTransportSettings#SETTING_HTTP_SERVER_SHUTDOWN_GRACE_PERIOD} is zero, the default, then
240247
* forcefully close all open connections immediately.
@@ -251,7 +258,7 @@ private TransportAddress bindAddress(final InetAddress hostAddress) {
251258
* </ol>
252259
*/
253260
@Override
254-
protected void doStop() {
261+
protected final void doStop() {
255262
synchronized (httpServerChannels) {
256263
if (httpServerChannels.isEmpty() == false) {
257264
try {

server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,10 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
211211
}
212212

213213
@Override
214-
protected void doStart() {
215-
216-
}
214+
protected void startInternal() {}
217215

218216
@Override
219-
protected void stopInternal() {
220-
221-
}
217+
protected void stopInternal() {}
222218

223219
@Override
224220
public HttpStats stats() {
@@ -295,14 +291,10 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
295291
}
296292

297293
@Override
298-
protected void doStart() {
299-
300-
}
294+
protected void startInternal() {}
301295

302296
@Override
303-
protected void stopInternal() {
304-
305-
}
297+
protected void stopInternal() {}
306298

307299
@Override
308300
public HttpStats stats() {
@@ -385,7 +377,7 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
385377
}
386378

387379
@Override
388-
protected void doStart() {}
380+
protected void startInternal() {}
389381

390382
@Override
391383
protected void stopInternal() {}
@@ -516,7 +508,7 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
516508
}
517509

518510
@Override
519-
protected void doStart() {}
511+
protected void startInternal() {}
520512

521513
@Override
522514
protected void stopInternal() {}
@@ -567,9 +559,7 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
567559
}
568560

569561
@Override
570-
protected void doStart() {
571-
572-
}
562+
protected void startInternal() {}
573563

574564
@Override
575565
protected void stopInternal() {
@@ -710,14 +700,10 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
710700
}
711701

712702
@Override
713-
protected void doStart() {
714-
715-
}
703+
protected void startInternal() {}
716704

717705
@Override
718-
protected void stopInternal() {
719-
720-
}
706+
protected void stopInternal() {}
721707

722708
@Override
723709
public HttpStats stats() {
@@ -774,7 +760,7 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
774760
}
775761

776762
@Override
777-
protected void doStart() {}
763+
protected void startInternal() {}
778764

779765
@Override
780766
protected void stopInternal() {}
@@ -856,7 +842,7 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
856842
}
857843

858844
@Override
859-
protected void doStart() {}
845+
protected void startInternal() {}
860846

861847
@Override
862848
protected void stopInternal() {}
@@ -1226,7 +1212,7 @@ protected HttpServerChannel bind(InetSocketAddress hostAddress) {
12261212
}
12271213

12281214
@Override
1229-
protected void doStart() {
1215+
protected void startInternal() {
12301216
bindServer();
12311217
}
12321218

0 commit comments

Comments
 (0)