View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.procedure2;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.classification.InterfaceStability;
23  
24  /**
25   * Once a Procedure completes the ProcedureExecutor takes all the useful
26   * information of the procedure (e.g. exception/result) and creates a ProcedureResult.
27   * The user of the Procedure framework will get the procedure result with
28   * procedureExecutor.getResult(procId)
29   */
30  @InterfaceAudience.Private
31  @InterfaceStability.Evolving
32  public class ProcedureResult {
33    private final RemoteProcedureException exception;
34    private final long lastUpdate;
35    private final long startTime;
36    private final byte[] result;
37  
38    private long clientAckTime = -1;
39  
40    public ProcedureResult(final long startTime, final long lastUpdate,
41        final RemoteProcedureException exception) {
42      this.lastUpdate = lastUpdate;
43      this.startTime = startTime;
44      this.exception = exception;
45      this.result = null;
46    }
47  
48    public ProcedureResult(final long startTime, final long lastUpdate, final byte[] result) {
49      this.lastUpdate = lastUpdate;
50      this.startTime = startTime;
51      this.exception = null;
52      this.result = result;
53    }
54  
55    public boolean isFailed() {
56      return exception != null;
57    }
58  
59    public RemoteProcedureException getException() {
60      return exception;
61    }
62  
63    public boolean hasResultData() {
64      return result != null;
65    }
66  
67    public byte[] getResult() {
68      return result;
69    }
70  
71    public long getStartTime() {
72      return startTime;
73    }
74  
75    public long getLastUpdate() {
76      return lastUpdate;
77    }
78  
79    public long executionTime() {
80      return lastUpdate - startTime;
81    }
82  
83    public boolean hasClientAckTime() {
84      return clientAckTime > 0;
85    }
86  
87    public long getClientAckTime() {
88      return clientAckTime;
89    }
90  
91    @InterfaceAudience.Private
92    protected void setClientAckTime(final long timestamp) {
93      this.clientAckTime = timestamp;
94    }
95  }