Example usage for io.netty.handler.traffic ChannelTrafficShapingHandler trafficCounter

List of usage examples for io.netty.handler.traffic ChannelTrafficShapingHandler trafficCounter

Introduction

In this page you can find the example usage for io.netty.handler.traffic ChannelTrafficShapingHandler trafficCounter.

Prototype

public TrafficCounter trafficCounter() 

Source Link

Usage

From source file:org.waarp.openr66.protocol.utils.ChannelUtils.java

License:Open Source License

/**
 * Compute Wait for Traffic in Write (ugly turn around)
 * /*  w ww . ja  v a  2  s . c  o  m*/
 * @param cts
 * @param size
 * @return the wait in ms
 */
public static final long willBeWaitingWriting(ChannelTrafficShapingHandler cts, int size) {
    long currentTime = System.currentTimeMillis();
    if (cts != null && Configuration.configuration.getServerChannelWriteLimit() > 0) {
        TrafficCounter tc = cts.trafficCounter();
        if (tc != null) {
            long wait = waitTraffic(Configuration.configuration.getServerChannelWriteLimit(),
                    tc.currentWrittenBytes() + size, tc.lastTime(), currentTime);
            if (wait > 0) {
                return wait;
            }
        }
    }
    if (Configuration.configuration.getServerGlobalWriteLimit() > 0) {
        GlobalTrafficHandler gts = Configuration.configuration.getGlobalTrafficShapingHandler();
        if (gts != null) {
            TrafficCounter tc = gts.trafficCounter();
            if (tc != null) {
                long wait = waitTraffic(Configuration.configuration.getServerGlobalWriteLimit(),
                        tc.currentWrittenBytes() + size, tc.lastTime(), currentTime);
                if (wait > 0) {
                    return wait;
                }
            }
        }
    }
    return 0;
}