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.monitoring;
019
020import java.io.IOException;
021import java.util.List;
022import java.util.Map;
023import org.apache.yetus.audience.InterfaceAudience;
024
025@InterfaceAudience.Private
026public interface MonitoredTask extends Cloneable {
027  enum State {
028    RUNNING,
029    WAITING,
030    COMPLETE,
031    ABORTED;
032  }
033
034  public interface StatusJournalEntry {
035    String getStatus();
036
037    long getTimeStamp();
038  }
039
040  long getStartTime();
041
042  String getDescription();
043
044  String getStatus();
045
046  long getStatusTime();
047
048  State getState();
049
050  long getStateTime();
051
052  long getCompletionTimestamp();
053
054  long getWarnTime();
055
056  void markComplete(String msg);
057
058  void pause(String msg);
059
060  void resume(String msg);
061
062  void abort(String msg);
063
064  void expireNow();
065
066  void setStatus(String status);
067
068  void setDescription(String description);
069
070  void setWarnTime(final long t);
071
072  /**
073   * If journal is enabled, we will store all statuses that have been set along with the time stamps
074   * when they were set. This method will give you all the journals stored so far.
075   */
076  List<StatusJournalEntry> getStatusJournal();
077
078  String prettyPrintJournal();
079
080  /**
081   * Explicitly mark this status as able to be cleaned up, even though it might not be complete.
082   */
083  void cleanup();
084
085  /**
086   * Public exposure of Object.clone() in order to allow clients to easily capture current state.
087   * @return a copy of the object whose references will not change
088   */
089  MonitoredTask clone();
090
091  /**
092   * Creates a string map of internal details for extensible exposure of monitored tasks.
093   * @return A Map containing information for this task.
094   */
095  Map<String, Object> toMap() throws IOException;
096
097  /**
098   * Creates a JSON object for parseable exposure of monitored tasks.
099   * @return An encoded JSON object containing information for this task.
100   */
101  String toJSON() throws IOException;
102
103}