Home / Function/ submitWrite() — netty Function Reference

submitWrite() — netty Function Reference

Architecture documentation for the submitWrite() function in GlobalTrafficShapingHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  54f6e54e_8782_c399_da86_551bdcf1fafe["submitWrite()"]
  25ae99c4_4bb1_9893_ce25_fa54995d6af1["GlobalTrafficShapingHandler"]
  54f6e54e_8782_c399_da86_551bdcf1fafe -->|defined in| 25ae99c4_4bb1_9893_ce25_fa54995d6af1
  05ea496a_b677_4176_c1f4_c62c517a8169["ToSend()"]
  54f6e54e_8782_c399_da86_551bdcf1fafe -->|calls| 05ea496a_b677_4176_c1f4_c62c517a8169
  671aee98_3b6a_90b2_4e2d_667b72384afa["sendAllValid()"]
  54f6e54e_8782_c399_da86_551bdcf1fafe -->|calls| 671aee98_3b6a_90b2_4e2d_667b72384afa
  style 54f6e54e_8782_c399_da86_551bdcf1fafe fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/traffic/GlobalTrafficShapingHandler.java lines 330–376

    @Override
    void submitWrite(final ChannelHandlerContext ctx, final Object msg,
            final long size, final long writedelay, final long now,
            final ChannelPromise promise) {
        Channel channel = ctx.channel();
        Integer key = channel.hashCode();
        PerChannel perChannel = channelQueues.get(key);
        if (perChannel == null) {
            // in case write occurs before handlerAdded is raised for this handler
            // imply a synchronized only if needed
            perChannel = getOrSetPerChannel(ctx);
        }
        final ToSend newToSend;
        long delay = writedelay;
        boolean globalSizeExceeded = false;
        // write operations need synchronization
        synchronized (perChannel) {
            if (writedelay == 0 && perChannel.messagesQueue.isEmpty()) {
                trafficCounter.bytesRealWriteFlowControl(size);
                ctx.write(msg, promise);
                perChannel.lastWriteTimestamp = now;
                return;
            }
            if (delay > maxTime && now + delay - perChannel.lastWriteTimestamp > maxTime) {
                delay = maxTime;
            }
            newToSend = new ToSend(delay + now, msg, size, promise);
            perChannel.messagesQueue.addLast(newToSend);
            perChannel.queueSize += size;
            queuesSize.addAndGet(size);
            checkWriteSuspend(ctx, delay, perChannel.queueSize);
            if (queuesSize.get() > maxGlobalWriteSize) {
                globalSizeExceeded = true;
            }
        }
        if (globalSizeExceeded) {
            setUserDefinedWritability(ctx, false);
        }
        final long futureNow = newToSend.relativeTimeAction;
        final PerChannel forSchedule = perChannel;
        ctx.executor().schedule(new Runnable() {
            @Override
            public void run() {
                sendAllValid(ctx, forSchedule, futureNow);
            }
        }, delay, TimeUnit.MILLISECONDS);
    }

Domain

Subdomains

Frequently Asked Questions

What does submitWrite() do?
submitWrite() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/traffic/GlobalTrafficShapingHandler.java.
Where is submitWrite() defined?
submitWrite() is defined in handler/src/main/java/io/netty/handler/traffic/GlobalTrafficShapingHandler.java at line 330.
What does submitWrite() call?
submitWrite() calls 2 function(s): ToSend, sendAllValid.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free