@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { getOrSetPerChannel(ctx); trafficCounter.resetCumulativeTime(); super.handlerAdded(ctx); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { getOrSetPerChannel(ctx); super.handlerAdded(ctx); }
@Override protected void doAccounting(TrafficCounter counter) { computeDeviationCumulativeBytes(); super.doAccounting(counter); }
/** * Create the global TrafficCounter */ void createGlobalTrafficCounter(ScheduledExecutorService executor) { // Default setMaxDeviation(DEFAULT_DEVIATION, DEFAULT_SLOWDOWN, DEFAULT_ACCELERATION); if (executor == null) { throw new IllegalArgumentException("Executor must not be null"); } TrafficCounter tc = new GlobalChannelTrafficCounter(this, executor, "GlobalChannelTC", checkInterval); setTrafficCounter(tc); tc.start(); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { TrafficCounter trafficCounter = new TrafficCounter(this, ctx.executor(), "ChannelTC" + ctx.channel().hashCode(), checkInterval); setTrafficCounter(trafficCounter); trafficCounter.start(); super.handlerAdded(ctx); }
@Override public void run() { if (!monitorActive) { return; } resetAccounting(milliSecondFromNano()); if (trafficShapingHandler != null) { trafficShapingHandler.doAccounting(TrafficCounter.this); } scheduledFuture = executor.schedule(this, checkInterval.get(), TimeUnit.MILLISECONDS); } }
/** * Create the global TrafficCounter. */ void createGlobalTrafficCounter(ScheduledExecutorService executor) { if (executor == null) { throw new NullPointerException("executor"); } TrafficCounter tc = new TrafficCounter(this, executor, "GlobalTC", checkInterval); setTrafficCounter(tc); tc.start(); }
/** * <p>Note the change will be taken as best effort, meaning * that all already scheduled traffics will not be * changed, but only applied to new traffics.</p> * <p>So the expected usage of this method is to be used not too often, * accordingly to the traffic shaping configuration.</p> * * @param readLimit the readLimit to set */ public void setReadLimit(long readLimit) { this.readLimit = readLimit; if (trafficCounter != null) { trafficCounter.resetAccounting(TrafficCounter.milliSecondFromNano()); } }
@Override public Long getValue() { return tc.cumulativeReadBytes(); } });
/** * @param checkInterval the interval in ms between each step check to set, default value being 1000 ms. */ public void setCheckInterval(long checkInterval) { this.checkInterval = checkInterval; if (trafficCounter != null) { trafficCounter.configure(checkInterval); } }
/** * Release all internal resources of this instance. */ public final void release() { trafficCounter.stop(); }
/** * Explicitly release the Write suspended status. */ void releaseWriteSuspended(ChannelHandlerContext ctx) { setUserDefinedWritability(ctx, true); }
/** * Create a new instance using default Check Interval value of 1000 ms and * default max time as delay allowed value of 15000 ms and no limit. * * @param executor * the {@link ScheduledExecutorService} to use for the {@link TrafficCounter}. */ public GlobalTrafficShapingHandler(EventExecutor executor) { createGlobalTrafficCounter(executor); }
/** * Create a new instance. * * @param executor * the {@link ScheduledExecutorService} to use for the {@link TrafficCounter}. */ public GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor) { createGlobalTrafficCounter(executor); }
@Override public Long getValue() { return tc.lastWrittenBytes(); } });
/** * Change the check interval. * * @param newCheckInterval The new check interval (in milliseconds) */ public void configure(long newCheckInterval) { checkInterval = newCheckInterval; if (trafficCounter != null) { trafficCounter.configure(checkInterval); } }
/** * Release all internal resources of this instance. */ public final void release() { trafficCounter.stop(); }
/** * Check the writability according to delay and size for the channel. * Set if necessary setUserDefinedWritability status. * @param delay the computed delay * @param queueSize the current queueSize */ void checkWriteSuspend(ChannelHandlerContext ctx, long delay, long queueSize) { if (queueSize > maxWriteSize || delay > maxWriteDelay) { setUserDefinedWritability(ctx, false); } } /**
/** * Create a new instance using * default max time as delay allowed value of 15000 ms and no limit. * * @param executor * the {@link ScheduledExecutorService} to use for the {@link TrafficCounter}. * @param checkInterval * The delay between two computations of performances for * channels or 0 if no stats are to be computed. */ public GlobalTrafficShapingHandler(ScheduledExecutorService executor, long checkInterval) { super(checkInterval); createGlobalTrafficCounter(executor); }
/** * Create a new instance. * * @param executor * the {@link ScheduledExecutorService} to use for the {@link TrafficCounter}. * @param checkInterval * The delay between two computations of performances for * channels or 0 if no stats are to be computed. */ public GlobalChannelTrafficShapingHandler(ScheduledExecutorService executor, long checkInterval) { super(checkInterval); createGlobalTrafficCounter(executor); }