001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.io; 019 020import java.nio.ByteBuffer; 021 022import org.apache.hadoop.classification.InterfaceAudience; 023import org.apache.hadoop.classification.InterfaceStability; 024 025@InterfaceAudience.Public 026@InterfaceStability.Stable 027public interface ByteBufferPool { 028 /** 029 * Get a new direct ByteBuffer. The pool can provide this from 030 * removing a buffer from its internal cache, or by allocating a 031 * new buffer. 032 * 033 * @param direct Whether the buffer should be direct. 034 * @param length The minimum length the buffer will have. 035 * @return A new ByteBuffer. This ByteBuffer must be direct. 036 * Its capacity can be less than what was requested, but 037 * must be at least 1 byte. 038 */ 039 ByteBuffer getBuffer(boolean direct, int length); 040 041 /** 042 * Release a buffer back to the pool. 043 * The pool may choose to put this buffer into its cache. 044 * 045 * @param buffer a direct bytebuffer 046 */ 047 void putBuffer(ByteBuffer buffer); 048}