1 /** 2 * Copyright 2011 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 21 package org.apache.hadoop.hbase.io.hfile; 22 23 import java.nio.ByteBuffer; 24 import org.apache.hadoop.hbase.io.HeapSize; 25 import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics; 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 public interface Cacheable extends HeapSize { 37 /** 38 * Returns the length of the ByteBuffer required to serialized the object. If the 39 * object cannot be serialized, it should also return 0. 40 * 41 * @return int length in bytes of the serialized form. 42 */ 43 44 public int getSerializedLength(); 45 46 /** 47 * Serializes its data into destination. 48 */ 49 public void serialize(ByteBuffer destination); 50 51 /** 52 * Returns CacheableDeserializer instance which reconstructs original object from ByteBuffer. 53 * 54 * @return CacheableDeserialzer instance. 55 */ 56 public CacheableDeserializer<Cacheable> getDeserializer(); 57 58 /** 59 * @return the block type of this cached HFile block 60 */ 61 public BlockType getBlockType(); 62 63 /** 64 * @return the metrics object identified by table and column family 65 */ 66 public SchemaMetrics getSchemaMetrics(); 67 68 }