View Javadoc

1   /**
2    * Copyright The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements. See the NOTICE file distributed with this
6    * work for additional information regarding copyright ownership. The ASF
7    * licenses this file to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance with the License.
9    * 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, WITHOUT
15   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16   * License for the specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.hadoop.hbase.io.hfile.bucket;
20  
21  import java.io.IOException;
22  import java.nio.ByteBuffer;
23  
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.io.hfile.Cacheable;
26  import org.apache.hadoop.hbase.io.hfile.CacheableDeserializer;
27  import org.apache.hadoop.hbase.nio.ByteBuff;
28  
29  /**
30   * A class implementing IOEngine interface supports data services for
31   * {@link BucketCache}.
32   */
33  @InterfaceAudience.Private
34  public interface IOEngine {
35    /**
36     * @return true if persistent storage is supported for the cache when shutdown
37     */
38    boolean isPersistent();
39  
40    /**
41     * Transfers data from IOEngine to a Cacheable object.
42     * @param length How many bytes to be read from the offset
43     * @param offset The offset in the IO engine where the first byte to be read
44     * @param deserializer The deserializer to be used to make a Cacheable from the data.
45     * @return Cacheable
46     * @throws IOException
47     * @throws RuntimeException when the length of the ByteBuff read is less than 'len'
48     */
49    Cacheable read(long offset, int length, CacheableDeserializer<Cacheable> deserializer)
50        throws IOException;
51  
52    /**
53     * Transfers data from the given byte buffer to IOEngine
54     * @param srcBuffer the given byte buffer from which bytes are to be read
55     * @param offset The offset in the IO engine where the first byte to be
56     *          written
57     * @throws IOException
58     */
59    void write(ByteBuffer srcBuffer, long offset) throws IOException;
60  
61    /**
62     * Transfers the data from the given MultiByteBuffer to IOEngine
63     * @param srcBuffer the given MultiBytebufffers from which bytes are to be read
64     * @param offset the offset in the IO engine where the first byte to be written
65     * @throws IOException
66     */
67    void write(ByteBuff srcBuffer, long offset) throws IOException;
68  
69    /**
70     * Sync the data to IOEngine after writing
71     * @throws IOException
72     */
73    void sync() throws IOException;
74  
75    /**
76     * Shutdown the IOEngine
77     */
78    void shutdown();
79  }