channelRead() — netty Function Reference
Architecture documentation for the channelRead() function in GlobalChannelTrafficShapingHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD ae77ebe1_84b2_b0c0_804c_46784f484fe4["channelRead()"] 70857fc2_a134_e299_7b48_1738d53c0016["GlobalChannelTrafficShapingHandler"] ae77ebe1_84b2_b0c0_804c_46784f484fe4 -->|defined in| 70857fc2_a134_e299_7b48_1738d53c0016 69a96252_28cc_c201_a07c_016f54efb94c["computeBalancedWait()"] ae77ebe1_84b2_b0c0_804c_46784f484fe4 -->|calls| 69a96252_28cc_c201_a07c_016f54efb94c 7e801b53_0b20_7901_ec31_c683f033fbe2["checkWaitReadTime()"] ae77ebe1_84b2_b0c0_804c_46784f484fe4 -->|calls| 7e801b53_0b20_7901_ec31_c683f033fbe2 14157cdc_f7dc_7027_fd43_a7b46fcd9b3f["informReadOperation()"] ae77ebe1_84b2_b0c0_804c_46784f484fe4 -->|calls| 14157cdc_f7dc_7027_fd43_a7b46fcd9b3f style ae77ebe1_84b2_b0c0_804c_46784f484fe4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.java lines 514–574
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
long size = calculateSize(msg);
long now = TrafficCounter.milliSecondFromNano();
if (size > 0) {
// compute the number of ms to wait before reopening the channel
long waitGlobal = trafficCounter.readTimeToWait(size, getReadLimit(), maxTime, now);
Integer key = ctx.channel().hashCode();
PerChannel perChannel = channelQueues.get(key);
long wait = 0;
if (perChannel != null) {
wait = perChannel.channelTrafficCounter.readTimeToWait(size, readChannelLimit, maxTime, now);
if (readDeviationActive) {
// now try to balance between the channels
long maxLocalRead;
maxLocalRead = perChannel.channelTrafficCounter.cumulativeReadBytes();
long maxGlobalRead = cumulativeReadBytes.get();
if (maxLocalRead <= 0) {
maxLocalRead = 0;
}
if (maxGlobalRead < maxLocalRead) {
maxGlobalRead = maxLocalRead;
}
wait = computeBalancedWait(maxLocalRead, maxGlobalRead, wait);
}
}
if (wait < waitGlobal) {
wait = waitGlobal;
}
wait = checkWaitReadTime(ctx, wait, now);
if (wait >= MINIMAL_WAIT) { // At least 10ms seems a minimal
// time in order to try to limit the traffic
// Only AutoRead AND HandlerActive True means Context Active
Channel channel = ctx.channel();
ChannelConfig config = channel.config();
if (logger.isDebugEnabled()) {
logger.debug("Read Suspend: " + wait + ':' + config.isAutoRead() + ':'
+ isHandlerActive(ctx));
}
if (config.isAutoRead() && isHandlerActive(ctx)) {
config.setAutoRead(false);
channel.attr(READ_SUSPENDED).set(true);
// Create a Runnable to reactive the read if needed. If one was create before it will just be
// reused to limit object creation
Attribute<Runnable> attr = channel.attr(REOPEN_TASK);
Runnable reopenTask = attr.get();
if (reopenTask == null) {
reopenTask = new ReopenReadTimerTask(ctx);
attr.set(reopenTask);
}
ctx.executor().schedule(reopenTask, wait, TimeUnit.MILLISECONDS);
if (logger.isDebugEnabled()) {
logger.debug("Suspend final status => " + config.isAutoRead() + ':'
+ isHandlerActive(ctx) + " will reopened at: " + wait);
}
}
}
}
informReadOperation(ctx, now);
ctx.fireChannelRead(msg);
}
Domain
Subdomains
Source
Frequently Asked Questions
What does channelRead() do?
channelRead() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.java.
Where is channelRead() defined?
channelRead() is defined in handler/src/main/java/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.java at line 514.
What does channelRead() call?
channelRead() calls 3 function(s): checkWaitReadTime, computeBalancedWait, informReadOperation.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free