remove Action interface and rename BaseAction to TransportAction (all transport level actions should extend it)

This commit is contained in:
Shay Banon 2012-01-15 01:08:39 +02:00
parent 4b21cf2993
commit 864c2ac96d
21 changed files with 44 additions and 82 deletions

View File

@ -1,32 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action;
import org.elasticsearch.ElasticSearchException;
/**
*
*/
public interface Action<Request extends ActionRequest, Response extends ActionResponse> {
ActionFuture<Response> execute(Request request) throws ElasticSearchException;
void execute(Request request, ActionListener<Response> listener);
}

View File

@ -72,7 +72,7 @@ import org.elasticsearch.action.percolate.TransportPercolateAction;
import org.elasticsearch.action.search.TransportSearchAction;
import org.elasticsearch.action.search.TransportSearchScrollAction;
import org.elasticsearch.action.search.type.*;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.update.TransportUpdateAction;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.MapBinder;
@ -88,10 +88,10 @@ public class TransportActionModule extends AbstractModule {
static class ActionEntry {
public final String name;
public final Class<? extends BaseAction> action;
public final Class<? extends TransportAction> action;
public final Class[] supportActions;
ActionEntry(String name, Class<? extends BaseAction> action, Class... supportActions) {
ActionEntry(String name, Class<? extends TransportAction> action, Class... supportActions) {
this.name = name;
this.action = action;
this.supportActions = supportActions;
@ -111,7 +111,7 @@ public class TransportActionModule extends AbstractModule {
* @param action The action itself
* @param supportActions Support actions.
*/
public void registerAction(String actionName, Class<? extends BaseAction> action, Class... supportActions) {
public void registerAction(String actionName, Class<? extends TransportAction> action, Class... supportActions) {
actions.put(actionName, new ActionEntry(actionName, action, supportActions));
}
@ -183,8 +183,8 @@ public class TransportActionModule extends AbstractModule {
registerAction(TransportActions.MORE_LIKE_THIS, TransportMoreLikeThisAction.class);
registerAction(TransportActions.PERCOLATE, TransportPercolateAction.class);
MapBinder<String, BaseAction> actionsBinder
= MapBinder.newMapBinder(binder(), String.class, BaseAction.class);
MapBinder<String, TransportAction> actionsBinder
= MapBinder.newMapBinder(binder(), String.class, TransportAction.class);
for (Map.Entry<String, ActionEntry> entry : actions.entrySet()) {
actionsBinder.addBinding(entry.getKey()).to(entry.getValue().action).asEagerSingleton();

View File

@ -31,7 +31,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
@ -57,7 +57,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
*
*/
public class TransportBulkAction extends BaseAction<BulkRequest, BulkResponse> {
public class TransportBulkAction extends TransportAction<BulkRequest, BulkResponse> {
private final boolean autoCreateIndex;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.action.get;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
@ -38,7 +38,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class TransportMultiGetAction extends BaseAction<MultiGetRequest, MultiGetResponse> {
public class TransportMultiGetAction extends TransportAction<MultiGetRequest, MultiGetResponse> {
private final ClusterService clusterService;

View File

@ -30,7 +30,7 @@ import org.elasticsearch.action.get.TransportGetAction;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.TransportSearchAction;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.inject.Inject;
@ -58,10 +58,8 @@ import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
/**
* The more like this action.
*
*
*/
public class TransportMoreLikeThisAction extends BaseAction<MoreLikeThisRequest, SearchResponse> {
public class TransportMoreLikeThisAction extends TransportAction<MoreLikeThisRequest, SearchResponse> {
private final TransportSearchAction searchAction;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.action.search;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.search.type.*;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.inject.Inject;
@ -41,7 +41,7 @@ import static org.elasticsearch.action.search.SearchType.*;
/**
*
*/
public class TransportSearchAction extends BaseAction<SearchRequest, SearchResponse> {
public class TransportSearchAction extends TransportAction<SearchRequest, SearchResponse> {
private final ClusterService clusterService;

View File

@ -26,7 +26,7 @@ import org.elasticsearch.action.search.type.ParsedScrollId;
import org.elasticsearch.action.search.type.TransportSearchScrollQueryAndFetchAction;
import org.elasticsearch.action.search.type.TransportSearchScrollQueryThenFetchAction;
import org.elasticsearch.action.search.type.TransportSearchScrollScanAction;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
@ -40,7 +40,7 @@ import static org.elasticsearch.action.search.type.TransportSearchHelper.parseSc
/**
*
*/
public class TransportSearchScrollAction extends BaseAction<SearchScrollRequest, SearchResponse> {
public class TransportSearchScrollAction extends TransportAction<SearchScrollRequest, SearchResponse> {
private final TransportSearchScrollQueryThenFetchAction queryThenFetchAction;

View File

@ -21,7 +21,7 @@ package org.elasticsearch.action.search.type;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.search.*;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
@ -54,7 +54,7 @@ import static org.elasticsearch.action.search.type.TransportSearchHelper.interna
/**
*
*/
public abstract class TransportSearchTypeAction extends BaseAction<SearchRequest, SearchResponse> {
public abstract class TransportSearchTypeAction extends TransportAction<SearchRequest, SearchResponse> {
protected final ClusterService clusterService;

View File

@ -30,16 +30,15 @@ import static org.elasticsearch.action.support.PlainActionFuture.newFuture;
/**
*
*/
public abstract class BaseAction<Request extends ActionRequest, Response extends ActionResponse> extends AbstractComponent implements Action<Request, Response> {
public abstract class TransportAction<Request extends ActionRequest, Response extends ActionResponse> extends AbstractComponent {
protected final ThreadPool threadPool;
protected BaseAction(Settings settings, ThreadPool threadPool) {
protected TransportAction(Settings settings, ThreadPool threadPool) {
super(settings);
this.threadPool = threadPool;
}
@Override
public ActionFuture<Response> execute(Request request) throws ElasticSearchException {
PlainActionFuture<Response> future = newFuture();
// since we don't have a listener, and we release a possible lock with the future
@ -49,7 +48,6 @@ public abstract class BaseAction<Request extends ActionRequest, Response extends
return future;
}
@Override
public void execute(Request request, ActionListener<Response> listener) {
if (request.listenerThreaded()) {
listener = new ThreadedActionListener<Response>(threadPool, listener);

View File

@ -21,7 +21,7 @@ package org.elasticsearch.action.support.broadcast;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
@ -42,7 +42,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
*
*/
public abstract class TransportBroadcastOperationAction<Request extends BroadcastOperationRequest, Response extends BroadcastOperationResponse, ShardRequest extends BroadcastShardOperationRequest, ShardResponse extends BroadcastShardOperationResponse>
extends BaseAction<Request, Response> {
extends TransportAction<Request, Response> {
protected final ClusterService clusterService;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.action.support.master;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -38,10 +38,8 @@ import org.elasticsearch.transport.*;
/**
* A base class for operations that needs to be performed on the master node.
*
*
*/
public abstract class TransportMasterNodeOperationAction<Request extends MasterNodeOperationRequest, Response extends ActionResponse> extends BaseAction<Request, Response> {
public abstract class TransportMasterNodeOperationAction<Request extends MasterNodeOperationRequest, Response extends ActionResponse> extends TransportAction<Request, Response> {
protected final TransportService transportService;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.NoSuchNodeException;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -40,7 +40,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
/**
*
*/
public abstract class TransportNodesOperationAction<Request extends NodesOperationRequest, Response extends NodesOperationResponse, NodeRequest extends NodeOperationRequest, NodeResponse extends NodeOperationResponse> extends BaseAction<Request, Response> {
public abstract class TransportNodesOperationAction<Request extends NodesOperationRequest, Response extends NodesOperationResponse, NodeRequest extends NodeOperationRequest, NodeResponse extends NodeOperationResponse> extends TransportAction<Request, Response> {
protected final ClusterName clusterName;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
@ -43,7 +43,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
*
*/
public abstract class TransportIndexReplicationOperationAction<Request extends IndexReplicationOperationRequest, Response extends ActionResponse, ShardRequest extends ShardReplicationOperationRequest, ShardReplicaRequest extends ActionRequest, ShardResponse extends ActionResponse>
extends BaseAction<Request, Response> {
extends TransportAction<Request, Response> {
protected final ClusterService clusterService;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.action.support.replication;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
@ -42,7 +42,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
*/
public abstract class TransportIndicesReplicationOperationAction<Request extends IndicesReplicationOperationRequest, Response extends ActionResponse, IndexRequest extends IndexReplicationOperationRequest, IndexResponse extends ActionResponse,
ShardRequest extends ShardReplicationOperationRequest, ShardReplicaRequest extends ActionRequest, ShardResponse extends ActionResponse>
extends BaseAction<Request, Response> {
extends TransportAction<Request, Response> {
protected final ClusterService clusterService;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.action.support.replication;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.*;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -59,7 +59,7 @@ import static org.elasticsearch.ExceptionsHelper.detailedMessage;
/**
*/
public abstract class TransportShardReplicationOperationAction<Request extends ShardReplicationOperationRequest, ReplicaRequest extends ActionRequest, Response extends ActionResponse> extends BaseAction<Request, Response> {
public abstract class TransportShardReplicationOperationAction<Request extends ShardReplicationOperationRequest, ReplicaRequest extends ActionRequest, Response extends ActionResponse> extends TransportAction<Request, Response> {
protected final TransportService transportService;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.NoShardAvailableActionException;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
@ -43,7 +43,7 @@ import java.io.IOException;
/**
*
*/
public abstract class TransportSingleCustomOperationAction<Request extends SingleCustomOperationRequest, Response extends ActionResponse> extends BaseAction<Request, Response> {
public abstract class TransportSingleCustomOperationAction<Request extends SingleCustomOperationRequest, Response extends ActionResponse> extends TransportAction<Request, Response> {
protected final ClusterService clusterService;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.UnavailableShardsException;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -46,7 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
/**
*
*/
public abstract class TransportInstanceSingleOperationAction<Request extends InstanceShardOperationRequest, Response extends ActionResponse> extends BaseAction<Request, Response> {
public abstract class TransportInstanceSingleOperationAction<Request extends InstanceShardOperationRequest, Response extends ActionResponse> extends TransportAction<Request, Response> {
protected final ClusterService clusterService;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.NoShardAvailableActionException;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
@ -44,7 +44,7 @@ import java.io.IOException;
/**
*
*/
public abstract class TransportShardSingleOperationAction<Request extends SingleShardOperationRequest, Response extends ActionResponse> extends BaseAction<Request, Response> {
public abstract class TransportShardSingleOperationAction<Request extends SingleShardOperationRequest, Response extends ActionResponse> extends TransportAction<Request, Response> {
protected final ClusterService clusterService;

View File

@ -44,7 +44,7 @@ import org.elasticsearch.action.percolate.PercolateRequest;
import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.action.percolate.TransportPercolateAction;
import org.elasticsearch.action.search.*;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.update.TransportUpdateAction;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
@ -91,7 +91,7 @@ public class NodeClient extends AbstractClient implements InternalClient {
private final TransportPercolateAction percolateAction;
@Inject
public NodeClient(Settings settings, ThreadPool threadPool, NodeAdminClient admin, Map<String, BaseAction> actions) {
public NodeClient(Settings settings, ThreadPool threadPool, NodeAdminClient admin, Map<String, TransportAction> actions) {
this.threadPool = threadPool;
this.admin = admin;
this.indexAction = (TransportIndexAction) actions.get(TransportActions.INDEX);

View File

@ -55,7 +55,7 @@ import org.elasticsearch.action.admin.cluster.settings.TransportClusterUpdateSet
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.client.internal.InternalClusterAdminClient;
import org.elasticsearch.client.support.AbstractClusterAdminClient;
import org.elasticsearch.common.inject.Inject;
@ -94,7 +94,7 @@ public class NodeClusterAdminClient extends AbstractClusterAdminClient implement
private final TransportNodesRestartAction nodesRestart;
@Inject
public NodeClusterAdminClient(Settings settings, ThreadPool threadPool, Map<String, BaseAction> actions) {
public NodeClusterAdminClient(Settings settings, ThreadPool threadPool, Map<String, TransportAction> actions) {
this.threadPool = threadPool;
this.clusterRerouteAction = (TransportClusterRerouteAction) actions.get(TransportActions.Admin.Cluster.REROUTE);
this.clusterHealthAction = (TransportClusterHealthAction) actions.get(TransportActions.Admin.Cluster.HEALTH);

View File

@ -85,7 +85,7 @@ import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemp
import org.elasticsearch.action.admin.indices.validate.query.TransportValidateQueryAction;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.action.support.BaseAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.support.AbstractIndicesAdminClient;
import org.elasticsearch.common.inject.Inject;
@ -144,7 +144,7 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
private final TransportValidateQueryAction validateQueryAction;
@Inject
public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, Map<String, BaseAction> actions) {
public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, Map<String, TransportAction> actions) {
this.threadPool = threadPool;
this.indicesExistsAction = (TransportIndicesExistsAction) actions.get(TransportActions.Admin.Indices.EXISTS);
this.indicesStatsAction = (TransportIndicesStatsAction) actions.get(TransportActions.Admin.Indices.STATS);