Skip to content

Commit

Permalink
Rename Action to ActionType (#43778)
Browse files Browse the repository at this point in the history
Action is a class that encapsulates meta information about an action
that allows it to be called remotely, specifically the action name and
response type. With recent refactoring, the action class can now be
constructed as a static constant, instead of needing to create a
subclass. This makes the old pattern of creating a singleton INSTANCE
both misnamed and lacking a common placement.

This commit renames Action to ActionType, thus allowing the old INSTANCE
naming pattern to be TYPE on the transport action itself. ActionType
also conveys that this class is also not the action itself, although
this change does not rename any concrete classes as those will be
removed organically as they are converted to TYPE constants.

relates #34389
  • Loading branch information
rjernst authored Jun 29, 2019
1 parent cdfc986 commit b33ffc1
Show file tree
Hide file tree
Showing 347 changed files with 787 additions and 790 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.elasticsearch.plugin.noop.action.bulk;

import org.elasticsearch.action.StreamableResponseAction;
import org.elasticsearch.action.StreamableResponseActionType;
import org.elasticsearch.action.bulk.BulkResponse;

public class NoopBulkAction extends StreamableResponseAction<BulkResponse> {
public class NoopBulkAction extends StreamableResponseActionType<BulkResponse> {
public static final String NAME = "mock:data/write/bulk";

public static final NoopBulkAction INSTANCE = new NoopBulkAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/
package org.elasticsearch.plugin.noop.action.search;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.io.stream.Writeable;

public class NoopSearchAction extends Action<SearchResponse> {
public class NoopSearchAction extends ActionType<SearchResponse> {
public static final NoopSearchAction INSTANCE = new NoopSearchAction();
public static final String NAME = "mock:data/read/search";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.StreamableResponseAction;
import org.elasticsearch.action.StreamableResponseActionType;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.client.node.NodeClient;
Expand All @@ -45,7 +45,7 @@
import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
import static org.elasticsearch.rest.RestRequest.Method.GET;

public class GrokProcessorGetAction extends StreamableResponseAction<GrokProcessorGetAction.Response> {
public class GrokProcessorGetAction extends StreamableResponseActionType<GrokProcessorGetAction.Response> {

static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction();
static final String NAME = "cluster:admin/ingest/processor/grok/get";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

package org.elasticsearch.script.mustache;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.Writeable;

public class MultiSearchTemplateAction extends Action<MultiSearchTemplateResponse> {
public class MultiSearchTemplateAction extends ActionType<MultiSearchTemplateResponse> {

public static final MultiSearchTemplateAction INSTANCE = new MultiSearchTemplateAction();
public static final String NAME = "indices:data/read/msearch/template";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

package org.elasticsearch.script.mustache;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.Writeable;

public class SearchTemplateAction extends Action<SearchTemplateResponse> {
public class SearchTemplateAction extends ActionType<SearchTemplateResponse> {

public static final SearchTemplateAction INSTANCE = new SearchTemplateAction();
public static final String NAME = "indices:data/read/search/template";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.painless.action;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
Expand Down Expand Up @@ -64,7 +64,7 @@
* retrieves all available information about the API for this specific context</li>
* </ul>
*/
public class PainlessContextAction extends Action<PainlessContextAction.Response> {
public class PainlessContextAction extends ActionType<PainlessContextAction.Response> {

public static final PainlessContextAction INSTANCE = new PainlessContextAction();
private static final String NAME = "cluster:admin/scripts/painless/context";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.store.RAMDirectory;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilters;
Expand Down Expand Up @@ -89,7 +89,7 @@
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;

public class PainlessExecuteAction extends Action<PainlessExecuteAction.Response> {
public class PainlessExecuteAction extends ActionType<PainlessExecuteAction.Response> {

public static final PainlessExecuteAction INSTANCE = new PainlessExecuteAction();
private static final String NAME = "cluster:admin/scripts/painless/execute";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package org.elasticsearch.index.rankeval;

import org.elasticsearch.action.StreamableResponseAction;
import org.elasticsearch.action.StreamableResponseActionType;

/**
* Action for explaining evaluating search ranking results.
* ActionType for explaining evaluating search ranking results.
*/
public class RankEvalAction extends StreamableResponseAction<RankEvalResponse> {
public class RankEvalAction extends StreamableResponseActionType<RankEvalResponse> {

public static final RankEvalAction INSTANCE = new RankEvalAction();
public static final String NAME = "indices:data/read/rank_eval";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

package org.elasticsearch.index.rankeval;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;

public class RankEvalRequestBuilder extends ActionRequestBuilder<RankEvalRequest, RankEvalResponse> {

public RankEvalRequestBuilder(ElasticsearchClient client, Action<RankEvalResponse> action,
public RankEvalRequestBuilder(ElasticsearchClient client, ActionType<RankEvalResponse> action,
RankEvalRequest request) {
super(client, action, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.node.NodeClient;
Expand All @@ -38,7 +38,7 @@

public abstract class AbstractBaseReindexRestHandler<
Request extends AbstractBulkByScrollRequest<Request>,
A extends Action<BulkByScrollResponse>
A extends ActionType<BulkByScrollResponse>
> extends BaseRestHandler {

private final A action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -38,7 +38,7 @@
*/
public abstract class AbstractBulkByQueryRestHandler<
Request extends AbstractBulkByScrollRequest<Request>,
A extends Action<BulkByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {
A extends ActionType<BulkByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {

protected AbstractBulkByQueryRestHandler(Settings settings, A action) {
super(settings, action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest;
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
Expand Down Expand Up @@ -61,7 +61,7 @@ private BulkByScrollParallelizationHelper() {}
static <Request extends AbstractBulkByScrollRequest<Request>> void startSlicedAction(
Request request,
BulkByScrollTask task,
Action<BulkByScrollResponse> action,
ActionType<BulkByScrollResponse> action,
ActionListener<BulkByScrollResponse> listener,
Client client,
DiscoveryNode node,
Expand All @@ -85,7 +85,7 @@ static <Request extends AbstractBulkByScrollRequest<Request>> void startSlicedAc
private static <Request extends AbstractBulkByScrollRequest<Request>> void sliceConditionally(
Request request,
BulkByScrollTask task,
Action<BulkByScrollResponse> action,
ActionType<BulkByScrollResponse> action,
ActionListener<BulkByScrollResponse> listener,
Client client,
DiscoveryNode node,
Expand Down Expand Up @@ -118,7 +118,7 @@ private static int countSlicesBasedOnShards(ClusterSearchShardsResponse response

private static <Request extends AbstractBulkByScrollRequest<Request>> void sendSubRequests(
Client client,
Action<BulkByScrollResponse> action,
ActionType<BulkByScrollResponse> action,
String localNodeId,
BulkByScrollTask task,
Request request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
import org.elasticsearch.common.io.stream.Writeable;

public class RethrottleAction extends Action<ListTasksResponse> {
public class RethrottleAction extends ActionType<ListTasksResponse> {
public static final RethrottleAction INSTANCE = new RethrottleAction();
public static final String NAME = "cluster:admin/reindex/rethrottle";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
import org.elasticsearch.action.support.tasks.TasksRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
Expand All @@ -29,7 +29,7 @@
*/
public class RethrottleRequestBuilder extends TasksRequestBuilder<RethrottleRequest, ListTasksResponse, RethrottleRequestBuilder> {
public RethrottleRequestBuilder(ElasticsearchClient client,
Action<ListTasksResponse> action) {
ActionType<ListTasksResponse> action) {
super(client, action, new RethrottleRequest());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
Expand Down Expand Up @@ -761,7 +761,7 @@ private class MyMockClient extends FilterClient {
@Override
@SuppressWarnings("unchecked")
protected <Request extends ActionRequest, Response extends ActionResponse>
void doExecute(Action<Response> action, Request request, ActionListener<Response> listener) {
void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) {
if (false == expectedHeaders.equals(threadPool().getThreadContext().getHeaders())) {
listener.onFailure(
new RuntimeException("Expected " + expectedHeaders + " but got " + threadPool().getThreadContext().getHeaders()));
Expand Down
18 changes: 9 additions & 9 deletions server/src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public void register(ActionHandler<?, ?> handler) {
}

public <Request extends ActionRequest, Response extends ActionResponse> void register(
Action<Response> action, Class<? extends TransportAction<Request, Response>> transportAction) {
ActionType<Response> action, Class<? extends TransportAction<Request, Response>> transportAction) {
register(new ActionHandler<>(action, transportAction));
}
}
Expand Down Expand Up @@ -460,7 +460,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(CloseIndexAction.INSTANCE, TransportCloseIndexAction.class);
actions.register(GetMappingsAction.INSTANCE, TransportGetMappingsAction.class);
actions.register(GetFieldMappingsAction.INSTANCE, TransportGetFieldMappingsAction.class);
actions.register(TransportGetFieldMappingsIndexAction.ACTION_INSTANCE, TransportGetFieldMappingsIndexAction.class);
actions.register(TransportGetFieldMappingsIndexAction.TYPE, TransportGetFieldMappingsIndexAction.class);
actions.register(PutMappingAction.INSTANCE, TransportPutMappingAction.class);
actions.register(IndicesAliasesAction.INSTANCE, TransportIndicesAliasesAction.class);
actions.register(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class);
Expand All @@ -484,13 +484,13 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(GetAction.INSTANCE, TransportGetAction.class);
actions.register(TermVectorsAction.INSTANCE, TransportTermVectorsAction.class);
actions.register(MultiTermVectorsAction.INSTANCE, TransportMultiTermVectorsAction.class);
actions.register(TransportShardMultiTermsVectorAction.ACTION_INSTANCE, TransportShardMultiTermsVectorAction.class);
actions.register(TransportShardMultiTermsVectorAction.TYPE, TransportShardMultiTermsVectorAction.class);
actions.register(DeleteAction.INSTANCE, TransportDeleteAction.class);
actions.register(UpdateAction.INSTANCE, TransportUpdateAction.class);
actions.register(MultiGetAction.INSTANCE, TransportMultiGetAction.class);
actions.register(TransportShardMultiGetAction.ACTION_INSTANCE, TransportShardMultiGetAction.class);
actions.register(TransportShardMultiGetAction.TYPE, TransportShardMultiGetAction.class);
actions.register(BulkAction.INSTANCE, TransportBulkAction.class);
actions.register(TransportShardBulkAction.ACTION_INSTANCE, TransportShardBulkAction.class);
actions.register(TransportShardBulkAction.TYPE, TransportShardBulkAction.class);
actions.register(SearchAction.INSTANCE, TransportSearchAction.class);
actions.register(SearchScrollAction.INSTANCE, TransportSearchScrollAction.class);
actions.register(MultiSearchAction.INSTANCE, TransportMultiSearchAction.class);
Expand All @@ -505,7 +505,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(DeleteStoredScriptAction.INSTANCE, TransportDeleteStoredScriptAction.class);

actions.register(FieldCapabilitiesAction.INSTANCE, TransportFieldCapabilitiesAction.class);
actions.register(TransportFieldCapabilitiesIndexAction.ACTION_INSTANCE, TransportFieldCapabilitiesIndexAction.class);
actions.register(TransportFieldCapabilitiesIndexAction.TYPE, TransportFieldCapabilitiesIndexAction.class);

actions.register(PutPipelineAction.INSTANCE, PutPipelineTransportAction.class);
actions.register(GetPipelineAction.INSTANCE, GetPipelineTransportAction.class);
Expand Down Expand Up @@ -684,10 +684,10 @@ protected void configure() {
bind(AutoCreateIndex.class).toInstance(autoCreateIndex);
bind(TransportLivenessAction.class).asEagerSingleton();

// register Action -> transportAction Map used by NodeClient
// register ActionType -> transportAction Map used by NodeClient
@SuppressWarnings("rawtypes")
MapBinder<Action, TransportAction> transportActionsBinder
= MapBinder.newMapBinder(binder(), Action.class, TransportAction.class);
MapBinder<ActionType, TransportAction> transportActionsBinder
= MapBinder.newMapBinder(binder(), ActionType.class, TransportAction.class);
for (ActionHandler<?, ?> action : actions.values()) {
// bind the action as eager singleton, so the map binder one will reuse it
bind(action.getTransportAction()).asEagerSingleton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

public abstract class ActionRequestBuilder<Request extends ActionRequest, Response extends ActionResponse> {

protected final Action<Response> action;
protected final ActionType<Response> action;
protected final Request request;
protected final ElasticsearchClient client;

protected ActionRequestBuilder(ElasticsearchClient client, Action<Response> action, Request request) {
protected ActionRequestBuilder(ElasticsearchClient client, ActionType<Response> action, Request request) {
Objects.requireNonNull(action, "action must not be null");
this.action = action;
this.request = request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* A generic action. Should strive to make it a singleton.
*/
public class Action<Response extends ActionResponse> {
public class ActionType<Response extends ActionResponse> {

private final String name;
private final Writeable.Reader<Response> responseReader;
Expand All @@ -36,15 +36,15 @@ public class Action<Response extends ActionResponse> {
* @deprecated Pass a {@link Writeable.Reader} with {@link }
*/
@Deprecated
protected Action(String name) {
protected ActionType(String name) {
this(name, null);
}

/**
* @param name The name of the action, must be unique across actions.
* @param responseReader A reader for the response type
*/
public Action(String name, Writeable.Reader<Response> responseReader) {
public ActionType(String name, Writeable.Reader<Response> responseReader) {
this.name = name;
this.responseReader = responseReader;
}
Expand Down Expand Up @@ -72,7 +72,7 @@ public TransportRequestOptions transportOptions(Settings settings) {

@Override
public boolean equals(Object o) {
return o instanceof Action && name.equals(((Action<?>) o).name());
return o instanceof ActionType && name.equals(((ActionType<?>) o).name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

/**
* An action for with the response type implements {@link org.elasticsearch.common.io.stream.Streamable}.
* @deprecated Use {@link Action} directly and provide a {@link Writeable.Reader}
* @deprecated Use {@link ActionType} directly and provide a {@link Writeable.Reader}
*/
@Deprecated
public abstract class StreamableResponseAction<Response extends ActionResponse> extends Action<Response> {
public abstract class StreamableResponseActionType<Response extends ActionResponse> extends ActionType<Response> {

protected StreamableResponseAction(String name) {
protected StreamableResponseActionType(String name) {
super(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
public class TransportActionNodeProxy<Request extends ActionRequest, Response extends ActionResponse> {

private final TransportService transportService;
private final Action<Response> action;
private final ActionType<Response> action;
private final TransportRequestOptions transportOptions;

public TransportActionNodeProxy(Settings settings, Action<Response> action, TransportService transportService) {
public TransportActionNodeProxy(Settings settings, ActionType<Response> action, TransportService transportService) {
this.action = action;
this.transportService = transportService;
this.transportOptions = action.transportOptions(settings);
Expand Down
Loading

0 comments on commit b33ffc1

Please sign in to comment.