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.MemoryType;
26  import org.apache.hadoop.hbase.nio.ByteBuff;
27  import org.apache.hadoop.hbase.util.Pair;
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 byte buffer
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     * @return Pair of ByteBuffer where data is read and its MemoryType ({@link MemoryType})
45     * @throws IOException
46     * @throws RuntimeException when the length of the ByteBuff read is less than 'len'
47     */
48    Pair<ByteBuff, MemoryType> read(long offset, int length) throws IOException;
49  
50    /**
51     * Transfers data from the given byte buffer to IOEngine
52     * @param srcBuffer the given byte buffer from which bytes are to be read
53     * @param offset The offset in the IO engine where the first byte to be
54     *          written
55     * @throws IOException
56     */
57    void write(ByteBuffer srcBuffer, long offset) throws IOException;
58  
59    /**
60     * Transfers the data from the given MultiByteBuffer to IOEngine
61     * @param srcBuffer the given MultiBytebufffers from which bytes are to be read
62     * @param offset the offset in the IO engine where the first byte to be written
63     * @throws IOException
64     */
65    void write(ByteBuff srcBuffer, long offset) throws IOException;
66  
67    /**
68     * Sync the data to IOEngine after writing
69     * @throws IOException
70     */
71    void sync() throws IOException;
72  
73    /**
74     * Shutdown the IOEngine
75     */
76    void shutdown();
77  }