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  
20  package org.apache.hadoop.hbase.io.hfile;
21  
22  import java.nio.ByteBuffer;
23  
24  import org.apache.hadoop.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.io.HeapSize;
26  
27  /**
28   * Cacheable is an interface that allows for an object to be cached. If using an
29   * on heap cache, just use heapsize. If using an off heap cache, Cacheable
30   * provides methods for serialization of the object.
31   *
32   * Some objects cannot be moved off heap, those objects will return a
33   * getSerializedLength() of 0.
34   *
35   */
36  @InterfaceAudience.Private
37  public interface Cacheable extends HeapSize {
38    /**
39     * Returns the length of the ByteBuffer required to serialized the object. If the
40     * object cannot be serialized, it should also return 0.
41     *
42     * @return int length in bytes of the serialized form.
43     */
44  
45    int getSerializedLength();
46  
47    /**
48     * Serializes its data into destination.
49     */
50    void serialize(ByteBuffer destination);
51  
52    /**
53     * Returns CacheableDeserializer instance which reconstructs original object from ByteBuffer.
54     *
55     * @return CacheableDeserialzer instance.
56     */
57    CacheableDeserializer<Cacheable> getDeserializer();
58  
59    /**
60     * @return the block type of this cached HFile block
61     */
62    BlockType getBlockType();
63  
64  }