Skip to content

Commit e6444d3

Browse files
authored
Add StreamableResponseAction to aid in deprecation of Streamable (#43770)
The Action base class currently works for both Streamable and Writeable response types. This commit intorduces StreamableResponseAction, for which only the legacy Action implementions which provide newResponse() will extend. This eliminates the need for overriding newResponse() with an UnsupportedOperationException. relates #34389
1 parent 5ac7ec2 commit e6444d3

File tree

277 files changed

+346
-934
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+346
-934
lines changed

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/NoopBulkAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
*/
1919
package org.elasticsearch.plugin.noop.action.bulk;
2020

21-
import org.elasticsearch.action.Action;
21+
import org.elasticsearch.action.StreamableResponseAction;
2222
import org.elasticsearch.action.bulk.BulkResponse;
2323

24-
public class NoopBulkAction extends Action<BulkResponse> {
24+
public class NoopBulkAction extends StreamableResponseAction<BulkResponse> {
2525
public static final String NAME = "mock:data/write/bulk";
2626

2727
public static final NoopBulkAction INSTANCE = new NoopBulkAction();

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ private NoopSearchAction() {
3030
super(NAME);
3131
}
3232

33-
@Override
34-
public SearchResponse newResponse() {
35-
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
36-
}
37-
3833
@Override
3934
public Writeable.Reader<SearchResponse> getResponseReader() {
4035
return SearchResponse::new;

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
package org.elasticsearch.ingest.common;
2020

21-
import org.elasticsearch.action.Action;
2221
import org.elasticsearch.action.ActionListener;
2322
import org.elasticsearch.action.ActionRequest;
2423
import org.elasticsearch.action.ActionRequestValidationException;
2524
import org.elasticsearch.action.ActionResponse;
25+
import org.elasticsearch.action.StreamableResponseAction;
2626
import org.elasticsearch.action.support.ActionFilters;
2727
import org.elasticsearch.action.support.HandledTransportAction;
2828
import org.elasticsearch.client.node.NodeClient;
@@ -45,7 +45,7 @@
4545
import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
4646
import static org.elasticsearch.rest.RestRequest.Method.GET;
4747

48-
public class GrokProcessorGetAction extends Action<GrokProcessorGetAction.Response> {
48+
public class GrokProcessorGetAction extends StreamableResponseAction<GrokProcessorGetAction.Response> {
4949

5050
static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction();
5151
static final String NAME = "cluster:admin/ingest/processor/grok/get";

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ private MultiSearchTemplateAction() {
3131
super(NAME);
3232
}
3333

34-
@Override
35-
public MultiSearchTemplateResponse newResponse() {
36-
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
37-
}
38-
3934
@Override
4035
public Writeable.Reader<MultiSearchTemplateResponse> getResponseReader() {
4136
return MultiSearchTemplateResponse::new;

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ private SearchTemplateAction() {
3131
super(NAME);
3232
}
3333

34-
@Override
35-
public SearchTemplateResponse newResponse() {
36-
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
37-
}
38-
3934
@Override
4035
public Writeable.Reader<SearchTemplateResponse> getResponseReader() {
4136
return SearchTemplateResponse::new;

modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ private PainlessContextAction() {
7575
super(NAME);
7676
}
7777

78-
@Override
79-
public Response newResponse() {
80-
throw new UnsupportedOperationException();
81-
}
82-
8378
@Override
8479
public Writeable.Reader<Response> getResponseReader() {
8580
return Response::new;

modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ private PainlessExecuteAction() {
9999
}
100100

101101
@Override
102-
public Response newResponse() {
103-
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
102+
public Writeable.Reader<Response> getResponseReader() {
103+
return Response::new;
104104
}
105105

106106
public static class Request extends SingleShardRequest<Request> implements ToXContentObject {

modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
package org.elasticsearch.index.rankeval;
2121

22-
import org.elasticsearch.action.Action;
22+
import org.elasticsearch.action.StreamableResponseAction;
2323

2424
/**
2525
* Action for explaining evaluating search ranking results.
2626
*/
27-
public class RankEvalAction extends Action<RankEvalResponse> {
27+
public class RankEvalAction extends StreamableResponseAction<RankEvalResponse> {
2828

2929
public static final RankEvalAction INSTANCE = new RankEvalAction();
3030
public static final String NAME = "indices:data/read/rank_eval";

modules/reindex/src/main/java/org/elasticsearch/index/reindex/RethrottleAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ private RethrottleAction() {
3131
super(NAME);
3232
}
3333

34-
@Override
35-
public ListTasksResponse newResponse() {
36-
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
37-
}
38-
3934
@Override
4035
public Writeable.Reader<ListTasksResponse> getResponseReader() {
4136
return ListTasksResponse::new;

server/src/main/java/org/elasticsearch/action/Action.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,27 @@
2626
/**
2727
* A generic action. Should strive to make it a singleton.
2828
*/
29-
public abstract class Action<Response extends ActionResponse> {
29+
public class Action<Response extends ActionResponse> {
3030

3131
private final String name;
32+
private final Writeable.Reader<Response> responseReader;
3233

3334
/**
3435
* @param name The name of the action, must be unique across actions.
36+
* @deprecated Pass a {@link Writeable.Reader} with {@link }
3537
*/
38+
@Deprecated
3639
protected Action(String name) {
40+
this(name, null);
41+
}
42+
43+
/**
44+
* @param name The name of the action, must be unique across actions.
45+
* @param responseReader A reader for the response type
46+
*/
47+
public Action(String name, Writeable.Reader<Response> responseReader) {
3748
this.name = name;
49+
this.responseReader = responseReader;
3850
}
3951

4052
/**
@@ -44,23 +56,11 @@ public String name() {
4456
return this.name;
4557
}
4658

47-
/**
48-
* Creates a new response instance.
49-
* @deprecated Implement {@link #getResponseReader()} instead and make this method throw an
50-
* {@link UnsupportedOperationException}
51-
*/
52-
@Deprecated
53-
public abstract Response newResponse();
54-
5559
/**
5660
* Get a reader that can create a new instance of the class from a {@link org.elasticsearch.common.io.stream.StreamInput}
5761
*/
5862
public Writeable.Reader<Response> getResponseReader() {
59-
return in -> {
60-
Response response = newResponse();
61-
response.readFrom(in);
62-
return response;
63-
};
63+
return responseReader;
6464
}
6565

6666
/**

0 commit comments

Comments
 (0)