1 /* 2 * Copyright 2012 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package org.jboss.netty.channel; 17 18 import org.jboss.netty.buffer.ChannelBuffer; 19 20 /** 21 * Predicts the number of readable bytes in the receive buffer of a 22 * {@link Channel}. 23 * <p> 24 * It calculates the close-to-optimal capacity of the {@link ChannelBuffer} 25 * for the next read operation depending on the actual number of read bytes 26 * in the previous read operation. More accurate the prediction is, more 27 * effective the memory utilization will be. 28 * <p> 29 * Once a read operation is performed and the actual number of read bytes is 30 * known, an I/O thread will call {@link #previousReceiveBufferSize(int)} to 31 * update the predictor so it can predict more accurately next time. 32 */ 33 public interface ReceiveBufferSizePredictor { 34 35 /** 36 * Predicts the capacity of the {@link ChannelBuffer} for the next 37 * read operation depending on the actual number of read bytes in the 38 * previous read operation. 39 * 40 * @return the expected number of readable bytes this time 41 */ 42 int nextReceiveBufferSize(); 43 44 /** 45 * Updates this predictor by specifying the actual number of read bytes 46 * in the previous read operation. 47 * 48 * @param previousReceiveBufferSize 49 * the actual number of read bytes in the previous read operation 50 */ 51 void previousReceiveBufferSize(int previousReceiveBufferSize); 52 }