View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.omid.transaction;
19  
20  import com.google.common.hash.Hashing;
21  import org.apache.omid.tso.client.CellId;
22  import org.apache.hadoop.hbase.client.HTableInterface;
23  
24  import static com.google.common.base.Charsets.UTF_8;
25  
26  public class HBaseCellId implements CellId {
27  
28      private final HTableInterface table;
29      private final byte[] row;
30      private final byte[] family;
31      private final byte[] qualifier;
32      private long timestamp;
33  
34      public HBaseCellId(HTableInterface table, byte[] row, byte[] family, byte[] qualifier, long timestamp) {
35          this.timestamp = timestamp;
36          this.table = table;
37          this.row = row;
38          this.family = family;
39          this.qualifier = qualifier;
40      }
41  
42      public HTableInterface getTable() {
43          return table;
44      }
45  
46      public byte[] getRow() {
47          return row;
48      }
49  
50      public byte[] getFamily() {
51          return family;
52      }
53  
54      public byte[] getQualifier() {
55          return qualifier;
56      }
57  
58      public long getTimestamp() {
59          return timestamp;
60      }
61  
62      public String toString() {
63          return new String(table.getTableName(), UTF_8)
64                  + ":" + new String(row, UTF_8)
65                  + ":" + new String(family, UTF_8)
66                  + ":" + new String(qualifier, UTF_8)
67                  + ":" + timestamp;
68      }
69  
70      @Override
71      public long getCellId() {
72          return Hashing.murmur3_128().newHasher()
73                  .putBytes(table.getTableName())
74                  .putBytes(row)
75                  .putBytes(family)
76                  .putBytes(qualifier)
77                  .hash().asLong();
78      }
79  
80  }