Skip to content

Commit 613c70c

Browse files
committed
introduce TransportResponse
a class that needs to be used when sending a response over the transport layer, with an option to have headers
1 parent 1545327 commit 613c70c

File tree

91 files changed

+577
-640
lines changed

Some content is hidden

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

91 files changed

+577
-640
lines changed

src/main/java/org/elasticsearch/action/ActionResponse.java

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

2020
package org.elasticsearch.action;
2121

22-
import org.elasticsearch.common.io.stream.Streamable;
22+
import org.elasticsearch.common.io.stream.StreamInput;
23+
import org.elasticsearch.common.io.stream.StreamOutput;
24+
import org.elasticsearch.transport.TransportResponse;
25+
26+
import java.io.IOException;
2327

2428
/**
2529
*
2630
*/
27-
public interface ActionResponse extends Streamable {
31+
public abstract class ActionResponse extends TransportResponse {
32+
33+
@Override
34+
public void readFrom(StreamInput in) throws IOException {
35+
super.readFrom(in);
36+
}
37+
38+
@Override
39+
public void writeTo(StreamOutput out) throws IOException {
40+
super.writeTo(out);
41+
}
2842
}

src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,19 @@
3636
/**
3737
*
3838
*/
39-
public class ClusterHealthResponse implements ActionResponse, Iterable<ClusterIndexHealth> {
39+
public class ClusterHealthResponse extends ActionResponse implements Iterable<ClusterIndexHealth> {
4040

4141
private String clusterName;
42-
4342
int numberOfNodes = 0;
44-
4543
int numberOfDataNodes = 0;
46-
4744
int activeShards = 0;
48-
4945
int relocatingShards = 0;
50-
5146
int activePrimaryShards = 0;
52-
5347
int initializingShards = 0;
54-
5548
int unassignedShards = 0;
56-
5749
boolean timedOut = false;
58-
5950
ClusterHealthStatus status = ClusterHealthStatus.RED;
60-
6151
private List<String> validationFailures;
62-
6352
Map<String, ClusterIndexHealth> indices = Maps.newHashMap();
6453

6554
ClusterHealthResponse() {
@@ -201,7 +190,8 @@ public Iterator<ClusterIndexHealth> iterator() {
201190

202191
@Override
203192
public void readFrom(StreamInput in) throws IOException {
204-
clusterName = in.readUTF();
193+
super.readFrom(in);
194+
clusterName = in.readString();
205195
activePrimaryShards = in.readVInt();
206196
activeShards = in.readVInt();
207197
relocatingShards = in.readVInt();
@@ -221,14 +211,15 @@ public void readFrom(StreamInput in) throws IOException {
221211
validationFailures = ImmutableList.of();
222212
} else {
223213
for (int i = 0; i < size; i++) {
224-
validationFailures.add(in.readUTF());
214+
validationFailures.add(in.readString());
225215
}
226216
}
227217
}
228218

229219
@Override
230220
public void writeTo(StreamOutput out) throws IOException {
231-
out.writeUTF(clusterName);
221+
super.writeTo(out);
222+
out.writeString(clusterName);
232223
out.writeVInt(activePrimaryShards);
233224
out.writeVInt(activeShards);
234225
out.writeVInt(relocatingShards);

src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/NodesShutdownResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
/**
3131
*
3232
*/
33-
public class NodesShutdownResponse implements ActionResponse {
33+
public class NodesShutdownResponse extends ActionResponse {
3434

3535
private ClusterName clusterName;
36-
3736
private DiscoveryNode[] nodes;
3837

3938
NodesShutdownResponse() {
@@ -62,6 +61,7 @@ public DiscoveryNode[] getNodes() {
6261

6362
@Override
6463
public void readFrom(StreamInput in) throws IOException {
64+
super.readFrom(in);
6565
clusterName = ClusterName.readClusterName(in);
6666
nodes = new DiscoveryNode[in.readVInt()];
6767
for (int i = 0; i < nodes.length; i++) {
@@ -71,6 +71,7 @@ public void readFrom(StreamInput in) throws IOException {
7171

7272
@Override
7373
public void writeTo(StreamOutput out) throws IOException {
74+
super.writeTo(out);
7475
clusterName.writeTo(out);
7576
out.writeVInt(nodes.length);
7677
for (DiscoveryNode node : nodes) {

src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.elasticsearch.common.inject.Inject;
3131
import org.elasticsearch.common.io.stream.StreamInput;
3232
import org.elasticsearch.common.io.stream.StreamOutput;
33-
import org.elasticsearch.common.io.stream.VoidStreamable;
3433
import org.elasticsearch.common.settings.Settings;
3534
import org.elasticsearch.common.unit.TimeValue;
3635
import org.elasticsearch.node.Node;
@@ -47,11 +46,8 @@
4746
public class TransportNodesShutdownAction extends TransportMasterNodeOperationAction<NodesShutdownRequest, NodesShutdownResponse> {
4847

4948
private final Node node;
50-
5149
private final ClusterName clusterName;
52-
5350
private final boolean disabled;
54-
5551
private final TimeValue delay;
5652

5753
@Inject
@@ -128,9 +124,9 @@ public void run() {
128124
latch.countDown();
129125
} else {
130126
logger.trace("[cluster_shutdown]: sending shutdown request to [{}]", node);
131-
transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new VoidTransportResponseHandler(ThreadPool.Names.SAME) {
127+
transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
132128
@Override
133-
public void handleResponse(VoidStreamable response) {
129+
public void handleResponse(TransportResponse.Empty response) {
134130
logger.trace("[cluster_shutdown]: received shutdown response from [{}]", node);
135131
latch.countDown();
136132
}
@@ -152,9 +148,9 @@ public void handleException(TransportException exp) {
152148

153149
// now, kill the master
154150
logger.trace("[cluster_shutdown]: shutting down the master [{}]", state.nodes().masterNode());
155-
transportService.sendRequest(state.nodes().masterNode(), NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new VoidTransportResponseHandler(ThreadPool.Names.SAME) {
151+
transportService.sendRequest(state.nodes().masterNode(), NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
156152
@Override
157-
public void handleResponse(VoidStreamable response) {
153+
public void handleResponse(TransportResponse.Empty response) {
158154
logger.trace("[cluster_shutdown]: received shutdown response from master");
159155
}
160156

@@ -196,9 +192,9 @@ public void run() {
196192
}
197193

198194
logger.trace("[partial_cluster_shutdown]: sending shutdown request to [{}]", node);
199-
transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new VoidTransportResponseHandler(ThreadPool.Names.SAME) {
195+
transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
200196
@Override
201-
public void handleResponse(VoidStreamable response) {
197+
public void handleResponse(TransportResponse.Empty response) {
202198
logger.trace("[partial_cluster_shutdown]: received shutdown response from [{}]", node);
203199
latch.countDown();
204200
}
@@ -288,7 +284,7 @@ public void run() {
288284
});
289285
t.start();
290286

291-
channel.sendResponse(VoidStreamable.INSTANCE);
287+
channel.sendResponse(TransportResponse.Empty.INSTANCE);
292288
}
293289
}
294290

src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
/**
3030
*/
31-
public class ClusterRerouteResponse implements ActionResponse {
31+
public class ClusterRerouteResponse extends ActionResponse {
3232

3333
private ClusterState state;
3434

@@ -50,11 +50,13 @@ public ClusterState getState() {
5050

5151
@Override
5252
public void readFrom(StreamInput in) throws IOException {
53+
super.readFrom(in);
5354
state = ClusterState.Builder.readFrom(in, null);
5455
}
5556

5657
@Override
5758
public void writeTo(StreamOutput out) throws IOException {
59+
super.writeTo(out);
5860
ClusterState.Builder.writeTo(state, out);
5961
}
6062
}

src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@
2222
import org.elasticsearch.action.ActionResponse;
2323
import org.elasticsearch.common.io.stream.StreamInput;
2424
import org.elasticsearch.common.io.stream.StreamOutput;
25-
import org.elasticsearch.common.io.stream.Streamable;
2625

2726
import java.io.IOException;
2827

2928
/**
3029
* A response for a cluster update settings action.
3130
*/
32-
public class ClusterUpdateSettingsResponse implements ActionResponse, Streamable {
31+
public class ClusterUpdateSettingsResponse extends ActionResponse {
3332

3433
ClusterUpdateSettingsResponse() {
3534
}
3635

3736
@Override
3837
public void readFrom(StreamInput in) throws IOException {
38+
super.readFrom(in);
3939
}
4040

4141
@Override
4242
public void writeTo(StreamOutput out) throws IOException {
43+
super.writeTo(out);
4344
}
4445
}

src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
/**
3131
*
3232
*/
33-
public class ClusterStateResponse implements ActionResponse {
33+
public class ClusterStateResponse extends ActionResponse {
3434

3535
private ClusterName clusterName;
36-
3736
private ClusterState clusterState;
3837

3938
public ClusterStateResponse() {
@@ -62,12 +61,14 @@ public ClusterName getClusterName() {
6261

6362
@Override
6463
public void readFrom(StreamInput in) throws IOException {
64+
super.readFrom(in);
6565
clusterName = ClusterName.readClusterName(in);
6666
clusterState = ClusterState.Builder.readFrom(in, null);
6767
}
6868

6969
@Override
7070
public void writeTo(StreamOutput out) throws IOException {
71+
super.writeTo(out);
7172
clusterName.writeTo(out);
7273
ClusterState.Builder.writeTo(clusterState, out);
7374
}

src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@
2222
import org.elasticsearch.action.ActionResponse;
2323
import org.elasticsearch.common.io.stream.StreamInput;
2424
import org.elasticsearch.common.io.stream.StreamOutput;
25-
import org.elasticsearch.common.io.stream.Streamable;
2625

2726
import java.io.IOException;
2827

2928
/**
3029
* A response for a add/remove alias action.
31-
*
32-
*
3330
*/
34-
public class IndicesAliasesResponse implements ActionResponse, Streamable {
31+
public class IndicesAliasesResponse extends ActionResponse {
3532

3633
private boolean acknowledged;
3734

@@ -54,11 +51,13 @@ public boolean getAcknowledged() {
5451

5552
@Override
5653
public void readFrom(StreamInput in) throws IOException {
54+
super.readFrom(in);
5755
acknowledged = in.readBoolean();
5856
}
5957

6058
@Override
6159
public void writeTo(StreamOutput out) throws IOException {
60+
super.writeTo(out);
6261
out.writeBoolean(acknowledged);
6362
}
6463
}

src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeResponse.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/**
3535
*
3636
*/
37-
public class AnalyzeResponse implements ActionResponse, Iterable<AnalyzeResponse.AnalyzeToken>, ToXContent {
37+
public class AnalyzeResponse extends ActionResponse implements Iterable<AnalyzeResponse.AnalyzeToken>, ToXContent {
3838

3939
public static class AnalyzeToken implements Streamable {
4040
private String term;
@@ -102,27 +102,20 @@ public static AnalyzeToken readAnalyzeToken(StreamInput in) throws IOException {
102102

103103
@Override
104104
public void readFrom(StreamInput in) throws IOException {
105-
term = in.readUTF();
105+
term = in.readString();
106106
startOffset = in.readInt();
107107
endOffset = in.readInt();
108108
position = in.readVInt();
109-
if (in.readBoolean()) {
110-
type = in.readUTF();
111-
}
109+
type = in.readOptionalString();
112110
}
113111

114112
@Override
115113
public void writeTo(StreamOutput out) throws IOException {
116-
out.writeUTF(term);
114+
out.writeString(term);
117115
out.writeInt(startOffset);
118116
out.writeInt(endOffset);
119117
out.writeVInt(position);
120-
if (type == null) {
121-
out.writeBoolean(false);
122-
} else {
123-
out.writeBoolean(true);
124-
out.writeUTF(type);
125-
}
118+
out.writeOptionalString(type);
126119
}
127120
}
128121

@@ -186,6 +179,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
186179

187180
@Override
188181
public void readFrom(StreamInput in) throws IOException {
182+
super.readFrom(in);
189183
int size = in.readVInt();
190184
tokens = new ArrayList<AnalyzeToken>(size);
191185
for (int i = 0; i < size; i++) {
@@ -195,6 +189,7 @@ public void readFrom(StreamInput in) throws IOException {
195189

196190
@Override
197191
public void writeTo(StreamOutput out) throws IOException {
192+
super.writeTo(out);
198193
out.writeVInt(tokens.size());
199194
for (AnalyzeToken token : tokens) {
200195
token.writeTo(out);

src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@
2222
import org.elasticsearch.action.ActionResponse;
2323
import org.elasticsearch.common.io.stream.StreamInput;
2424
import org.elasticsearch.common.io.stream.StreamOutput;
25-
import org.elasticsearch.common.io.stream.Streamable;
2625

2726
import java.io.IOException;
2827

2928
/**
3029
* A response for a close index action.
31-
*
32-
*
3330
*/
34-
public class CloseIndexResponse implements ActionResponse, Streamable {
31+
public class CloseIndexResponse extends ActionResponse {
3532

3633
private boolean acknowledged;
3734

@@ -52,11 +49,13 @@ public boolean getAcknowledged() {
5249

5350
@Override
5451
public void readFrom(StreamInput in) throws IOException {
52+
super.readFrom(in);
5553
acknowledged = in.readBoolean();
5654
}
5755

5856
@Override
5957
public void writeTo(StreamOutput out) throws IOException {
58+
super.writeTo(out);
6059
out.writeBoolean(acknowledged);
6160
}
6261
}

0 commit comments

Comments
 (0)