From 5849646baa5acda8eb22152c148545407de77e57 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 12 Feb 2016 16:16:39 +0100 Subject: [PATCH] Java api: remove needless copy constructors from request classes After #15776 got in, we don't need these copy constructors anymore. When we used to copy requests it was to make sure that headers and context were copied from the parent requests (e.g. index/delete as part of update). This is not a problem anymore. --- .../action/bulk/TransportBulkAction.java | 2 +- .../action/delete/DeleteRequest.java | 23 ------------------- .../elasticsearch/action/get/GetRequest.java | 20 ---------------- .../action/index/IndexRequest.java | 20 ---------------- .../percolate/TransportPercolateAction.java | 5 +--- .../action/search/SearchRequest.java | 17 -------------- .../search/TransportMultiSearchAction.java | 3 +-- .../replication/BasicReplicationRequest.java | 10 -------- .../replication/ReplicationRequest.java | 10 -------- .../action/update/TransportUpdateAction.java | 8 +++---- .../transport/TransportRequest.java | 2 -- 11 files changed, 6 insertions(+), 114 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 9cdce240d7f..52336ccae0b 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -272,7 +272,7 @@ public class TransportBulkAction extends HandledTransportAction(); requestsByShard.put(shardIt.shardId(), list); } - list.add(new BulkItemRequest(i, new DeleteRequest(deleteRequest))); + list.add(new BulkItemRequest(i, deleteRequest)); } } else { ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, deleteRequest.type(), deleteRequest.id(), deleteRequest.routing()).shardId(); diff --git a/core/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java b/core/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java index 6c609eb9f31..cbd10553522 100644 --- a/core/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java +++ b/core/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.delete; -import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.DocumentRequest; import org.elasticsearch.action.support.replication.ReplicationRequest; @@ -80,28 +79,6 @@ public class DeleteRequest extends ReplicationRequest implements this.id = id; } - /** - * Copy constructor that creates a new delete request that is a copy of the one provided as an argument. - */ - public DeleteRequest(DeleteRequest request) { - this(request, request); - } - - /** - * Copy constructor that creates a new delete request that is a copy of the one provided as an argument. - * The new request will inherit though headers and context from the original request that caused it. - */ - public DeleteRequest(DeleteRequest request, ActionRequest originalRequest) { - super(request); - this.type = request.type(); - this.id = request.id(); - this.routing = request.routing(); - this.parent = request.parent(); - this.refresh = request.refresh(); - this.version = request.version(); - this.versionType = request.versionType(); - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); diff --git a/core/src/main/java/org/elasticsearch/action/get/GetRequest.java b/core/src/main/java/org/elasticsearch/action/get/GetRequest.java index 1c83cbeb631..b2f3bc2b018 100644 --- a/core/src/main/java/org/elasticsearch/action/get/GetRequest.java +++ b/core/src/main/java/org/elasticsearch/action/get/GetRequest.java @@ -67,26 +67,6 @@ public class GetRequest extends SingleShardRequest implements Realti type = "_all"; } - /** - * Copy constructor that creates a new get request that is a copy of the one provided as an argument. - * The new request will inherit though headers and context from the original request that caused it. - */ - public GetRequest(GetRequest getRequest) { - this.index = getRequest.index; - this.type = getRequest.type; - this.id = getRequest.id; - this.routing = getRequest.routing; - this.parent = getRequest.parent; - this.preference = getRequest.preference; - this.fields = getRequest.fields; - this.fetchSourceContext = getRequest.fetchSourceContext; - this.refresh = getRequest.refresh; - this.realtime = getRequest.realtime; - this.version = getRequest.version; - this.versionType = getRequest.versionType; - this.ignoreErrorsOnGeneratedFields = getRequest.ignoreErrorsOnGeneratedFields; - } - /** * Constructs a new get request against the specified index. The {@link #type(String)} and {@link #id(String)} * must be set. diff --git a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 336782d16f4..5f2d97051e4 100644 --- a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -159,26 +159,6 @@ public class IndexRequest extends ReplicationRequest implements Do public IndexRequest() { } - /** - * Copy constructor that creates a new index request that is a copy of the one provided as an argument. - * The new request will inherit though headers and context from the original request that caused it. - */ - public IndexRequest(IndexRequest indexRequest) { - super(indexRequest); - this.type = indexRequest.type; - this.id = indexRequest.id; - this.routing = indexRequest.routing; - this.parent = indexRequest.parent; - this.timestamp = indexRequest.timestamp; - this.ttl = indexRequest.ttl; - this.source = indexRequest.source; - this.opType = indexRequest.opType; - this.refresh = indexRequest.refresh; - this.version = indexRequest.version; - this.versionType = indexRequest.versionType; - this.contentType = indexRequest.contentType; - } - /** * Constructs a new index request against the specific index. The {@link #type(String)} * {@link #source(byte[])} must be set. diff --git a/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java b/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java index 0edce177be7..2a8f1a4ed24 100644 --- a/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java +++ b/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java @@ -21,7 +21,6 @@ package org.elasticsearch.action.percolate; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ShardOperationFailedException; -import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.TransportGetAction; import org.elasticsearch.action.support.ActionFilters; @@ -74,9 +73,7 @@ public class TransportPercolateAction extends TransportBroadcastAction listener) { request.startTime = System.currentTimeMillis(); if (request.getRequest() != null) { - //create a new get request to make sure it has the same headers and context as the original percolate request - GetRequest getRequest = new GetRequest(request.getRequest()); - getAction.execute(getRequest, new ActionListener() { + getAction.execute(request.getRequest(), new ActionListener() { @Override public void onResponse(GetResponse getResponse) { if (!getResponse.isExists()) { diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java index 10a1ad2efce..9d3c200ed98 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -76,23 +76,6 @@ public class SearchRequest extends ActionRequest implements Indic public SearchRequest() { } - /** - * Copy constructor that creates a new search request that is a copy of the one provided as an argument. - * The new request will inherit though headers and context from the original request that caused it. - */ - public SearchRequest(SearchRequest searchRequest) { - this.searchType = searchRequest.searchType; - this.indices = searchRequest.indices; - this.routing = searchRequest.routing; - this.preference = searchRequest.preference; - this.template = searchRequest.template; - this.source = searchRequest.source; - this.requestCache = searchRequest.requestCache; - this.scroll = searchRequest.scroll; - this.types = searchRequest.types; - this.indicesOptions = searchRequest.indicesOptions; - } - /** * Constructs a new search request against the indices. No indices provided here means that search * will run against all indices. diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java index 18490735631..43754427598 100644 --- a/core/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java @@ -59,8 +59,7 @@ public class TransportMultiSearchAction extends HandledTransportAction() { + searchAction.execute(request.requests().get(i), new ActionListener() { @Override public void onResponse(SearchResponse searchResponse) { responses.set(index, new MultiSearchResponse.Item(searchResponse, null)); diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/BasicReplicationRequest.java b/core/src/main/java/org/elasticsearch/action/support/replication/BasicReplicationRequest.java index 274d13bf4cf..f431c67b290 100644 --- a/core/src/main/java/org/elasticsearch/action/support/replication/BasicReplicationRequest.java +++ b/core/src/main/java/org/elasticsearch/action/support/replication/BasicReplicationRequest.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.support.replication; -import org.elasticsearch.action.ActionRequest; import org.elasticsearch.index.shard.ShardId; /** @@ -38,13 +37,4 @@ public class BasicReplicationRequest extends ReplicationRequest1m. */ diff --git a/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java b/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java index b60403b00b6..a4053ce857e 100644 --- a/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java +++ b/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java @@ -26,7 +26,6 @@ import org.elasticsearch.action.RoutingMissingException; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; 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.delete.DeleteResponse; import org.elasticsearch.action.delete.TransportDeleteAction; import org.elasticsearch.action.index.IndexRequest; @@ -169,7 +168,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio final UpdateHelper.Result result = updateHelper.prepare(request, indexShard); switch (result.operation()) { case UPSERT: - IndexRequest upsertRequest = new IndexRequest((IndexRequest)result.action()); + IndexRequest upsertRequest = result.action(); // we fetch it from the index request so we don't generate the bytes twice, its already done in the index request final BytesReference upsertSourceBytes = upsertRequest.source(); indexAction.execute(upsertRequest, new ActionListener() { @@ -206,7 +205,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio }); break; case INDEX: - IndexRequest indexRequest = new IndexRequest((IndexRequest)result.action()); + IndexRequest indexRequest = result.action(); // we fetch it from the index request so we don't generate the bytes twice, its already done in the index request final BytesReference indexSourceBytes = indexRequest.source(); indexAction.execute(indexRequest, new ActionListener() { @@ -236,8 +235,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio }); break; case DELETE: - DeleteRequest deleteRequest = new DeleteRequest(result.action(), request); - deleteAction.execute(deleteRequest, new ActionListener() { + deleteAction.execute(result.action(), new ActionListener() { @Override public void onResponse(DeleteResponse response) { UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), false); diff --git a/core/src/main/java/org/elasticsearch/transport/TransportRequest.java b/core/src/main/java/org/elasticsearch/transport/TransportRequest.java index dc396c3d8c0..a367e288674 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportRequest.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportRequest.java @@ -32,7 +32,6 @@ public abstract class TransportRequest extends TransportMessage