View Javadoc

1   /**
2    * Copyright 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;
21  
22  import java.nio.ByteBuffer;
23  
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.classification.InterfaceStability;
26  import org.apache.hadoop.hbase.util.Bytes;
27  
28  /**
29   * Tags are part of cells and helps to add metadata about them.
30   * Metadata could be ACLs, visibility labels, etc.
31   * <p>
32   * Each Tag is having a type (one byte) and value part. The max value length for a Tag is 65533.
33   * <p>
34   * See {@link TagType} for reserved tag types.
35   */
36  @InterfaceAudience.Private
37  @InterfaceStability.Evolving
38  public interface Tag {
39  
40    public final static int TYPE_LENGTH_SIZE = Bytes.SIZEOF_BYTE;
41    public final static int TAG_LENGTH_SIZE = Bytes.SIZEOF_SHORT;
42    public final static int INFRASTRUCTURE_SIZE = TYPE_LENGTH_SIZE + TAG_LENGTH_SIZE;
43    public static final int MAX_TAG_LENGTH = (2 * Short.MAX_VALUE) + 1 - TAG_LENGTH_SIZE;
44  
45    /**
46     * @return the tag type
47     */
48    byte getType();
49  
50    /**
51     * @return Offset of tag value within the backed buffer
52     */
53    int getValueOffset();
54  
55    /**
56     * @return Length of tag value within the backed buffer
57     */
58    int getValueLength();
59  
60    /**
61     * Tells whether or not this Tag is backed by a byte array.
62     * @return true when this Tag is backed by byte array
63     */
64    boolean hasArray();
65  
66    /**
67     * @return The array containing the value bytes.
68     * @throws UnsupportedOperationException
69     *           when {@link #hasArray()} return false. Use {@link #getValueByteBuffer()} in such
70     *           situation
71     */
72    byte[] getValueArray();
73  
74    /**
75     * @return The {@link java.nio.ByteBuffer} containing the value bytes.
76     */
77    ByteBuffer getValueByteBuffer();
78  }