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 implements Writable, Comparable {
36  
37    private byte[] regionName;
38    private Row action;
39    private int originalIndex;
40    private Result result;
41  
42    public Action() {
43      super();
44    }
45  
46    public Action(byte[] regionName, Row action, int originalIndex) {
47      super();
48      this.regionName = regionName;
49      this.action = action;
50      this.originalIndex = originalIndex;
51    }
52  
53    public byte[] getRegionName() {
54      return regionName;
55    }
56  
57    public void setRegionName(byte[] regionName) {
58      this.regionName = regionName;
59    }
60  
61    public Result getResult() {
62      return result;
63    }
64  
65    public void setResult(Result result) {
66      this.result = result;
67    }
68  
69    public Row getAction() {
70      return action;
71    }
72  
73    public int getOriginalIndex() {
74      return originalIndex;
75    }
76  
77    @Override
78    public int compareTo(Object o) {
79      return action.compareTo(((Action) o).getAction());
80    }
81  
82    // ///////////////////////////////////////////////////////////////////////////
83    // Writable
84    // ///////////////////////////////////////////////////////////////////////////
85  
86    public void write(final DataOutput out) throws IOException {
87      Bytes.writeByteArray(out, regionName);
88      HbaseObjectWritable.writeObject(out, action, Row.class, null);
89      out.writeInt(originalIndex);
90      HbaseObjectWritable.writeObject(out, result, Result.class, null);
91    }
92  
93    public void readFields(final DataInput in) throws IOException {
94      this.regionName = Bytes.readByteArray(in);
95      this.action = (Row) HbaseObjectWritable.readObject(in, null);
96      this.originalIndex = in.readInt();
97      this.result = (Result) HbaseObjectWritable.readObject(in, null);
98    }
99  
100 }