package io.netty.handler.traffic;

import g.a.a.a.a;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.traffic.AbstractTrafficShapingHandler;
import io.netty.util.Attribute;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.util.AbstractCollection;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import kotlinx.serialization.json.internal.AbstractJsonLexerKt;

/* JADX INFO: loaded from: classes.dex */
@ChannelHandler.Sharable
public class GlobalChannelTrafficShapingHandler extends AbstractTrafficShapingHandler {
    private static final float DEFAULT_ACCELERATION = -0.1f;
    private static final float DEFAULT_DEVIATION = 0.1f;
    private static final float DEFAULT_SLOWDOWN = 0.4f;
    private static final float MAX_DEVIATION = 0.4f;
    private static final InternalLogger logger = InternalLoggerFactory.getInstance((Class<?>) GlobalChannelTrafficShapingHandler.class);
    private volatile float accelerationFactor;
    public final ConcurrentMap<Integer, PerChannel> channelQueues;
    private final AtomicLong cumulativeReadBytes;
    private final AtomicLong cumulativeWrittenBytes;
    private volatile float maxDeviation;
    public volatile long maxGlobalWriteSize;
    private final AtomicLong queuesSize;
    private volatile long readChannelLimit;
    private volatile boolean readDeviationActive;
    private volatile float slowDownFactor;
    private volatile long writeChannelLimit;
    private volatile boolean writeDeviationActive;

    public static final class PerChannel {
        public TrafficCounter channelTrafficCounter;
        public long lastReadTimestamp;
        public long lastWriteTimestamp;
        public ArrayDeque<ToSend> messagesQueue;
        public long queueSize;
    }

    public static final class ToSend {
        public final ChannelPromise promise;
        public final long relativeTimeAction;
        public final long size;
        public final Object toSend;

        private ToSend(long j2, Object obj, long j3, ChannelPromise channelPromise) {
            this.relativeTimeAction = j2;
            this.toSend = obj;
            this.size = j3;
            this.promise = channelPromise;
        }
    }

    public GlobalChannelTrafficShapingHandler(ScheduledExecutorService scheduledExecutorService) {
        this.channelQueues = PlatformDependent.newConcurrentHashMap();
        this.queuesSize = new AtomicLong();
        this.cumulativeWrittenBytes = new AtomicLong();
        this.cumulativeReadBytes = new AtomicLong();
        this.maxGlobalWriteSize = 419430400L;
        createGlobalTrafficCounter(scheduledExecutorService);
    }

    public GlobalChannelTrafficShapingHandler(ScheduledExecutorService scheduledExecutorService, long j2) {
        super(j2);
        this.channelQueues = PlatformDependent.newConcurrentHashMap();
        this.queuesSize = new AtomicLong();
        this.cumulativeWrittenBytes = new AtomicLong();
        this.cumulativeReadBytes = new AtomicLong();
        this.maxGlobalWriteSize = 419430400L;
        createGlobalTrafficCounter(scheduledExecutorService);
    }

    public GlobalChannelTrafficShapingHandler(ScheduledExecutorService scheduledExecutorService, long j2, long j3, long j4, long j5) {
        super(j2, j3);
        this.channelQueues = PlatformDependent.newConcurrentHashMap();
        this.queuesSize = new AtomicLong();
        this.cumulativeWrittenBytes = new AtomicLong();
        this.cumulativeReadBytes = new AtomicLong();
        this.maxGlobalWriteSize = 419430400L;
        this.writeChannelLimit = j4;
        this.readChannelLimit = j5;
        createGlobalTrafficCounter(scheduledExecutorService);
    }

    public GlobalChannelTrafficShapingHandler(ScheduledExecutorService scheduledExecutorService, long j2, long j3, long j4, long j5, long j6) {
        super(j2, j3, j6);
        this.channelQueues = PlatformDependent.newConcurrentHashMap();
        this.queuesSize = new AtomicLong();
        this.cumulativeWrittenBytes = new AtomicLong();
        this.cumulativeReadBytes = new AtomicLong();
        this.maxGlobalWriteSize = 419430400L;
        this.writeChannelLimit = j4;
        this.readChannelLimit = j5;
        createGlobalTrafficCounter(scheduledExecutorService);
    }

