1 /* 2 * Copyright 2015 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 * https://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 io.netty.channel; 17 18 import java.util.Map.Entry; 19 20 /** 21 * {@link RecvByteBufAllocator} that limits a read operation based upon a maximum value per individual read 22 * and a maximum amount when a read operation is attempted by the event loop. 23 */ 24 public interface MaxBytesRecvByteBufAllocator extends RecvByteBufAllocator { 25 /** 26 * Returns the maximum number of bytes to read per read loop. 27 * a {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) channelRead()} event. 28 * If this value is greater than 1, an event loop might attempt to read multiple times to procure bytes. 29 */ 30 int maxBytesPerRead(); 31 32 /** 33 * Sets the maximum number of bytes to read per read loop. 34 * If this value is greater than 1, an event loop might attempt to read multiple times to procure bytes. 35 */ 36 MaxBytesRecvByteBufAllocator maxBytesPerRead(int maxBytesPerRead); 37 38 /** 39 * Returns the maximum number of bytes to read per individual read operation. 40 * a {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) channelRead()} event. 41 * If this value is greater than 1, an event loop might attempt to read multiple times to procure bytes. 42 */ 43 int maxBytesPerIndividualRead(); 44 45 /** 46 * Sets the maximum number of bytes to read per individual read operation. 47 * If this value is greater than 1, an event loop might attempt to read multiple times to procure bytes. 48 */ 49 MaxBytesRecvByteBufAllocator maxBytesPerIndividualRead(int maxBytesPerIndividualRead); 50 51 /** 52 * Atomic way to get the maximum number of bytes to read for a read loop and per individual read operation. 53 * If this value is greater than 1, an event loop might attempt to read multiple times to procure bytes. 54 * @return The Key is from {@link #maxBytesPerRead()}. The Value is from {@link #maxBytesPerIndividualRead()} 55 */ 56 Entry<Integer, Integer> maxBytesPerReadPair(); 57 58 /** 59 * Sets the maximum number of bytes to read for a read loop and per individual read operation. 60 * If this value is greater than 1, an event loop might attempt to read multiple times to procure bytes. 61 * @param maxBytesPerRead see {@link #maxBytesPerRead(int)} 62 * @param maxBytesPerIndividualRead see {@link #maxBytesPerIndividualRead(int)} 63 */ 64 MaxBytesRecvByteBufAllocator maxBytesPerReadPair(int maxBytesPerRead, int maxBytesPerIndividualRead); 65 }