Skip to content

Commit 979a342

Browse files
committed
Remove usages of TransportMessage
This base class is kinda pointless: everywhere it's used we can either be more specific (e.g. choosing between `TransportRequest` or `TransportResponse`) or more general (e.g. choosing `Writeable`). This commit removes all the usages apart from the `extends` clauses of its direct descendants.
1 parent 0b09506 commit 979a342

File tree

9 files changed

+31
-30
lines changed

9 files changed

+31
-30
lines changed

server/src/main/java/org/elasticsearch/transport/InboundHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import java.nio.ByteBuffer;
3333

3434
/**
35-
* Handles inbound messages by first deserializing a {@link TransportMessage} from an {@link InboundMessage} and then passing
36-
* it to the appropriate handler.
35+
* Handles inbound messages by first deserializing a {@link TransportRequest} or {@link TransportResponse} from an {@link InboundMessage}
36+
* and then passing it to the appropriate handler.
3737
*/
3838
public class InboundHandler {
3939

server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.elasticsearch.common.util.concurrent.EsExecutors;
3737
import org.elasticsearch.common.util.concurrent.EsExecutors.TaskTrackingConfig;
3838
import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor;
39+
import org.elasticsearch.core.RefCounted;
3940
import org.elasticsearch.index.shard.ShardId;
4041
import org.elasticsearch.lucene.grouping.TopFieldGroups;
4142
import org.elasticsearch.search.DocValueFormat;
@@ -70,7 +71,6 @@
7071
import org.elasticsearch.test.ESTestCase;
7172
import org.elasticsearch.threadpool.TestThreadPool;
7273
import org.elasticsearch.threadpool.ThreadPool;
73-
import org.elasticsearch.transport.TransportMessage;
7474
import org.junit.After;
7575
import org.junit.Before;
7676

@@ -177,7 +177,7 @@ public void testSortDocs() {
177177
ScoreDoc[] sortedDocs = SearchPhaseController.sortDocs(true, topDocsList, from, size, reducedCompletionSuggestions).scoreDocs();
178178
assertThat(sortedDocs.length, equalTo(accumulatedLength));
179179
} finally {
180-
results.asList().forEach(TransportMessage::decRef);
180+
results.asList().forEach(RefCounted::decRef);
181181
}
182182
}
183183

@@ -211,7 +211,7 @@ public void testSortDocsIsIdempotent() throws Exception {
211211
}
212212
sortedDocs = SearchPhaseController.sortDocs(ignoreFrom, topDocsList, from, size, Collections.emptyList()).scoreDocs();
213213
} finally {
214-
results.asList().forEach(TransportMessage::decRef);
214+
results.asList().forEach(RefCounted::decRef);
215215
}
216216
results = generateSeededQueryResults(randomSeed, nShards, Collections.emptyList(), queryResultSize, useConstantScore);
217217
try {
@@ -231,7 +231,7 @@ public void testSortDocsIsIdempotent() throws Exception {
231231
assertEquals(sortedDocs[i].score, sortedDocs2[i].score, 0.0f);
232232
}
233233
} finally {
234-
results.asList().forEach(TransportMessage::decRef);
234+
results.asList().forEach(RefCounted::decRef);
235235
}
236236
}
237237

@@ -342,10 +342,10 @@ public void testMerge() {
342342
assertThat(mergedResponse.profile(), is(anEmptyMap()));
343343
}
344344
} finally {
345-
fetchResults.asList().forEach(TransportMessage::decRef);
345+
fetchResults.asList().forEach(RefCounted::decRef);
346346
}
347347
} finally {
348-
queryResults.asList().forEach(TransportMessage::decRef);
348+
queryResults.asList().forEach(RefCounted::decRef);
349349
}
350350
}
351351
}
@@ -419,11 +419,11 @@ protected boolean lessThan(RankDoc a, RankDoc b) {
419419
assertThat(mergedResponse.hits().getHits().length, equalTo(reducedQueryPhase.sortedTopDocs().scoreDocs().length));
420420
assertThat(mergedResponse.profile(), is(anEmptyMap()));
421421
} finally {
422-
fetchResults.asList().forEach(TransportMessage::decRef);
422+
fetchResults.asList().forEach(RefCounted::decRef);
423423
}
424424
} finally {
425425

426-
queryResults.asList().forEach(TransportMessage::decRef);
426+
queryResults.asList().forEach(RefCounted::decRef);
427427
}
428428
}
429429
}

server/src/test/java/org/elasticsearch/search/profile/SearchProfileResultsBuilderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
package org.elasticsearch.search.profile;
1111