    public GlobalChannelTrafficShapingHandler(ScheduledExecutorService scheduledExecutorService, long j2, long j3, long j4, long j5, long j6, long j7) {
        super(j2, j3, j6, j7);
        this.channelQueues = PlatformDependent.newConcurrentHashMap();
        this.queuesSize = new AtomicLong();
        this.cumulativeWrittenBytes = new AtomicLong();
        this.cumulativeReadBytes = new AtomicLong();
        this.maxGlobalWriteSize = 419430400L;
        createGlobalTrafficCounter(scheduledExecutorService);
        this.writeChannelLimit = j4;
        this.readChannelLimit = j5;
    }

    private long computeBalancedWait(float f2, float f3, long j2) {
        float f4;
        if (f3 == 0.0f) {
            return j2;
        }
        float f5 = f2 / f3;
        if (f5 <= this.maxDeviation) {
            f4 = this.accelerationFactor;
        } else {
            if (f5 < 1.0f - this.maxDeviation) {
                return j2;
            }
            f4 = this.slowDownFactor;
            if (j2 < 10) {
                j2 = 10;
            }
        }
        return (long) (j2 * f4);
    }

    private void computeDeviationCumulativeBytes() {
        long j2 = Long.MAX_VALUE;
        long j3 = 0;
        long j4 = 0;
        long j5 = Long.MAX_VALUE;
        for (PerChannel perChannel : this.channelQueues.values()) {
            long jCumulativeWrittenBytes = perChannel.channelTrafficCounter.cumulativeWrittenBytes();
            if (j3 < jCumulativeWrittenBytes) {
                j3 = jCumulativeWrittenBytes;
            }
            if (j2 > jCumulativeWrittenBytes) {
                j2 = jCumulativeWrittenBytes;
            }
            long jCumulativeReadBytes = perChannel.channelTrafficCounter.cumulativeReadBytes();
            if (j4 < jCumulativeReadBytes) {
                j4 = jCumulativeReadBytes;
            }
            if (j5 > jCumulativeReadBytes) {
                j5 = jCumulativeReadBytes;
            }
        }
        boolean z2 = false;
        boolean z3 = this.channelQueues.size() > 1;
        this.readDeviationActive = z3 && j5 < j4 / 2;
        if (z3 && j2 < j3 / 2) {
            z2 = true;
        }
        this.writeDeviationActive = z2;
        this.cumulativeWrittenBytes.set(j3);
        this.cumulativeReadBytes.set(j4);
    }

