Remove writeAllocationCommand and writeValueFormat

Replace with writeNamedWriteable. s/write/read/g
This commit is contained in:
Nik Everett 2016-04-18 19:49:27 -04:00
parent c7c120c781
commit 38721ecf7b
29 changed files with 65 additions and 100 deletions

View File

@ -52,13 +52,13 @@ public class RerouteExplanation implements ToXContent {
}
public static RerouteExplanation readFrom(StreamInput in) throws IOException {
AllocationCommand command = in.readAllocationCommand();
AllocationCommand command = in.readNamedWriteable(AllocationCommand.class);
Decision decisions = Decision.readFrom(in);
return new RerouteExplanation(command, decisions);
}
public static void writeTo(RerouteExplanation explanation, StreamOutput out) throws IOException {
out.writeAllocationCommand(explanation.command);
out.writeNamedWriteable(explanation.command);
Decision.writeTo(explanation.decisions, out);
}

View File

@ -96,7 +96,7 @@ public class AllocationCommands {
AllocationCommands commands = new AllocationCommands();
int size = in.readVInt();
for (int i = 0; i < size; i++) {
commands.add(in.readAllocationCommand());
commands.add(in.readNamedWriteable(AllocationCommand.class));
}
return commands;
}
@ -111,7 +111,7 @@ public class AllocationCommands {
public static void writeTo(AllocationCommands commands, StreamOutput out) throws IOException {
out.writeVInt(commands.commands.size());
for (AllocationCommand command : commands.commands) {
out.writeAllocationCommand(command);
out.writeNamedWriteable(command);
}
}

View File

@ -790,24 +790,6 @@ public abstract class StreamInput extends InputStream {
return readNamedWriteable(Task.Status.class);
}
/**
* Reads a {@link DocValueFormat} from the current stream.
* @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link DocValueFormat}.
*/
@Deprecated
public DocValueFormat readValueFormat() throws IOException {
return readNamedWriteable(DocValueFormat.class);
}
/**
* Reads an {@link AllocationCommand} from the stream.
* @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link AllocationCommand}.
*/
@Deprecated
public AllocationCommand readAllocationCommand() throws IOException {
return readNamedWriteable(AllocationCommand.class);
}
/**
* Reads a list of objects
*/

View File

@ -790,22 +790,4 @@ public abstract class StreamOutput extends OutputStream {
public void writeSortBuilder(SortBuilder<?> sort) throws IOException {
writeNamedWriteable(sort);
}
/**
* Writes a {@link DocValueFormat}.
* @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
*/
@Deprecated
public void writeValueFormat(DocValueFormat format) throws IOException {
writeNamedWriteable(format);
}
/**
* Writes an {@link AllocationCommand} to the stream.
* @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
*/
@Deprecated
public void writeAllocationCommand(AllocationCommand command) throws IOException {
writeNamedWriteable(command);
}
}

View File

@ -62,14 +62,14 @@ public class BucketStreamContext implements Streamable {
@Override
public void readFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
keyed = in.readBoolean();
attributes = in.readMap();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeBoolean(keyed);
out.writeMap(attributes);
}

View File

@ -497,7 +497,7 @@ public class InternalHistogram<B extends InternalHistogram.Bucket> extends Inter
if (minDocCount == 0) {
emptyBucketInfo = EmptyBucketInfo.readFrom(in);
}
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
keyed = in.readBoolean();
int size = in.readVInt();
List<B> buckets = new ArrayList<>(size);
@ -528,7 +528,7 @@ public class InternalHistogram<B extends InternalHistogram.Bucket> extends Inter
if (minDocCount == 0) {
EmptyBucketInfo.writeTo(emptyBucketInfo, out);
}
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeBoolean(keyed);
out.writeVInt(buckets.size());
for (B bucket : buckets) {

View File

@ -324,7 +324,7 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
keyed = in.readBoolean();
int size = in.readVInt();
List<B> ranges = new ArrayList<>(size);
@ -338,7 +338,7 @@ public class InternalRange<B extends InternalRange.Bucket, R extends InternalRan
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeBoolean(keyed);
out.writeVInt(ranges.size());
for (B bucket : ranges) {

View File

@ -201,7 +201,7 @@ public class SignificantLongTerms extends InternalSignificantTerms<SignificantLo
@Override
protected void doReadFrom(StreamInput in) throws IOException {
this.format = in.readValueFormat();
this.format = in.readNamedWriteable(DocValueFormat.class);
this.requiredSize = readSize(in);
this.minDocCount = in.readVLong();
this.subsetSize = in.readVLong();
@ -222,7 +222,7 @@ public class SignificantLongTerms extends InternalSignificantTerms<SignificantLo
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
writeSize(requiredSize, out);
out.writeVLong(minDocCount);
out.writeVLong(subsetSize);

View File

@ -190,7 +190,7 @@ public class DoubleTerms extends InternalTerms<DoubleTerms, DoubleTerms.Bucket>
protected void doReadFrom(StreamInput in) throws IOException {
this.docCountError = in.readLong();
this.order = InternalOrder.Streams.readOrder(in);
this.format = in.readValueFormat();
this.format = in.readNamedWriteable(DocValueFormat.class);
this.requiredSize = readSize(in);
this.shardSize = readSize(in);
this.showTermDocCountError = in.readBoolean();
@ -211,7 +211,7 @@ public class DoubleTerms extends InternalTerms<DoubleTerms, DoubleTerms.Bucket>
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeLong(docCountError);
InternalOrder.Streams.writeOrder(order, out);
out.writeValueFormat(format);
out.writeNamedWriteable(format);
writeSize(requiredSize, out);
writeSize(shardSize, out);
out.writeBoolean(showTermDocCountError);

View File

@ -189,7 +189,7 @@ public class LongTerms extends InternalTerms<LongTerms, LongTerms.Bucket> {
protected void doReadFrom(StreamInput in) throws IOException {
this.docCountError = in.readLong();
this.order = InternalOrder.Streams.readOrder(in);
this.format = in.readValueFormat();
this.format = in.readNamedWriteable(DocValueFormat.class);
this.requiredSize = readSize(in);
this.shardSize = readSize(in);
this.showTermDocCountError = in.readBoolean();
@ -210,7 +210,7 @@ public class LongTerms extends InternalTerms<LongTerms, LongTerms.Bucket> {
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeLong(docCountError);
InternalOrder.Streams.writeOrder(order, out);
out.writeValueFormat(format);
out.writeNamedWriteable(format);
writeSize(requiredSize, out);
writeSize(shardSize, out);
out.writeBoolean(showTermDocCountError);

View File

@ -189,7 +189,7 @@ public class StringTerms extends InternalTerms<StringTerms, StringTerms.Bucket>
protected void doReadFrom(StreamInput in) throws IOException {
this.docCountError = in.readLong();
this.order = InternalOrder.Streams.readOrder(in);
this.format = in.readValueFormat();
this.format = in.readNamedWriteable(DocValueFormat.class);
this.requiredSize = readSize(in);
this.shardSize = readSize(in);
this.showTermDocCountError = in.readBoolean();
@ -210,7 +210,7 @@ public class StringTerms extends InternalTerms<StringTerms, StringTerms.Bucket>
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeLong(docCountError);
InternalOrder.Streams.writeOrder(order, out);
out.writeValueFormat(format);
out.writeNamedWriteable(format);
writeSize(requiredSize, out);
writeSize(shardSize, out);
out.writeBoolean(showTermDocCountError);

View File

@ -92,14 +92,14 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
sum = in.readDouble();
count = in.readVLong();
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeDouble(sum);
out.writeVLong(count);
}

View File

@ -23,6 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationStreams;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation;
@ -77,7 +78,7 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
if (in.readBoolean()) {
counts = HyperLogLogPlusPlus.readFrom(in, BigArrays.NON_RECYCLING_INSTANCE);
} else {
@ -87,7 +88,7 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
if (counts != null) {
out.writeBoolean(true);
counts.writeTo(0, out);

View File

@ -88,13 +88,13 @@ public class InternalMax extends InternalNumericMetricsAggregation.SingleValue i
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
max = in.readDouble();
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeDouble(max);
}

View File

@ -89,13 +89,13 @@ public class InternalMin extends InternalNumericMetricsAggregation.SingleValue i
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
min = in.readDouble();
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeDouble(min);
}

View File

@ -82,7 +82,7 @@ abstract class AbstractInternalHDRPercentiles extends InternalNumericMetricsAggr
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
keys = new double[in.readInt()];
for (int i = 0; i < keys.length; ++i) {
keys[i] = in.readDouble();
@ -102,7 +102,7 @@ abstract class AbstractInternalHDRPercentiles extends InternalNumericMetricsAggr
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeInt(keys.length);
for (int i = 0 ; i < keys.length; ++i) {
out.writeDouble(keys[i]);

View File

@ -78,7 +78,7 @@ abstract class AbstractInternalTDigestPercentiles extends InternalNumericMetrics
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
keys = new double[in.readInt()];
for (int i = 0; i < keys.length; ++i) {
keys[i] = in.readDouble();
@ -89,7 +89,7 @@ abstract class AbstractInternalTDigestPercentiles extends InternalNumericMetrics
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeInt(keys.length);
for (int i = 0 ; i < keys.length; ++i) {
out.writeDouble(keys[i]);

View File

@ -165,7 +165,7 @@ public class InternalStats extends InternalNumericMetricsAggregation.MultiValue
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
count = in.readVLong();
min = in.readDouble();
max = in.readDouble();
@ -178,7 +178,7 @@ public class InternalStats extends InternalNumericMetricsAggregation.MultiValue
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeVLong(count);
out.writeDouble(min);
out.writeDouble(max);

View File

@ -88,13 +88,13 @@ public class InternalSum extends InternalNumericMetricsAggregation.SingleValue i
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
sum = in.readDouble();
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeDouble(sum);
}

View File

@ -82,13 +82,13 @@ public class InternalSimpleValue extends InternalNumericMetricsAggregation.Singl
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
value = in.readDouble();
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeDouble(value);
}

View File

@ -112,7 +112,7 @@ public abstract class BucketMetricsPipelineAggregator extends SiblingPipelineAgg
@Override
public final void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
gapPolicy = GapPolicy.readFrom(in);
innerReadFrom(in);
}
@ -122,7 +122,7 @@ public abstract class BucketMetricsPipelineAggregator extends SiblingPipelineAgg
@Override
public final void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
gapPolicy.writeTo(out);
innerWriteTo(out);
}

View File

@ -99,14 +99,14 @@ public class InternalBucketMetricValue extends InternalNumericMetricsAggregation
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
value = in.readDouble();
keys = in.readStringArray();
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeDouble(value);
out.writeStringArray(keys);
}

View File

@ -106,14 +106,14 @@ public class InternalPercentilesBucket extends InternalNumericMetricsAggregation
@Override
protected void doReadFrom(StreamInput in) throws IOException {
format = in.readValueFormat();
format = in.readNamedWriteable(DocValueFormat.class);
percentiles = in.readDoubleArray();
percents = in.readDoubleArray();
}
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(format);
out.writeNamedWriteable(format);
out.writeDoubleArray(percentiles);
out.writeDoubleArray(percents);
}

View File

@ -139,7 +139,7 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator {
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
script.writeTo(out);
out.writeValueFormat(formatter);
out.writeNamedWriteable(formatter);
gapPolicy.writeTo(out);
out.writeGenericValue(bucketsPathsMap);
}
@ -148,7 +148,7 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator {
@Override
protected void doReadFrom(StreamInput in) throws IOException {
script = Script.readScript(in);
formatter = in.readValueFormat();
formatter = in.readNamedWriteable(DocValueFormat.class);
gapPolicy = GapPolicy.readFrom(in);
bucketsPathsMap = (Map<String, String>) in.readGenericValue();
}

View File

@ -95,11 +95,11 @@ public class CumulativeSumPipelineAggregator extends PipelineAggregator {
@Override
public void doReadFrom(StreamInput in) throws IOException {
formatter = in.readValueFormat();
formatter = in.readNamedWriteable(DocValueFormat.class);
}
@Override
public void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(formatter);
out.writeNamedWriteable(formatter);
}
}

View File

@ -127,7 +127,7 @@ public class DerivativePipelineAggregator extends PipelineAggregator {
@Override
public void doReadFrom(StreamInput in) throws IOException {
formatter = in.readValueFormat();
formatter = in.readNamedWriteable(DocValueFormat.class);
gapPolicy = GapPolicy.readFrom(in);
if (in.readBoolean()) {
xAxisUnits = in.readDouble();
@ -139,7 +139,7 @@ public class DerivativePipelineAggregator extends PipelineAggregator {
@Override
public void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(formatter);
out.writeNamedWriteable(formatter);
gapPolicy.writeTo(out);
boolean hasXAxisUnitsValue = xAxisUnits != null;
out.writeBoolean(hasXAxisUnitsValue);

View File

@ -250,7 +250,7 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
@Override
public void doReadFrom(StreamInput in) throws IOException {
formatter = in.readValueFormat();
formatter = in.readNamedWriteable(DocValueFormat.class);
gapPolicy = GapPolicy.readFrom(in);
window = in.readVInt();
predict = in.readVInt();
@ -261,7 +261,7 @@ public class MovAvgPipelineAggregator extends PipelineAggregator {
@Override
public void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(formatter);
out.writeNamedWriteable(formatter);
gapPolicy.writeTo(out);
out.writeVInt(window);
out.writeVInt(predict);

View File

@ -128,14 +128,14 @@ public class SerialDiffPipelineAggregator extends PipelineAggregator {
@Override
public void doReadFrom(StreamInput in) throws IOException {
formatter = in.readValueFormat();
formatter = in.readNamedWriteable(DocValueFormat.class);
gapPolicy = GapPolicy.readFrom(in);
lag = in.readVInt();
}
@Override
public void doWriteTo(StreamOutput out) throws IOException {
out.writeValueFormat(formatter);
out.writeNamedWriteable(formatter);
gapPolicy.writeTo(out);
out.writeVInt(lag);
}

View File

@ -39,41 +39,41 @@ public class DocValueFormatTests extends ESTestCase {
registry.register(DocValueFormat.class, DocValueFormat.RAW.getWriteableName(), in -> DocValueFormat.RAW);
BytesStreamOutput out = new BytesStreamOutput();
out.writeValueFormat(DocValueFormat.BOOLEAN);
out.writeNamedWriteable(DocValueFormat.BOOLEAN);
StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes()), registry);
assertSame(DocValueFormat.BOOLEAN, in.readValueFormat());
assertSame(DocValueFormat.BOOLEAN, in.readNamedWriteable(DocValueFormat.class));
DocValueFormat.Decimal decimalFormat = new DocValueFormat.Decimal("###.##");
out = new BytesStreamOutput();
out.writeValueFormat(decimalFormat);
out.writeNamedWriteable(decimalFormat);
in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes()), registry);
DocValueFormat vf = in.readValueFormat();
DocValueFormat vf = in.readNamedWriteable(DocValueFormat.class);
assertEquals(DocValueFormat.Decimal.class, vf.getClass());
assertEquals("###.##", ((DocValueFormat.Decimal) vf).pattern);
DocValueFormat.DateTime dateFormat = new DocValueFormat.DateTime(Joda.forPattern("epoch_second"), DateTimeZone.forOffsetHours(1));
out = new BytesStreamOutput();
out.writeValueFormat(dateFormat);
out.writeNamedWriteable(dateFormat);
in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes()), registry);
vf = in.readValueFormat();
vf = in.readNamedWriteable(DocValueFormat.class);
assertEquals(DocValueFormat.DateTime.class, vf.getClass());
assertEquals("epoch_second", ((DocValueFormat.DateTime) vf).formatter.format());
assertEquals(DateTimeZone.forOffsetHours(1), ((DocValueFormat.DateTime) vf).timeZone);
out = new BytesStreamOutput();
out.writeValueFormat(DocValueFormat.GEOHASH);
out.writeNamedWriteable(DocValueFormat.GEOHASH);
in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes()), registry);
assertSame(DocValueFormat.GEOHASH, in.readValueFormat());
assertSame(DocValueFormat.GEOHASH, in.readNamedWriteable(DocValueFormat.class));
out = new BytesStreamOutput();
out.writeValueFormat(DocValueFormat.IP);
out.writeNamedWriteable(DocValueFormat.IP);
in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes()), registry);
assertSame(DocValueFormat.IP, in.readValueFormat());
assertSame(DocValueFormat.IP, in.readNamedWriteable(DocValueFormat.class));
out = new BytesStreamOutput();
out.writeValueFormat(DocValueFormat.RAW);
out.writeNamedWriteable(DocValueFormat.RAW);
in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes()), registry);
assertSame(DocValueFormat.RAW, in.readValueFormat());
assertSame(DocValueFormat.RAW, in.readNamedWriteable(DocValueFormat.class));
}
}