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  
26  /**
27   * A class implementing IOEngine interface supports data services for
28   * {@link BucketCache}.
29   */
30  @InterfaceAudience.Private
31  public interface IOEngine {
32    /**
33     * @return true if persistent storage is supported for the cache when shutdown
34     */
35    boolean isPersistent();
36  
37    /**
38     * Transfers data from IOEngine to the given byte buffer
39     * @param dstBuffer the given byte buffer into which bytes are to be written
40     * @param offset The offset in the IO engine where the first byte to be read
41     * @return number of bytes read
42     * @throws IOException
43     */
44    int read(ByteBuffer dstBuffer, long offset) throws IOException;
45  
46    /**
47     * Transfers data from the given byte buffer to IOEngine
48     * @param srcBuffer the given byte buffer from which bytes are to be read
49     * @param offset The offset in the IO engine where the first byte to be
50     *          written
51     * @throws IOException
52     */
53    void write(ByteBuffer srcBuffer, long offset) throws IOException;
54  
55    /**
56     * Sync the data to IOEngine after writing
57     * @throws IOException
58     */
59    void sync() throws IOException;
60  
61    /**
62     * Shutdown the IOEngine
63     */
64    void shutdown();
65  }