1212
import org.elasticsearch.common.util.Maps;
13+
import org.elasticsearch.core.RefCounted;
1314
import org.elasticsearch.index.shard.ShardId;
1415
import org.elasticsearch.search.SearchHits;
1516
import org.elasticsearch.search.SearchShardTarget;
1617
import org.elasticsearch.search.fetch.FetchSearchResult;
1718
import org.elasticsearch.test.ESTestCase;
18-
import org.elasticsearch.transport.TransportMessage;
1919

2020
import java.util.List;
2121
import java.util.Map;
@@ -77,7 +77,7 @@ public void testQueryAndFetch() {
7777
equalTo((long) searchPhase.size())
7878
);
7979
} finally {
80-
fetchPhase.forEach(TransportMessage::decRef);
80+
fetchPhase.forEach(RefCounted::decRef);
8181
}
8282
}
8383

server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.bytes.ReleasableBytesReference;
1616
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1717
import org.elasticsearch.common.io.stream.RecyclerBytesStreamOutput;
18+
import org.elasticsearch.common.io.stream.Writeable;
1819
import org.elasticsearch.common.settings.Settings;
1920
import org.elasticsearch.common.util.MockPageCacheRecycler;
2021
import org.elasticsearch.common.util.concurrent.ThreadContext;
@@ -269,7 +270,7 @@ public void testCompressedDecode() throws IOException {
269270
Compression.Scheme scheme = randomFrom(Compression.Scheme.DEFLATE, Compression.Scheme.LZ4);
270271

271272
try (RecyclerBytesStreamOutput os = new RecyclerBytesStreamOutput(recycler)) {
272-
final TransportMessage transportMessage = isRequest
273+
final Writeable transportMessage = isRequest
273274
? new TestRequest(randomAlphaOfLength(100))
274275
: new TestResponse(randomAlphaOfLength(100));
275276
final BytesReference totalBytes = OutboundHandler.serialize(

server/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void testSendMessage() throws InterruptedException {
159159
TransportActionProxy.registerProxyAction(serviceC, "internal:test", cancellable, SimpleTestResponse::new);
160160
// Node A -> Node B -> Node C: different versions - serialize the response
161161
{
162-
final List<TransportMessage> responses = Collections.synchronizedList(new ArrayList<>());
162+
final List<TransportResponse> responses = Collections.synchronizedList(new ArrayList<>());
163163
final CountDownLatch latch = new CountDownLatch(1);
164164
serviceB.addRequestHandlingBehavior(
165165
TransportActionProxy.getProxyAction("internal:test"),
@@ -212,7 +212,7 @@ public void handleException(TransportException exp) {
212212
{
213213
AbstractSimpleTransportTestCase.connectToNode(serviceD, nodeB);
214214
final CountDownLatch latch = new CountDownLatch(1);
215-
final List<TransportMessage> responses = Collections.synchronizedList(new ArrayList<>());
215+
final List<TransportResponse> responses = Collections.synchronizedList(new ArrayList<>());
216216
serviceB.addRequestHandlingBehavior(
217217
TransportActionProxy.getProxyAction("internal:test"),
218218
(handler, request, channel, task) -> handler.messageReceived(

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/AuthenticationFailureHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.elasticsearch.ElasticsearchSecurityException;
1010
import org.elasticsearch.common.util.concurrent.ThreadContext;
1111
import org.elasticsearch.http.HttpPreRequest;
12-
import org.elasticsearch.transport.TransportMessage;
12+
import org.elasticsearch.transport.TransportRequest;
1313

1414
/**
1515
* A AuthenticationFailureHandler is responsible for the handling of a request that has failed authentication. This must
@@ -51,7 +51,7 @@ public interface AuthenticationFailureHandler {
5151
* @return ElasticsearchSecurityException with the appropriate headers and message
5252
*/
5353
ElasticsearchSecurityException failedAuthentication(
54-
TransportMessage message,
54+
TransportRequest message,
5555
AuthenticationToken token,
5656
String action,
5757
ThreadContext context
@@ -78,7 +78,7 @@ ElasticsearchSecurityException failedAuthentication(
7878
* @param context The context of the request that failed authentication that could not be authenticated
7979
* @return ElasticsearchSecurityException with the appropriate headers and message
8080
*/
81-
ElasticsearchSecurityException exceptionProcessingRequest(TransportMessage message, String action, Exception e, ThreadContext context);
81+
ElasticsearchSecurityException exceptionProcessingRequest(TransportRequest message, String action, Exception e, ThreadContext context);
8282

8383
/**
8484
* This method is called when a REST request is received and no authentication token could be extracted AND anonymous
@@ -99,7 +99,7 @@ ElasticsearchSecurityException failedAuthentication(
9999
* @param context The context of the request that failed authentication that could not be authenticated
100100
* @return ElasticsearchSecurityException with the appropriate headers and message
101101
*/
102-
ElasticsearchSecurityException missingToken(TransportMessage message, String action, ThreadContext context);
102+
ElasticsearchSecurityException missingToken(TransportRequest message, String action, ThreadContext context);
103103

104104
/**
105105
* This method is called when anonymous access is enabled, a request does not pass authorization with the anonymous

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/DefaultAuthenticationFailureHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.elasticsearch.common.util.concurrent.ThreadContext;
1212
import org.elasticsearch.http.HttpPreRequest;
1313
import org.elasticsearch.rest.RestStatus;
14-
import org.elasticsearch.transport.TransportMessage;
14+
import org.elasticsearch.transport.TransportRequest;
1515
import org.elasticsearch.xpack.core.XPackField;
1616

1717
import java.util.ArrayList;
@@ -98,7 +98,7 @@ public ElasticsearchSecurityException failedAuthentication(HttpPreRequest reques
9898

9999
@Override
100100
public ElasticsearchSecurityException failedAuthentication(
101-
TransportMessage message,
101+
TransportRequest message,
102102
AuthenticationToken token,
103103
String action,
104104
ThreadContext context
@@ -118,7 +118,7 @@ public ElasticsearchSecurityException exceptionProcessingRequest(HttpPreRequest
118118

119119
@Override
120120
public ElasticsearchSecurityException exceptionProcessingRequest(
121-
TransportMessage message,
121+
TransportRequest message,
122122
String action,
123123
Exception e,
124124
ThreadContext context
@@ -137,7 +137,7 @@ public ElasticsearchSecurityException missingToken(HttpPreRequest request, Threa
137137
}
138138

139139
@Override
140-
public ElasticsearchSecurityException missingToken(TransportMessage message, String action, ThreadContext context) {
140+
public ElasticsearchSecurityException missingToken(TransportRequest message, String action, ThreadContext context) {
141141
return createAuthenticationError("missing authentication credentials for action [{}]", null, action);
142142
}
143143

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/audit/AuditUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.elasticsearch.common.util.concurrent.ThreadContext;
1414
import org.elasticsearch.common.xcontent.XContentHelper;
1515
import org.elasticsearch.rest.RestRequest;
16-
import org.elasticsearch.transport.TransportMessage;
16+
import org.elasticsearch.transport.TransportRequest;
1717

1818
import java.io.IOException;
1919
import java.util.Arrays;
@@ -37,9 +37,9 @@ public static String restRequestContent(RestRequest request) {
3737
return "";
3838
}
3939

40-
public static Set<String> indices(TransportMessage message) {
41-
if (message instanceof IndicesRequest) {
42-
return arrayToSetOrNull(((IndicesRequest) message).indices());
40+
public static Set<String> indices(TransportRequest message) {
41+
if (message instanceof IndicesRequest indicesRequest) {
42+
return arrayToSetOrNull(indicesRequest.indices());
4343
}
4444
return null;
4545
}

x-pack/qa/security-example-spi-extension/src/main/java/org/elasticsearch/example/realm/CustomAuthenticationFailureHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.elasticsearch.ElasticsearchSecurityException;
1010
import org.elasticsearch.common.util.concurrent.ThreadContext;
1111
import org.elasticsearch.http.HttpPreRequest;
12-
import org.elasticsearch.transport.TransportMessage;
12+
import org.elasticsearch.transport.TransportRequest;
1313
import org.elasticsearch.xpack.core.security.authc.AuthenticationToken;
1414
import org.elasticsearch.xpack.core.security.authc.DefaultAuthenticationFailureHandler;
1515

@@ -31,7 +31,7 @@ public ElasticsearchSecurityException failedAuthentication(HttpPreRequest reques
3131

3232
@Override
3333
public ElasticsearchSecurityException failedAuthentication(
34-
TransportMessage message,
34+
TransportRequest message,
3535
AuthenticationToken token,
3636
String action,
3737
ThreadContext context
@@ -51,7 +51,7 @@ public ElasticsearchSecurityException missingToken(HttpPreRequest request, Threa
5151
}
5252

5353
@Override
54-
public ElasticsearchSecurityException missingToken(TransportMessage message, String action, ThreadContext context) {
54+
public ElasticsearchSecurityException missingToken(TransportRequest message, String action, ThreadContext context) {
5555
ElasticsearchSecurityException e = super.missingToken(message, action, context);
5656
// set a custom header
5757
e.addHeader("WWW-Authenticate", "custom-challenge");

0 commit comments

Comments
 (0)