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  
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  public class Action<R> implements Comparable<R> {
31    // TODO: This class should not be visible outside of the client package.
32    private Row action;
33    private int originalIndex;
34    private long nonce = HConstants.NO_NONCE;
35  
36    public Action(Row action, int originalIndex) {
37      super();
38      this.action = action;
39      this.originalIndex = originalIndex;    
40    }
41  
42    public void setNonce(long nonce) {
43      this.nonce = nonce;
44    }
45  
46    public boolean hasNonce() {
47      return nonce != HConstants.NO_NONCE;
48    }
49  
50    public Row getAction() {
51      return action;
52    }
53  
54    public int getOriginalIndex() {
55      return originalIndex;
56    }
57  
58    @SuppressWarnings("rawtypes")
59    @Override
60    public int compareTo(Object o) {
61      return action.compareTo(((Action) o).getAction());
62    }
63  
64    @Override
65    public int hashCode() {
66      return this.action.hashCode();
67    }
68  
69    @Override
70    public boolean equals(Object obj) {
71      if (this == obj) return true;
72      if (obj == null || getClass() != obj.getClass()) return false;
73      Action<?> other = (Action<?>) obj;
74      return compareTo(other) == 0;
75    }
76  
77    public long getNonce() {
78      return nonce;
79    }
80  }