View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.client;
20  
21  import org.apache.hadoop.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.HConstants;
23  import org.apache.hadoop.hbase.HRegionInfo;
24  
25  /**
26   * A Get, Put, Increment, Append, or Delete associated with it's region.  Used internally by  
27   * {@link HTable#batch} to associate the action with it's region and maintain
28   * the index from the original request. 
29   */
30  @InterfaceAudience.Private
31  //TODO: R is never used
32  public class Action<R> implements Comparable<R> {
33    // TODO: This class should not be visible outside of the client package.
34    private Row action;
35    private int originalIndex;
36    private long nonce = HConstants.NO_NONCE;
37    private int replicaId = RegionReplicaUtil.DEFAULT_REPLICA_ID;
38  
39    public Action(Row action, int originalIndex) {
40      super();
41      this.action = action;
42      this.originalIndex = originalIndex;
43    }
44  
45    /**
46     * Creates an action for a particular replica from original action.
47     * @param action Original action.
48     * @param replicaId Replica id for the new action.
49     */
50    public Action(Action<R> action, int replicaId) {
51      super();
52      this.action = action.action;
53      this.nonce = action.nonce;
54      this.originalIndex = action.originalIndex;
55      this.replicaId = replicaId;
56    }
57  
58  
59    public void setNonce(long nonce) {
60      this.nonce = nonce;
61    }
62  
63    public boolean hasNonce() {
64      return nonce != HConstants.NO_NONCE;
65    }
66  
67    public Row getAction() {
68      return action;
69    }
70  
71    public int getOriginalIndex() {
72      return originalIndex;
73    }
74  
75    public int getReplicaId() {
76      return replicaId;
77    }
78  
79    @SuppressWarnings("rawtypes")
80    @Override
81    public int compareTo(Object o) {
82      return action.compareTo(((Action) o).getAction());
83    }
84  
85    @Override
86    public int hashCode() {
87      return this.action.hashCode();
88    }
89  
90    @Override
91    public boolean equals(Object obj) {
92      if (this == obj) return true;
93      if (obj == null || getClass() != obj.getClass()) return false;
94      Action<?> other = (Action<?>) obj;
95      return compareTo(other) == 0;
96    }
97  
98    public long getNonce() {
99      return nonce;
100   }
101 }