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.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.HConstants;
23  
24  /**
25   * A Get, Put, Increment, Append, or Delete associated with it's region.  Used internally by  
26   * {@link HTable#batch} to associate the action with it's region and maintain
27   * the index from the original request. 
28   */
29  @InterfaceAudience.Private
30  //TODO: R is never used
31  public class Action<R> implements Comparable<R> {
32    // TODO: This class should not be visible outside of the client package.
33    private Row action;
34    private int originalIndex;
35    private long nonce = HConstants.NO_NONCE;
36    private int replicaId = RegionReplicaUtil.DEFAULT_REPLICA_ID;
37  
38    public Action(Row action, int originalIndex) {
39      super();
40      this.action = action;
41      this.originalIndex = originalIndex;
42    }
43  
44    /**
45     * Creates an action for a particular replica from original action.
46     * @param action Original action.
47     * @param replicaId Replica id for the new action.
48     */
49    public Action(Action<R> action, int replicaId) {
50      super();
51      this.action = action.action;
52      this.nonce = action.nonce;
53      this.originalIndex = action.originalIndex;
54      this.replicaId = replicaId;
55    }
56  
57  
58    public void setNonce(long nonce) {
59      this.nonce = nonce;
60    }
61  
62    public boolean hasNonce() {
63      return nonce != HConstants.NO_NONCE;
64    }
65  
66    public Row getAction() {
67      return action;
68    }
69  
70    public int getOriginalIndex() {
71      return originalIndex;
72    }
73  
74    public int getReplicaId() {
75      return replicaId;
76    }
77  
78    @SuppressWarnings("rawtypes")
79    @Override
80    public int compareTo(Object o) {
81      return action.compareTo(((Action) o).getAction());
82    }
83  
84    @Override
85    public int hashCode() {
86      return this.action.hashCode();
87    }
88  
89    @Override
90    public boolean equals(Object obj) {
91      if (this == obj) return true;
92      if (obj == null || getClass() != obj.getClass()) return false;
93      Action<?> other = (Action<?>) obj;
94      return compareTo(other) == 0;
95    }
96  
97    public long getNonce() {
98      return nonce;
99    }
100 }