Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.elasticsearch.ElasticsearchException;
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.unit.TimeValue;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeZone;
Expand All @@ -33,7 +33,7 @@
/**
* A strategy for rounding long values.
*/
public abstract class Rounding implements Streamable {
public abstract class Rounding implements Writeable {

public abstract byte id();

Expand Down Expand Up @@ -107,13 +107,10 @@ static class TimeUnitRounding extends Rounding {

static final byte ID = 1;

private DateTimeUnit unit;
private DateTimeField field;
private DateTimeZone timeZone;
private boolean unitRoundsToMidnight;

TimeUnitRounding() { // for serialization
}
private final DateTimeUnit unit;
private final DateTimeField field;
private final DateTimeZone timeZone;
private final boolean unitRoundsToMidnight;

TimeUnitRounding(DateTimeUnit unit, DateTimeZone timeZone) {
this.unit = unit;
Expand All @@ -122,6 +119,13 @@ static class TimeUnitRounding extends Rounding {
this.timeZone = timeZone;
}

TimeUnitRounding(StreamInput in) throws IOException {
unit = DateTimeUnit.resolve(in.readByte());
timeZone = DateTimeZone.forID(in.readString());
field = unit.field(timeZone);
unitRoundsToMidnight = field.getDurationField().getUnitMillis() > 60L * 60L * 1000L;
}

@Override
public byte id() {
return ID;
Expand Down Expand Up @@ -237,14 +241,6 @@ public long nextRoundingValue(long utcMillis) {
return next;
}

@Override
public void readFrom(StreamInput in) throws IOException {
unit = DateTimeUnit.resolve(in.readByte());
timeZone = DateTimeZone.forID(in.readString());
field = unit.field(timeZone);
unitRoundsToMidnight = field.getDurationField().getUnitMillis() > 60L * 60L * 1000L;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeByte(unit.id());
Expand Down Expand Up @@ -278,11 +274,8 @@ static class TimeIntervalRounding extends Rounding {

static final byte ID = 2;

private long interval;
private DateTimeZone timeZone;

TimeIntervalRounding() { // for serialization
}
private final long interval;
private final DateTimeZone timeZone;

TimeIntervalRounding(long interval, DateTimeZone timeZone) {
if (interval < 1)
Expand All @@ -291,6 +284,11 @@ static class TimeIntervalRounding extends Rounding {
this.timeZone = timeZone;
}

TimeIntervalRounding(StreamInput in) throws IOException {
interval = in.readVLong();
timeZone = DateTimeZone.forID(in.readString());
}

@Override
public byte id() {
return ID;
Expand Down Expand Up @@ -374,12 +372,6 @@ public long nextRoundingValue(long time) {
return timeZone.convertLocalToUTC(next, false);
}

@Override
public void readFrom(StreamInput in) throws IOException {
interval = in.readVLong();
timeZone = DateTimeZone.forID(in.readString());
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(interval);
Expand Down Expand Up @@ -415,11 +407,10 @@ public static Rounding read(StreamInput in) throws IOException {
Rounding rounding = null;
byte id = in.readByte();
switch (id) {
case TimeUnitRounding.ID: rounding = new TimeUnitRounding(); break;
case TimeIntervalRounding.ID: rounding = new TimeIntervalRounding(); break;
case TimeUnitRounding.ID: rounding = new TimeUnitRounding(in); break;
case TimeIntervalRounding.ID: rounding = new TimeIntervalRounding(in); break;
default: throw new ElasticsearchException("unknown rounding id [" + id + "]");
}
rounding.readFrom(in);
return rounding;
}

Expand Down