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;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022/** Builder for information about active monitored server tasks */
023@InterfaceAudience.Private
024public final class ServerTaskBuilder {
025
026  public static ServerTaskBuilder newBuilder() {
027    return new ServerTaskBuilder();
028  }
029
030  private String description = "";
031  private String status = "";
032  private ServerTask.State state = ServerTask.State.RUNNING;
033  private long startTime;
034  private long completionTime;
035
036  private ServerTaskBuilder() {
037  }
038
039  private static final class ServerTaskImpl implements ServerTask {
040
041    private final String description;
042    private final String status;
043    private final ServerTask.State state;
044    private final long startTime;
045    private final long completionTime;
046
047    private ServerTaskImpl(final String description, final String status,
048      final ServerTask.State state, final long startTime, final long completionTime) {
049      this.description = description;
050      this.status = status;
051      this.state = state;
052      this.startTime = startTime;
053      this.completionTime = completionTime;
054    }
055
056    @Override
057    public String getDescription() {
058      return description;
059    }
060
061    @Override
062    public String getStatus() {
063      return status;
064    }
065
066    @Override
067    public State getState() {
068      return state;
069    }
070
071    @Override
072    public long getStartTime() {
073      return startTime;
074    }
075
076    @Override
077    public long getCompletionTime() {
078      return completionTime;
079    }
080
081    @Override
082    public String toString() {
083      StringBuilder sb = new StringBuilder(512);
084      sb.append(getDescription());
085      sb.append(": status=");
086      sb.append(getStatus());
087      sb.append(", state=");
088      sb.append(getState());
089      sb.append(", startTime=");
090      sb.append(getStartTime());
091      sb.append(", completionTime=");
092      sb.append(getCompletionTime());
093      return sb.toString();
094    }
095
096  }
097
098  public ServerTaskBuilder setDescription(final String description) {
099    this.description = description;
100    return this;
101  }
102
103  public ServerTaskBuilder setStatus(final String status) {
104    this.status = status;
105    return this;
106  }
107
108  public ServerTaskBuilder setState(final ServerTask.State state) {
109    this.state = state;
110    return this;
111  }
112
113  public ServerTaskBuilder setStartTime(final long startTime) {
114    this.startTime = startTime;
115    return this;
116  }
117
118  public ServerTaskBuilder setCompletionTime(final long completionTime) {
119    this.completionTime = completionTime;
120    return this;
121  }
122
123  public ServerTask build() {
124    return new ServerTaskImpl(description, status, state, startTime, completionTime);
125  }
126
127}