diff --git a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java index 01069609ac742..20055ee92f187 100644 --- a/server/src/main/java/org/elasticsearch/transport/InboundHandler.java +++ b/server/src/main/java/org/elasticsearch/transport/InboundHandler.java @@ -32,8 +32,8 @@ import java.nio.ByteBuffer; /** - * Handles inbound messages by first deserializing a {@link TransportMessage} from an {@link InboundMessage} and then passing - * it to the appropriate handler. + * Handles inbound messages by first deserializing a {@link TransportRequest} or {@link TransportResponse} from an {@link InboundMessage} + * and then passing it to the appropriate handler. */ public class InboundHandler { diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java index c95a155a790fd..b98c6d662f692 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchPhaseControllerTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsExecutors.TaskTrackingConfig; import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor; +import org.elasticsearch.core.RefCounted; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.lucene.grouping.TopFieldGroups; import org.elasticsearch.search.DocValueFormat; @@ -71,7 +72,6 @@ import org.elasticsearch.test.InternalAggregationTestCase; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportMessage; import org.junit.After; import org.junit.Before; @@ -178,7 +178,7 @@ public void testSortDocs() { ScoreDoc[] sortedDocs = SearchPhaseController.sortDocs(true, topDocsList, from, size, reducedCompletionSuggestions).scoreDocs(); assertThat(sortedDocs.length, equalTo(accumulatedLength)); } finally { - results.asList().forEach(TransportMessage::decRef); + results.asList().forEach(RefCounted::decRef); } } @@ -212,7 +212,7 @@ public void testSortDocsIsIdempotent() throws Exception { } sortedDocs = SearchPhaseController.sortDocs(ignoreFrom, topDocsList, from, size, Collections.emptyList()).scoreDocs(); } finally { - results.asList().forEach(TransportMessage::decRef); + results.asList().forEach(RefCounted::decRef); } results = generateSeededQueryResults(randomSeed, nShards, Collections.emptyList(), queryResultSize, useConstantScore); try { @@ -232,7 +232,7 @@ public void testSortDocsIsIdempotent() throws Exception { assertEquals(sortedDocs[i].score, sortedDocs2[i].score, 0.0f); } } finally { - results.asList().forEach(TransportMessage::decRef); + results.asList().forEach(RefCounted::decRef); } } @@ -345,10 +345,10 @@ public void testMerge() { assertThat(mergedResponse.profile(), is(anEmptyMap())); } } finally { - fetchResults.asList().forEach(TransportMessage::decRef); + fetchResults.asList().forEach(RefCounted::decRef); } } finally { - queryResults.asList().forEach(TransportMessage::decRef); + queryResults.asList().forEach(RefCounted::decRef); } } } @@ -424,11 +424,11 @@ protected boolean lessThan(RankDoc a, RankDoc b) { assertThat(mergedResponse.hits().getHits().length, equalTo(reducedQueryPhase.sortedTopDocs().scoreDocs().length)); assertThat(mergedResponse.profile(), is(anEmptyMap())); } finally { - fetchResults.asList().forEach(TransportMessage::decRef); + fetchResults.asList().forEach(RefCounted::decRef); } } finally { - queryResults.asList().forEach(TransportMessage::decRef); + queryResults.asList().forEach(RefCounted::decRef); } } } diff --git a/server/src/test/java/org/elasticsearch/search/profile/SearchProfileResultsBuilderTests.java b/server/src/test/java/org/elasticsearch/search/profile/SearchProfileResultsBuilderTests.java index cd9249c98de3e..629e51b352b89 100644 --- a/server/src/test/java/org/elasticsearch/search/profile/SearchProfileResultsBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/search/profile/SearchProfileResultsBuilderTests.java @@ -10,12 +10,12 @@ package org.elasticsearch.search.profile; import org.elasticsearch.common.util.Maps; +import org.elasticsearch.core.RefCounted; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.fetch.FetchSearchResult; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.transport.TransportMessage; import java.util.List; import java.util.Map; @@ -77,7 +77,7 @@ public void testQueryAndFetch() { equalTo((long) searchPhase.size()) ); } finally { - fetchPhase.forEach(TransportMessage::decRef); + fetchPhase.forEach(RefCounted::decRef); } } diff --git a/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java b/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java index 34a7fb9cf167d..d91d2cfb4bae3 100644 --- a/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java +++ b/server/src/test/java/org/elasticsearch/transport/InboundDecoderTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.bytes.ReleasableBytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.RecyclerBytesStreamOutput; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.MockPageCacheRecycler; import org.elasticsearch.common.util.concurrent.ThreadContext; @@ -376,7 +377,7 @@ public void testCompressedDecode() throws IOException { Compression.Scheme scheme = randomFrom(Compression.Scheme.DEFLATE, Compression.Scheme.LZ4); try (RecyclerBytesStreamOutput os = new RecyclerBytesStreamOutput(recycler)) { - final TransportMessage transportMessage = isRequest + final Writeable transportMessage = isRequest ? new TestRequest(randomAlphaOfLength(100)) : new TestResponse(randomAlphaOfLength(100)); final BytesReference totalBytes = OutboundHandler.serialize( diff --git a/server/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java b/server/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java index 46585ac382583..7b0a9f6ccbed4 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportActionProxyTests.java @@ -159,7 +159,7 @@ public void testSendMessage() throws InterruptedException { TransportActionProxy.registerProxyAction(serviceC, "internal:test", cancellable, SimpleTestResponse::new); // Node A -> Node B -> Node C: different versions - serialize the response { - final List responses = Collections.synchronizedList(new ArrayList<>()); + final List responses = Collections.synchronizedList(new ArrayList<>()); final CountDownLatch latch = new CountDownLatch(1); serviceB.addRequestHandlingBehavior( TransportActionProxy.getProxyAction("internal:test"), @@ -212,7 +212,7 @@ public void handleException(TransportException exp) { { AbstractSimpleTransportTestCase.connectToNode(serviceD, nodeB); final CountDownLatch latch = new CountDownLatch(1); - final List responses = Collections.synchronizedList(new ArrayList<>()); + final List responses = Collections.synchronizedList(new ArrayList<>()); serviceB.addRequestHandlingBehavior( TransportActionProxy.getProxyAction("internal:test"), (handler, request, channel, task) -> handler.messageReceived( diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/AuthenticationFailureHandler.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/AuthenticationFailureHandler.java index 6a2cf608d21df..682072598c04f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/AuthenticationFailureHandler.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/AuthenticationFailureHandler.java @@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.http.HttpPreRequest; -import org.elasticsearch.transport.TransportMessage; +import org.elasticsearch.transport.TransportRequest; /** * A AuthenticationFailureHandler is responsible for the handling of a request that has failed authentication. This must @@ -51,7 +51,7 @@ public interface AuthenticationFailureHandler { * @return ElasticsearchSecurityException with the appropriate headers and message */ ElasticsearchSecurityException failedAuthentication( - TransportMessage message, + TransportRequest message, AuthenticationToken token, String action, ThreadContext context @@ -78,7 +78,7 @@ ElasticsearchSecurityException failedAuthentication( * @param context The context of the request that failed authentication that could not be authenticated * @return ElasticsearchSecurityException with the appropriate headers and message */ - ElasticsearchSecurityException exceptionProcessingRequest(TransportMessage message, String action, Exception e, ThreadContext context); + ElasticsearchSecurityException exceptionProcessingRequest(TransportRequest message, String action, Exception e, ThreadContext context); /** * 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( * @param context The context of the request that failed authentication that could not be authenticated * @return ElasticsearchSecurityException with the appropriate headers and message */ - ElasticsearchSecurityException missingToken(TransportMessage message, String action, ThreadContext context); + ElasticsearchSecurityException missingToken(TransportRequest message, String action, ThreadContext context); /** * This method is called when anonymous access is enabled, a request does not pass authorization with the anonymous diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/DefaultAuthenticationFailureHandler.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/DefaultAuthenticationFailureHandler.java index c9b30a826248a..21a316f2cd1ec 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/DefaultAuthenticationFailureHandler.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/DefaultAuthenticationFailureHandler.java @@ -11,7 +11,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.http.HttpPreRequest; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.transport.TransportMessage; +import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.xpack.core.XPackField; import java.util.ArrayList; @@ -98,7 +98,7 @@ public ElasticsearchSecurityException failedAuthentication(HttpPreRequest reques @Override public ElasticsearchSecurityException failedAuthentication( - TransportMessage message, + TransportRequest message, AuthenticationToken token, String action, ThreadContext context @@ -118,7 +118,7 @@ public ElasticsearchSecurityException exceptionProcessingRequest(HttpPreRequest @Override public ElasticsearchSecurityException exceptionProcessingRequest( - TransportMessage message, + TransportRequest message, String action, Exception e, ThreadContext context @@ -137,7 +137,7 @@ public ElasticsearchSecurityException missingToken(HttpPreRequest request, Threa } @Override - public ElasticsearchSecurityException missingToken(TransportMessage message, String action, ThreadContext context) { + public ElasticsearchSecurityException missingToken(TransportRequest message, String action, ThreadContext context) { return createAuthenticationError("missing authentication credentials for action [{}]", null, action); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/audit/AuditUtil.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/audit/AuditUtil.java index 58516b1d8324d..c584945bc3bd2 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/audit/AuditUtil.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/audit/AuditUtil.java @@ -13,7 +13,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.transport.TransportMessage; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; import java.util.Arrays; @@ -37,9 +37,9 @@ public static String restRequestContent(RestRequest request) { return ""; } - public static Set indices(TransportMessage message) { - if (message instanceof IndicesRequest) { - return arrayToSetOrNull(((IndicesRequest) message).indices()); + public static Set indices(TransportRequest message) { + if (message instanceof IndicesRequest indicesRequest) { + return arrayToSetOrNull(indicesRequest.indices()); } return null; } diff --git a/x-pack/qa/security-example-spi-extension/src/main/java/org/elasticsearch/example/realm/CustomAuthenticationFailureHandler.java b/x-pack/qa/security-example-spi-extension/src/main/java/org/elasticsearch/example/realm/CustomAuthenticationFailureHandler.java index a6e545070d92f..6f28660dc8423 100644 --- a/x-pack/qa/security-example-spi-extension/src/main/java/org/elasticsearch/example/realm/CustomAuthenticationFailureHandler.java +++ b/x-pack/qa/security-example-spi-extension/src/main/java/org/elasticsearch/example/realm/CustomAuthenticationFailureHandler.java @@ -9,7 +9,7 @@ import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.http.HttpPreRequest; -import org.elasticsearch.transport.TransportMessage; +import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.xpack.core.security.authc.AuthenticationToken; import org.elasticsearch.xpack.core.security.authc.DefaultAuthenticationFailureHandler; @@ -31,7 +31,7 @@ public ElasticsearchSecurityException failedAuthentication(HttpPreRequest reques @Override public ElasticsearchSecurityException failedAuthentication( - TransportMessage message, + TransportRequest message, AuthenticationToken token, String action, ThreadContext context @@ -51,7 +51,7 @@ public ElasticsearchSecurityException missingToken(HttpPreRequest request, Threa } @Override - public ElasticsearchSecurityException missingToken(TransportMessage message, String action, ThreadContext context) { + public ElasticsearchSecurityException missingToken(TransportRequest message, String action, ThreadContext context) { ElasticsearchSecurityException e = super.missingToken(message, action, context); // set a custom header e.addHeader("WWW-Authenticate", "custom-challenge");