TransportInfo to implement Writeable rather than Streamable

This commit is contained in:
javanna 2016-09-01 18:42:25 +02:00 committed by Luca Cavanna
parent 536d13ff11
commit 2b2fb8daed
2 changed files with 30 additions and 43 deletions

View File

@ -214,7 +214,7 @@ public class NodeInfo extends BaseNodeResponse {
threadPool = new ThreadPoolInfo(in);
}
if (in.readBoolean()) {
transport = TransportInfo.readTransportInfo(in);
transport = new TransportInfo(in);
}
if (in.readBoolean()) {
http = new HttpInfo(in);

View File

@ -22,7 +22,7 @@ package org.elasticsearch.transport;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -31,56 +31,17 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class TransportInfo implements Streamable, ToXContent {
public class TransportInfo implements Writeable, ToXContent {
private BoundTransportAddress address;
private Map<String, BoundTransportAddress> profileAddresses;
TransportInfo() {
}
public TransportInfo(BoundTransportAddress address, @Nullable Map<String, BoundTransportAddress> profileAddresses) {
this.address = address;
this.profileAddresses = profileAddresses;
}
static final class Fields {
static final String TRANSPORT = "transport";
static final String BOUND_ADDRESS = "bound_address";
static final String PUBLISH_ADDRESS = "publish_address";
static final String PROFILES = "profiles";
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.TRANSPORT);
builder.array(Fields.BOUND_ADDRESS, (Object[]) address.boundAddresses());
builder.field(Fields.PUBLISH_ADDRESS, address.publishAddress().toString());
builder.startObject(Fields.PROFILES);
if (profileAddresses != null && profileAddresses.size() > 0) {
for (Map.Entry<String, BoundTransportAddress> entry : profileAddresses.entrySet()) {
builder.startObject(entry.getKey());
builder.array(Fields.BOUND_ADDRESS, (Object[]) entry.getValue().boundAddresses());
builder.field(Fields.PUBLISH_ADDRESS, entry.getValue().publishAddress().toString());
builder.endObject();
}
}
builder.endObject();
builder.endObject();
return builder;
}
public static TransportInfo readTransportInfo(StreamInput in) throws IOException {
TransportInfo info = new TransportInfo();
info.readFrom(in);
return info;
}
@Override
public void readFrom(StreamInput in) throws IOException {
public TransportInfo(StreamInput in) throws IOException {
address = BoundTransportAddress.readBoundTransportAddress(in);
int size = in.readVInt();
if (size > 0) {
@ -109,6 +70,32 @@ public class TransportInfo implements Streamable, ToXContent {
}
}
static final class Fields {
static final String TRANSPORT = "transport";
static final String BOUND_ADDRESS = "bound_address";
static final String PUBLISH_ADDRESS = "publish_address";
static final String PROFILES = "profiles";
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.TRANSPORT);
builder.array(Fields.BOUND_ADDRESS, (Object[]) address.boundAddresses());
builder.field(Fields.PUBLISH_ADDRESS, address.publishAddress().toString());
builder.startObject(Fields.PROFILES);
if (profileAddresses != null && profileAddresses.size() > 0) {
for (Map.Entry<String, BoundTransportAddress> entry : profileAddresses.entrySet()) {
builder.startObject(entry.getKey());
builder.array(Fields.BOUND_ADDRESS, (Object[]) entry.getValue().boundAddresses());
builder.field(Fields.PUBLISH_ADDRESS, entry.getValue().publishAddress().toString());
builder.endObject();
}
}
builder.endObject();
builder.endObject();
return builder;
}
public BoundTransportAddress address() {
return address;
}