View Javadoc

1   /**
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.client;
21  
22  import java.io.DataInput;
23  import java.io.DataOutput;
24  import java.io.IOException;
25  
26  import org.apache.hadoop.hbase.io.HbaseObjectWritable;
27  import org.apache.hadoop.hbase.util.Bytes;
28  import org.apache.hadoop.io.Writable;
29  
30  /*
31   * A Get, Put or Delete associated with it's region.  Used internally by  
32   * {@link HTable::batch} to associate the action with it's region and maintain 
33   * the index from the original request. 
34   */
35  public class Action<R> implements Writable, Comparable {
36  
37    private Row action;
38    private int originalIndex;
39    private R result;
40  
41    public Action() {
42      super();
43    }
44  
45    /*
46     * This constructor is replaced by {@link #Action(Row, int)}
47     */
48    @Deprecated
49    public Action(byte[] regionName, Row action, int originalIndex) {
50      this(action, originalIndex);
51    }
52  
53    public Action(Row action, int originalIndex) {
54      super();
55      this.action = action;
56      this.originalIndex = originalIndex;    
57    }
58    
59    @Deprecated
60    public byte[] getRegionName() {
61      return null;
62    }
63  
64    @Deprecated
65    public void setRegionName(byte[] regionName) {
66    }
67  
68    public R getResult() {
69      return result;
70    }
71  
72    public void setResult(R result) {
73      this.result = result;
74    }
75  
76    public Row getAction() {
77      return action;
78    }
79  
80    public int getOriginalIndex() {
81      return originalIndex;
82    }
83  
84    @Override
85    public int compareTo(Object o) {
86      return action.compareTo(((Action) o).getAction());
87    }
88  
89    // ///////////////////////////////////////////////////////////////////////////
90    // Writable
91    // ///////////////////////////////////////////////////////////////////////////
92  
93    public void write(final DataOutput out) throws IOException {
94      HbaseObjectWritable.writeObject(out, action, Row.class, null);
95      out.writeInt(originalIndex);
96      HbaseObjectWritable.writeObject(out, result,
97          result != null ? result.getClass() : Writable.class, null);
98    }
99  
100   public void readFields(final DataInput in) throws IOException {
101     this.action = (Row) HbaseObjectWritable.readObject(in, null);
102     this.originalIndex = in.readInt();
103     this.result = (R) HbaseObjectWritable.readObject(in, null);
104   }
105 
106 }