001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.replication;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022/**
023 * A HBase ReplicationLoad to present MetricsSource information
024 */
025@InterfaceAudience.Public
026public final class ReplicationLoadSource {
027  private final String peerID;
028  private final long ageOfLastShippedOp;
029  private final int sizeOfLogQueue;
030  private final long timestampOfLastShippedOp;
031  private final long replicationLag;
032  private long timeStampOfNextToReplicate;
033  private String queueId;
034  private boolean recovered;
035  private boolean running;
036  private boolean editsSinceRestart;
037  private long editsRead;
038  private long oPsShipped;
039
040  @InterfaceAudience.Private
041  private ReplicationLoadSource(String id, long age, int size, long timestamp,
042    long timeStampOfNextToReplicate, long lag, String queueId, boolean recovered, boolean running,
043    boolean editsSinceRestart, long editsRead, long oPsShipped) {
044    this.peerID = id;
045    this.ageOfLastShippedOp = age;
046    this.sizeOfLogQueue = size;
047    this.timestampOfLastShippedOp = timestamp;
048    this.replicationLag = lag;
049    this.timeStampOfNextToReplicate = timeStampOfNextToReplicate;
050    this.queueId = queueId;
051    this.recovered = recovered;
052    this.running = running;
053    this.editsSinceRestart = editsSinceRestart;
054    this.editsRead = editsRead;
055    this.oPsShipped = oPsShipped;
056  }
057
058  public String getPeerID() {
059    return this.peerID;
060  }
061
062  public long getAgeOfLastShippedOp() {
063    return this.ageOfLastShippedOp;
064  }
065
066  public long getSizeOfLogQueue() {
067    return this.sizeOfLogQueue;
068  }
069
070  /**
071   * Get the timestamp of the last shipped operation.
072   * @deprecated Since 2.0.0. Will be removed in 3.0.0.
073   * @see #getTimestampOfLastShippedOp()
074   */
075  @Deprecated
076  public long getTimeStampOfLastShippedOp() {
077    return getTimestampOfLastShippedOp();
078  }
079
080  public long getTimestampOfLastShippedOp() {
081    return this.timestampOfLastShippedOp;
082  }
083
084  public long getReplicationLag() {
085    return this.replicationLag;
086  }
087
088  public long getTimeStampOfNextToReplicate() {
089    return this.timeStampOfNextToReplicate;
090  }
091
092  public String getQueueId() {
093    return queueId;
094  }
095
096  public boolean isRecovered() {
097    return recovered;
098  }
099
100  public boolean isRunning() {
101    return running;
102  }
103
104  public boolean hasEditsSinceRestart() {
105    return editsSinceRestart;
106  }
107
108  public long getEditsRead() {
109    return editsRead;
110  }
111
112  public long getOPsShipped() {
113    return oPsShipped;
114  }
115
116  public static ReplicationLoadSourceBuilder newBuilder() {
117    return new ReplicationLoadSourceBuilder();
118  }
119
120  public static final class ReplicationLoadSourceBuilder {
121
122    private String peerID;
123    private long ageOfLastShippedOp;
124    private int sizeOfLogQueue;
125    private long timestampOfLastShippedOp;
126    private long replicationLag;
127    private long timeStampOfNextToReplicate;
128    private String queueId;
129    private boolean recovered;
130    private boolean running;
131    private boolean editsSinceRestart;
132    private long editsRead;
133    private long oPsShipped;
134
135    private ReplicationLoadSourceBuilder() {
136
137    }
138
139    public ReplicationLoadSourceBuilder
140      setTimeStampOfNextToReplicate(long timeStampOfNextToReplicate) {
141      this.timeStampOfNextToReplicate = timeStampOfNextToReplicate;
142      return this;
143    }
144
145    public ReplicationLoadSourceBuilder setPeerID(String peerID) {
146      this.peerID = peerID;
147      return this;
148    }
149
150    public ReplicationLoadSourceBuilder setAgeOfLastShippedOp(long ageOfLastShippedOp) {
151      this.ageOfLastShippedOp = ageOfLastShippedOp;
152      return this;
153    }
154
155    public ReplicationLoadSourceBuilder setSizeOfLogQueue(int sizeOfLogQueue) {
156      this.sizeOfLogQueue = sizeOfLogQueue;
157      return this;
158    }
159
160    public ReplicationLoadSourceBuilder setTimestampOfLastShippedOp(long timestampOfLastShippedOp) {
161      this.timestampOfLastShippedOp = timestampOfLastShippedOp;
162      return this;
163    }
164
165    public ReplicationLoadSourceBuilder setReplicationLag(long replicationLag) {
166      this.replicationLag = replicationLag;
167      return this;
168    }
169
170    public ReplicationLoadSourceBuilder setQueueId(String queueId) {
171      this.queueId = queueId;
172      return this;
173    }
174
175    public ReplicationLoadSourceBuilder setRecovered(boolean recovered) {
176      this.recovered = recovered;
177      return this;
178    }
179
180    public ReplicationLoadSourceBuilder setRunning(boolean running) {
181      this.running = running;
182      return this;
183    }
184
185    public ReplicationLoadSourceBuilder setEditsSinceRestart(boolean editsSinceRestart) {
186      this.editsSinceRestart = editsSinceRestart;
187      return this;
188    }
189
190    public ReplicationLoadSourceBuilder setEditsRead(long editsRead) {
191      this.editsRead = editsRead;
192      return this;
193    }
194
195    public ReplicationLoadSourceBuilder setoPsShipped(long oPsShipped) {
196      this.oPsShipped = oPsShipped;
197      return this;
198    }
199
200    public ReplicationLoadSource build() {
201      return new ReplicationLoadSource(peerID, ageOfLastShippedOp, sizeOfLogQueue,
202        timestampOfLastShippedOp, timeStampOfNextToReplicate, replicationLag, queueId, recovered,
203        running, editsSinceRestart, editsRead, oPsShipped);
204    }
205  }
206}