Same fix than in version 3.5 for Master branch (refer to issue #345)
Will be proposed once the one in 3.5 will be validated
This commit is contained in:
parent
54c97d0720
commit
714e3d682e
@ -15,8 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.traffic;
|
package io.netty.handler.traffic;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipelineFactory;
|
import io.netty.channel.ChannelPipelineFactory;
|
||||||
import io.netty.channel.ChannelStateEvent;
|
import io.netty.channel.ChannelStateEvent;
|
||||||
@ -24,6 +22,7 @@ import io.netty.handler.execution.ExecutionHandler;
|
|||||||
import io.netty.handler.execution.MemoryAwareThreadPoolExecutor;
|
import io.netty.handler.execution.MemoryAwareThreadPoolExecutor;
|
||||||
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
||||||
import io.netty.handler.execution.ObjectSizeEstimator;
|
import io.netty.handler.execution.ObjectSizeEstimator;
|
||||||
|
import io.netty.util.Timer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This implementation of the {@link AbstractTrafficShapingHandler} is for channel
|
* This implementation of the {@link AbstractTrafficShapingHandler} is for channel
|
||||||
@ -33,8 +32,8 @@ import io.netty.handler.execution.ObjectSizeEstimator;
|
|||||||
* <ul>
|
* <ul>
|
||||||
* <li>Add in your pipeline a new ChannelTrafficShapingHandler, before a recommended {@link ExecutionHandler} (like
|
* <li>Add in your pipeline a new ChannelTrafficShapingHandler, before a recommended {@link ExecutionHandler} (like
|
||||||
* {@link OrderedMemoryAwareThreadPoolExecutor} or {@link MemoryAwareThreadPoolExecutor}).<br>
|
* {@link OrderedMemoryAwareThreadPoolExecutor} or {@link MemoryAwareThreadPoolExecutor}).<br>
|
||||||
* <tt>ChannelTrafficShapingHandler myHandler = new ChannelTrafficShapingHandler(executor);</tt><br>
|
* <tt>ChannelTrafficShapingHandler myHandler = new ChannelTrafficShapingHandler(timer);</tt><br>
|
||||||
* executor could be created using <tt>Executors.newCachedThreadPool();</tt><br>
|
* timer could be created using <tt>HashedWheelTimer<tt><br>
|
||||||
* <tt>pipeline.addLast("CHANNEL_TRAFFIC_SHAPING", myHandler);</tt><br><br>
|
* <tt>pipeline.addLast("CHANNEL_TRAFFIC_SHAPING", myHandler);</tt><br><br>
|
||||||
*
|
*
|
||||||
* <b>Note that this handler has a Pipeline Coverage of "one" which means a new handler must be created
|
* <b>Note that this handler has a Pipeline Coverage of "one" which means a new handler must be created
|
||||||
@ -52,7 +51,7 @@ import io.netty.handler.execution.ObjectSizeEstimator;
|
|||||||
* the less precise the traffic shaping will be. It is suggested as higher value something close
|
* the less precise the traffic shaping will be. It is suggested as higher value something close
|
||||||
* to 5 or 10 minutes.<br>
|
* to 5 or 10 minutes.<br>
|
||||||
* </li>
|
* </li>
|
||||||
* <li>When you shutdown your application, release all the external resources like the executor
|
* <li>When you shutdown your application, release all the external resources (except the timer internal itself)
|
||||||
* by calling:<br>
|
* by calling:<br>
|
||||||
* <tt>myHandler.releaseExternalResources();</tt><br>
|
* <tt>myHandler.releaseExternalResources();</tt><br>
|
||||||
* </li>
|
* </li>
|
||||||
@ -60,96 +59,53 @@ import io.netty.handler.execution.ObjectSizeEstimator;
|
|||||||
*/
|
*/
|
||||||
public class ChannelTrafficShapingHandler extends AbstractTrafficShapingHandler {
|
public class ChannelTrafficShapingHandler extends AbstractTrafficShapingHandler {
|
||||||
|
|
||||||
/**
|
public ChannelTrafficShapingHandler(Timer timer, long writeLimit,
|
||||||
* @param executor
|
|
||||||
* @param writeLimit
|
|
||||||
* @param readLimit
|
|
||||||
* @param checkInterval
|
|
||||||
*/
|
|
||||||
public ChannelTrafficShapingHandler(Executor executor, long writeLimit,
|
|
||||||
long readLimit, long checkInterval) {
|
long readLimit, long checkInterval) {
|
||||||
super(executor, writeLimit, readLimit, checkInterval);
|
super(timer, writeLimit, readLimit, checkInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ChannelTrafficShapingHandler(Timer timer, long writeLimit,
|
||||||
* @param executor
|
|
||||||
* @param writeLimit
|
|
||||||
* @param readLimit
|
|
||||||
*/
|
|
||||||
public ChannelTrafficShapingHandler(Executor executor, long writeLimit,
|
|
||||||
long readLimit) {
|
long readLimit) {
|
||||||
super(executor, writeLimit, readLimit);
|
super(timer, writeLimit, readLimit);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param executor
|
|
||||||
* @param checkInterval
|
|
||||||
*/
|
|
||||||
public ChannelTrafficShapingHandler(Executor executor, long checkInterval) {
|
|
||||||
super(executor, checkInterval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ChannelTrafficShapingHandler(Timer timer, long checkInterval) {
|
||||||
* @param executor
|
super(timer, checkInterval);
|
||||||
*/
|
}
|
||||||
public ChannelTrafficShapingHandler(Executor executor) {
|
|
||||||
super(executor);
|
public ChannelTrafficShapingHandler(Timer timer) {
|
||||||
|
super(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param objectSizeEstimator
|
|
||||||
* @param executor
|
|
||||||
* @param writeLimit
|
|
||||||
* @param readLimit
|
|
||||||
* @param checkInterval
|
|
||||||
*/
|
|
||||||
public ChannelTrafficShapingHandler(
|
public ChannelTrafficShapingHandler(
|
||||||
ObjectSizeEstimator objectSizeEstimator, Executor executor,
|
ObjectSizeEstimator objectSizeEstimator, Timer timer,
|
||||||
long writeLimit, long readLimit, long checkInterval) {
|
long writeLimit, long readLimit, long checkInterval) {
|
||||||
super(objectSizeEstimator, executor, writeLimit, readLimit,
|
super(objectSizeEstimator, timer, writeLimit, readLimit,
|
||||||
checkInterval);
|
checkInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param objectSizeEstimator
|
|
||||||
* @param executor
|
|
||||||
* @param writeLimit
|
|
||||||
* @param readLimit
|
|
||||||
*/
|
|
||||||
public ChannelTrafficShapingHandler(
|
public ChannelTrafficShapingHandler(
|
||||||
ObjectSizeEstimator objectSizeEstimator, Executor executor,
|
ObjectSizeEstimator objectSizeEstimator, Timer timer,
|
||||||
long writeLimit, long readLimit) {
|
long writeLimit, long readLimit) {
|
||||||
super(objectSizeEstimator, executor, writeLimit, readLimit);
|
super(objectSizeEstimator, timer, writeLimit, readLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param objectSizeEstimator
|
|
||||||
* @param executor
|
|
||||||
* @param checkInterval
|
|
||||||
*/
|
|
||||||
public ChannelTrafficShapingHandler(
|
public ChannelTrafficShapingHandler(
|
||||||
ObjectSizeEstimator objectSizeEstimator, Executor executor,
|
ObjectSizeEstimator objectSizeEstimator, Timer timer,
|
||||||
long checkInterval) {
|
long checkInterval) {
|
||||||
super(objectSizeEstimator, executor, checkInterval);
|
super(objectSizeEstimator, timer, checkInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param objectSizeEstimator
|
|
||||||
* @param executor
|
|
||||||
*/
|
|
||||||
public ChannelTrafficShapingHandler(
|
public ChannelTrafficShapingHandler(
|
||||||
ObjectSizeEstimator objectSizeEstimator, Executor executor) {
|
ObjectSizeEstimator objectSizeEstimator, Timer timer) {
|
||||||
super(objectSizeEstimator, executor);
|
super(objectSizeEstimator, timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
|
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (trafficCounter != null) {
|
if (trafficCounter != null) {
|
||||||
trafficCounter.stop();
|
trafficCounter.stop();
|
||||||
trafficCounter = null;
|
|
||||||
}
|
}
|
||||||
super.channelClosed(ctx, e);
|
super.channelClosed(ctx, e);
|
||||||
}
|
}
|
||||||
@ -162,8 +118,10 @@ public class ChannelTrafficShapingHandler extends AbstractTrafficShapingHandler
|
|||||||
ctx.getChannel().setReadable(false);
|
ctx.getChannel().setReadable(false);
|
||||||
if (trafficCounter == null) {
|
if (trafficCounter == null) {
|
||||||
// create a new counter now
|
// create a new counter now
|
||||||
trafficCounter = new TrafficCounter(this, executor, "ChannelTC" +
|
if (timer != null) {
|
||||||
ctx.getChannel().getId(), checkInterval);
|
trafficCounter = new TrafficCounter(this, timer, "ChannelTC" +
|
||||||
|
ctx.getChannel().getId(), checkInterval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (trafficCounter != null) {
|
if (trafficCounter != null) {
|
||||||
trafficCounter.start();
|
trafficCounter.start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user