    private PerChannel getOrSetPerChannel(ChannelHandlerContext channelHandlerContext) {
        Integer numValueOf = Integer.valueOf(channelHandlerContext.channel().hashCode());
        PerChannel perChannel = this.channelQueues.get(numValueOf);
        if (perChannel != null) {
            return perChannel;
        }
        PerChannel perChannel2 = new PerChannel();
        perChannel2.messagesQueue = new ArrayDeque<>();
        StringBuilder sbF = a.F("ChannelTC");
        sbF.append(channelHandlerContext.channel().hashCode());
        perChannel2.channelTrafficCounter = new TrafficCounter(this, null, sbF.toString(), this.checkInterval);
        perChannel2.queueSize = 0L;
        long jMilliSecondFromNano = TrafficCounter.milliSecondFromNano();
        perChannel2.lastReadTimestamp = jMilliSecondFromNano;
        perChannel2.lastWriteTimestamp = jMilliSecondFromNano;
        this.channelQueues.put(numValueOf, perChannel2);
        return perChannel2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendAllValid(ChannelHandlerContext channelHandlerContext, PerChannel perChannel, long j2) {
        synchronized (perChannel) {
            ToSend toSendPollFirst = perChannel.messagesQueue.pollFirst();
            while (true) {
                ToSend toSend = toSendPollFirst;
                if (toSend != null) {
                    if (toSend.relativeTimeAction > j2) {
                        perChannel.messagesQueue.addFirst(toSend);
                        break;
                    }
                    long j3 = toSend.size;
                    this.trafficCounter.bytesRealWriteFlowControl(j3);
                    perChannel.channelTrafficCounter.bytesRealWriteFlowControl(j3);
                    perChannel.queueSize -= j3;
                    this.queuesSize.addAndGet(-j3);
                    channelHandlerContext.write(toSend.toSend, toSend.promise);
                    perChannel.lastWriteTimestamp = j2;
                    toSendPollFirst = perChannel.messagesQueue.pollFirst();
                } else {
                    break;
                }
            }
            if (perChannel.messagesQueue.isEmpty()) {
                releaseWriteSuspended(channelHandlerContext);
            }
        }
        channelHandlerContext.flush();
    }

    public float accelerationFactor() {
        return this.accelerationFactor;
    }

    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler, io.netty.channel.ChannelInboundHandlerAdapter, io.netty.channel.ChannelInboundHandler
    public void channelRead(ChannelHandlerContext channelHandlerContext, Object obj) {
        long j2;
        long jCalculateSize = calculateSize(obj);
        long jMilliSecondFromNano = TrafficCounter.milliSecondFromNano();
        if (jCalculateSize > 0) {
            long timeToWait = this.trafficCounter.readTimeToWait(jCalculateSize, getReadLimit(), this.maxTime, jMilliSecondFromNano);
            PerChannel perChannel = this.channelQueues.get(Integer.valueOf(channelHandlerContext.channel().hashCode()));
            if (perChannel != null) {
                long timeToWait2 = perChannel.channelTrafficCounter.readTimeToWait(jCalculateSize, this.readChannelLimit, this.maxTime, jMilliSecondFromNano);
                if (this.readDeviationActive) {
                    long jCumulativeReadBytes = perChannel.channelTrafficCounter.cumulativeReadBytes();
                    long j3 = this.cumulativeReadBytes.get();
                    jComputeBalancedWait = jCumulativeReadBytes > 0 ? jCumulativeReadBytes : 0L;
                    if (j3 < jComputeBalancedWait) {
                        j3 = jComputeBalancedWait;
                    }
                    jComputeBalancedWait = computeBalancedWait(jComputeBalancedWait, j3, timeToWait2);
                } else {
                    jComputeBalancedWait = timeToWait2;
                }
            }
            if (jComputeBalancedWait < timeToWait) {
                jComputeBalancedWait = timeToWait;
            }
            j2 = jMilliSecondFromNano;
            long jCheckWaitReadTime = checkWaitReadTime(channelHandlerContext, jComputeBalancedWait, jMilliSecondFromNano);
            if (jCheckWaitReadTime >= 10) {
                Channel channel = channelHandlerContext.channel();
                ChannelConfig channelConfigConfig = channel.config();
                InternalLogger internalLogger = logger;
                if (internalLogger.isDebugEnabled()) {
                    internalLogger.debug("Read Suspend: " + jCheckWaitReadTime + AbstractJsonLexerKt.COLON + channelConfigConfig.isAutoRead() + AbstractJsonLexerKt.COLON + AbstractTrafficShapingHandler.isHandlerActive(channelHandlerContext));
                }
                if (channelConfigConfig.isAutoRead() && AbstractTrafficShapingHandler.isHandlerActive(channelHandlerContext)) {
                    channelConfigConfig.setAutoRead(false);
                    channel.attr(AbstractTrafficShapingHandler.READ_SUSPENDED).set(Boolean.TRUE);
                    Attribute attributeAttr = channel.attr(AbstractTrafficShapingHandler.REOPEN_TASK);
                    Runnable reopenReadTimerTask = (Runnable) attributeAttr.get();
                    if (reopenReadTimerTask == null) {
                        reopenReadTimerTask = new AbstractTrafficShapingHandler.ReopenReadTimerTask(channelHandlerContext);
                        attributeAttr.set(reopenReadTimerTask);
                    }
                    channelHandlerContext.executor().schedule(reopenReadTimerTask, jCheckWaitReadTime, TimeUnit.MILLISECONDS);
                    if (internalLogger.isDebugEnabled()) {
                        StringBuilder sbF = a.F("Suspend final status => ");
                        sbF.append(channelConfigConfig.isAutoRead());
                        sbF.append(AbstractJsonLexerKt.COLON);
                        sbF.append(AbstractTrafficShapingHandler.isHandlerActive(channelHandlerContext));
                        sbF.append(" will reopened at: ");
                        sbF.append(jCheckWaitReadTime);
                        internalLogger.debug(sbF.toString());
                    }
                }
            }
        } else {
            j2 = jMilliSecondFromNano;
        }
        informReadOperation(channelHandlerContext, j2);
        channelHandlerContext.fireChannelRead(obj);
    }

    public Collection<TrafficCounter> channelTrafficCounters() {
        return new AbstractCollection<TrafficCounter>() { // from class: io.netty.handler.traffic.GlobalChannelTrafficShapingHandler.1
            @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
            public Iterator<TrafficCounter> iterator() {
                return new Iterator<TrafficCounter>() { // from class: io.netty.handler.traffic.GlobalChannelTrafficShapingHandler.1.1
                    public final Iterator<PerChannel> iter;

                    {
                        this.iter = GlobalChannelTrafficShapingHandler.this.channelQueues.values().iterator();
                    }

                    @Override // java.util.Iterator
                    public boolean hasNext() {
                        return this.iter.hasNext();
                    }

                    /* JADX WARN: Can't rename method to resolve collision */
                    @Override // java.util.Iterator
                    public TrafficCounter next() {
                        return this.iter.next().channelTrafficCounter;
                    }

                    @Override // java.util.Iterator
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }

            @Override // java.util.AbstractCollection, java.util.Collection
            public int size() {
                return GlobalChannelTrafficShapingHandler.this.channelQueues.size();
            }
        };
    }

    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler
    public long checkWaitReadTime(ChannelHandlerContext channelHandlerContext, long j2, long j3) {
        PerChannel perChannel = this.channelQueues.get(Integer.valueOf(channelHandlerContext.channel().hashCode()));
        return (perChannel == null || j2 <= this.maxTime || (j3 + j2) - perChannel.lastReadTimestamp <= this.maxTime) ? j2 : this.maxTime;
    }

    public void configureChannel(long j2, long j3) {
        this.writeChannelLimit = j2;
        this.readChannelLimit = j3;
        long jMilliSecondFromNano = TrafficCounter.milliSecondFromNano();
        Iterator<PerChannel> it = this.channelQueues.values().iterator();
        while (it.hasNext()) {
            it.next().channelTrafficCounter.resetAccounting(jMilliSecondFromNano);
        }
    }

    public void createGlobalTrafficCounter(ScheduledExecutorService scheduledExecutorService) {
        setMaxDeviation(DEFAULT_DEVIATION, 0.4f, DEFAULT_ACCELERATION);
        if (scheduledExecutorService == null) {
            throw new IllegalArgumentException("Executor must not be null");
        }
        GlobalChannelTrafficCounter globalChannelTrafficCounter = new GlobalChannelTrafficCounter(this, scheduledExecutorService, "GlobalChannelTC", this.checkInterval);
        setTrafficCounter(globalChannelTrafficCounter);
        globalChannelTrafficCounter.start();
    }

    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler
    public void doAccounting(TrafficCounter trafficCounter) {
        computeDeviationCumulativeBytes();
        super.doAccounting(trafficCounter);
    }

    public long getMaxGlobalWriteSize() {
        return this.maxGlobalWriteSize;
    }

    public long getReadChannelLimit() {
        return this.readChannelLimit;
    }

    public long getWriteChannelLimit() {
        return this.writeChannelLimit;
    }

    @Override // io.netty.channel.ChannelHandlerAdapter, io.netty.channel.ChannelHandler
    public void handlerAdded(ChannelHandlerContext channelHandlerContext) {
        getOrSetPerChannel(channelHandlerContext);
        this.trafficCounter.resetCumulativeTime();
        super.handlerAdded(channelHandlerContext);
    }

    @Override // io.netty.channel.ChannelHandlerAdapter, io.netty.channel.ChannelHandler
    public void handlerRemoved(ChannelHandlerContext channelHandlerContext) {
        this.trafficCounter.resetCumulativeTime();
        Channel channel = channelHandlerContext.channel();
        PerChannel perChannelRemove = this.channelQueues.remove(Integer.valueOf(channel.hashCode()));
        if (perChannelRemove != null) {
            synchronized (perChannelRemove) {
                if (channel.isActive()) {
                    for (ToSend toSend : perChannelRemove.messagesQueue) {
                        long jCalculateSize = calculateSize(toSend.toSend);
                        this.trafficCounter.bytesRealWriteFlowControl(jCalculateSize);
                        perChannelRemove.channelTrafficCounter.bytesRealWriteFlowControl(jCalculateSize);
                        perChannelRemove.queueSize -= jCalculateSize;
                        this.queuesSize.addAndGet(-jCalculateSize);
                        channelHandlerContext.write(toSend.toSend, toSend.promise);
                    }
                } else {
                    this.queuesSize.addAndGet(-perChannelRemove.queueSize);
                    Iterator<ToSend> it = perChannelRemove.messagesQueue.iterator();
                    while (it.hasNext()) {
                        Object obj = it.next().toSend;
                        if (obj instanceof ByteBuf) {
                            ((ByteBuf) obj).release();
                        }
                    }
                }
                perChannelRemove.messagesQueue.clear();
            }
        }
        releaseWriteSuspended(channelHandlerContext);
        releaseReadSuspended(channelHandlerContext);
        super.handlerRemoved(channelHandlerContext);
    }

    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler
    public void informReadOperation(ChannelHandlerContext channelHandlerContext, long j2) {
        PerChannel perChannel = this.channelQueues.get(Integer.valueOf(channelHandlerContext.channel().hashCode()));
        if (perChannel != null) {
            perChannel.lastReadTimestamp = j2;
        }
    }

    public float maxDeviation() {
        return this.maxDeviation;
    }

    public long maximumCumulativeReadBytes() {
        return this.cumulativeReadBytes.get();
    }

    public long maximumCumulativeWrittenBytes() {
        return this.cumulativeWrittenBytes.get();
    }

    public long queuesSize() {
        return this.queuesSize.get();
    }

    public final void release() {
        this.trafficCounter.stop();
    }

    public void setMaxDeviation(float f2, float f3, float f4) {
        if (f2 > 0.4f) {
            throw new IllegalArgumentException("maxDeviation must be <= 0.4");
        }
        if (f3 < 0.0f) {
            throw new IllegalArgumentException("slowDownFactor must be >= 0");
        }
        if (f4 > 0.0f) {
            throw new IllegalArgumentException("accelerationFactor must be <= 0");
        }
        this.maxDeviation = f2;
        this.accelerationFactor = f4 + 1.0f;
        this.slowDownFactor = f3 + 1.0f;
    }

    public void setMaxGlobalWriteSize(long j2) {
        if (j2 <= 0) {
            throw new IllegalArgumentException("maxGlobalWriteSize must be positive");
        }
        this.maxGlobalWriteSize = j2;
    }

    public void setReadChannelLimit(long j2) {
        this.readChannelLimit = j2;
        long jMilliSecondFromNano = TrafficCounter.milliSecondFromNano();
        Iterator<PerChannel> it = this.channelQueues.values().iterator();
        while (it.hasNext()) {
            it.next().channelTrafficCounter.resetAccounting(jMilliSecondFromNano);
        }
    }

    public void setWriteChannelLimit(long j2) {
        this.writeChannelLimit = j2;
        long jMilliSecondFromNano = TrafficCounter.milliSecondFromNano();
        Iterator<PerChannel> it = this.channelQueues.values().iterator();
        while (it.hasNext()) {
            it.next().channelTrafficCounter.resetAccounting(jMilliSecondFromNano);
        }
    }

    public float slowDownFactor() {
        return this.slowDownFactor;
    }

    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler
    public void submitWrite(final ChannelHandlerContext channelHandlerContext, Object obj, long j2, long j3, long j4, ChannelPromise channelPromise) {
        PerChannel orSetPerChannel = this.channelQueues.get(Integer.valueOf(channelHandlerContext.channel().hashCode()));
        if (orSetPerChannel == null) {
            orSetPerChannel = getOrSetPerChannel(channelHandlerContext);
        }
        final PerChannel perChannel = orSetPerChannel;
        synchronized (perChannel) {
            if (j3 == 0) {
                if (perChannel.messagesQueue.isEmpty()) {
                    this.trafficCounter.bytesRealWriteFlowControl(j2);
                    perChannel.channelTrafficCounter.bytesRealWriteFlowControl(j2);
                    channelHandlerContext.write(obj, channelPromise);
                    perChannel.lastWriteTimestamp = j4;
                    return;
                }
            }
            long j5 = (j3 <= this.maxTime || (j4 + j3) - perChannel.lastWriteTimestamp <= this.maxTime) ? j3 : this.maxTime;
            ToSend toSend = new ToSend(j5 + j4, obj, j2, channelPromise);
            perChannel.messagesQueue.addLast(toSend);
            perChannel.queueSize += j2;
            this.queuesSize.addAndGet(j2);
            checkWriteSuspend(channelHandlerContext, j5, perChannel.queueSize);
            boolean z2 = this.queuesSize.get() > this.maxGlobalWriteSize;
            if (z2) {
                setUserDefinedWritability(channelHandlerContext, false);
            }
            final long j6 = toSend.relativeTimeAction;
            channelHandlerContext.executor().schedule(new Runnable() { // from class: io.netty.handler.traffic.GlobalChannelTrafficShapingHandler.2
                @Override // java.lang.Runnable
                public void run() {
                    GlobalChannelTrafficShapingHandler.this.sendAllValid(channelHandlerContext, perChannel, j6);
                }
            }, j5, TimeUnit.MILLISECONDS);
        }
    }

    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler
    public String toString() {
        StringBuilder sb = new StringBuilder(340);
        sb.append(super.toString());
        sb.append(" Write Channel Limit: ");
        sb.append(this.writeChannelLimit);
        sb.append(" Read Channel Limit: ");
        sb.append(this.readChannelLimit);
        return sb.toString();
    }

    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler
    public int userDefinedWritabilityIndex() {
        return 3;
    }

    /* JADX WARN: Removed duplicated region for block: B:29:0x00bf  */
    @Override // io.netty.handler.traffic.AbstractTrafficShapingHandler, io.netty.channel.ChannelDuplexHandler, io.netty.channel.ChannelOutboundHandler
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void write(io.netty.channel.ChannelHandlerContext r21, java.lang.Object r22, io.netty.channel.ChannelPromise r23) {
        /*
            r20 = this;
            r10 = r20
            r2 = r22
            long r3 = r10.calculateSize(r2)
            long r7 = io.netty.handler.traffic.TrafficCounter.milliSecondFromNano()
            r0 = 0
            int r5 = (r3 > r0 ? 1 : (r3 == r0 ? 0 : -1))
            if (r5 <= 0) goto Lbf
            io.netty.handler.traffic.TrafficCounter r11 = r10.trafficCounter
            long r14 = r20.getWriteLimit()
            long r5 = r10.maxTime
            r12 = r3
            r16 = r5
            r18 = r7
            long r5 = r11.writeTimeToWait(r12, r14, r16, r18)
            io.netty.channel.Channel r9 = r21.channel()
            int r9 = r9.hashCode()
            java.lang.Integer r9 = java.lang.Integer.valueOf(r9)
            java.util.concurrent.ConcurrentMap<java.lang.Integer, io.netty.handler.traffic.GlobalChannelTrafficShapingHandler$PerChannel> r11 = r10.channelQueues
            java.lang.Object r9 = r11.get(r9)
            io.netty.handler.traffic.GlobalChannelTrafficShapingHandler$PerChannel r9 = (io.netty.handler.traffic.GlobalChannelTrafficShapingHandler.PerChannel) r9
            if (r9 == 0) goto L6d
            io.netty.handler.traffic.TrafficCounter r11 = r9.channelTrafficCounter
            long r14 = r10.writeChannelLimit
            long r12 = r10.maxTime
            r16 = r12
            r12 = r3
            r18 = r7
            long r11 = r11.writeTimeToWait(r12, r14, r16, r18)
            boolean r13 = r10.writeDeviationActive
            if (r13 == 0) goto L6c
            io.netty.handler.traffic.TrafficCounter r9 = r9.channelTrafficCounter
            long r13 = r9.cumulativeWrittenBytes()
            java.util.concurrent.atomic.AtomicLong r9 = r10.cumulativeWrittenBytes
            long r15 = r9.get()
            int r9 = (r13 > r0 ? 1 : (r13 == r0 ? 0 : -1))
            if (r9 > 0) goto L5d
            goto L5e
        L5d:
            r0 = r13
        L5e:
            int r9 = (r15 > r0 ? 1 : (r15 == r0 ? 0 : -1))
            if (r9 >= 0) goto L64
            r13 = r0
            goto L65
        L64:
            r13 = r15
        L65:
            float r0 = (float) r0
            float r1 = (float) r13
            long r0 = r10.computeBalancedWait(r0, r1, r11)
            goto L6d
        L6c:
            r0 = r11
        L6d:
            int r9 = (r0 > r5 ? 1 : (r0 == r5 ? 0 : -1))
            if (r9 >= 0) goto L72
            goto L73
        L72:
            r5 = r0
        L73:
            r0 = 10
            int r0 = (r5 > r0 ? 1 : (r5 == r0 ? 0 : -1))
            if (r0 < 0) goto Lbf
            io.netty.util.internal.logging.InternalLogger r0 = io.netty.handler.traffic.GlobalChannelTrafficShapingHandler.logger
            boolean r1 = r0.isDebugEnabled()
            if (r1 == 0) goto Lb3
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r1.<init>()
            java.lang.String r9 = "Write suspend: "
            r1.append(r9)
            r1.append(r5)
            r9 = 58
            r1.append(r9)
            io.netty.channel.Channel r11 = r21.channel()
            io.netty.channel.ChannelConfig r11 = r11.config()
            boolean r11 = r11.isAutoRead()
            r1.append(r11)
            r1.append(r9)
            boolean r9 = io.netty.handler.traffic.AbstractTrafficShapingHandler.isHandlerActive(r21)
            r1.append(r9)
            java.lang.String r1 = r1.toString()
            r0.debug(r1)
        Lb3:
            r0 = r20
            r1 = r21
            r2 = r22
            r9 = r23
            r0.submitWrite(r1, r2, r3, r5, r7, r9)
            return
        Lbf:
            r5 = 0
            goto Lb3
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.handler.traffic.GlobalChannelTrafficShapingHandler.write(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise):void");
    }
}
