HBASE-26490 Add builder for class ReplicationLoadSink (#3883)

Signed-off-by: Reid Chan <reidchan@apache.org>
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Yutong Xiao 2021-12-04 23:00:22 +08:00 committed by Duo Zhang
parent 19d991d291
commit b471d753d3
2 changed files with 47 additions and 7 deletions

View File

@ -22,9 +22,7 @@ public class ReplicationLoadSink {
private final long timestampStarted;
private final long totalOpsProcessed;
// TODO: add the builder for this class
@InterfaceAudience.Private
public ReplicationLoadSink(long age, long timestamp, long timestampStarted,
private ReplicationLoadSink(long age, long timestamp, long timestampStarted,
long totalOpsProcessed) {
this.ageOfLastAppliedOp = age;
this.timestampsOfLastAppliedOp = timestamp;
@ -56,4 +54,44 @@ public class ReplicationLoadSink {
public long getTotalOpsProcessed() {
return totalOpsProcessed;
}
@InterfaceAudience.Private
public static ReplicationLoadSinkBuilder newBuilder() {
return new ReplicationLoadSinkBuilder();
}
@InterfaceAudience.Private
public static final class ReplicationLoadSinkBuilder {
private long ageOfLastAppliedOp;
private long timestampsOfLastAppliedOp;
private long timestampStarted;
private long totalOpsProcessed;
private ReplicationLoadSinkBuilder() {}
public ReplicationLoadSinkBuilder setAgeOfLastAppliedOp(long ageOfLastAppliedOp) {
this.ageOfLastAppliedOp = ageOfLastAppliedOp;
return this;
}
public ReplicationLoadSinkBuilder setTimestampsOfLastAppliedOp(long timestampsOfLastAppliedOp) {
this.timestampsOfLastAppliedOp = timestampsOfLastAppliedOp;
return this;
}
public ReplicationLoadSinkBuilder setTimestampStarted(long timestampStarted) {
this.timestampStarted = timestampStarted;
return this;
}
public ReplicationLoadSinkBuilder setTotalOpsProcessed(long totalOpsProcessed) {
this.totalOpsProcessed = totalOpsProcessed;
return this;
}
public ReplicationLoadSink build() {
return new ReplicationLoadSink(ageOfLastAppliedOp, timestampsOfLastAppliedOp,
timestampStarted, totalOpsProcessed);
}
}
}

View File

@ -2798,10 +2798,12 @@ public final class ProtobufUtil {
public static ReplicationLoadSink toReplicationLoadSink(
ClusterStatusProtos.ReplicationLoadSink rls) {
return new ReplicationLoadSink(rls.getAgeOfLastAppliedOp(),
rls.getTimeStampsOfLastAppliedOp(),
rls.hasTimestampStarted()? rls.getTimestampStarted(): -1L,
rls.hasTotalOpsProcessed()? rls.getTotalOpsProcessed(): -1L);
ReplicationLoadSink.ReplicationLoadSinkBuilder builder = ReplicationLoadSink.newBuilder();
builder.setAgeOfLastAppliedOp(rls.getAgeOfLastAppliedOp()).
setTimestampsOfLastAppliedOp(rls.getTimeStampsOfLastAppliedOp()).
setTimestampStarted(rls.hasTimestampStarted()? rls.getTimestampStarted(): -1L).
setTotalOpsProcessed(rls.hasTotalOpsProcessed()? rls.getTotalOpsProcessed(): -1L);
return builder.build();
}
public static ReplicationLoadSource toReplicationLoadSource(