Change Executor to Timer from Netty, in reference to Issue #345

This commit is contained in:
Frédéric Brégier 2012-05-20 11:25:28 +03:00
parent f3a7029c0f
commit 9ba9107267

View File

@ -15,13 +15,12 @@
*/
package org.jboss.netty.handler.traffic;
import java.util.concurrent.Executor;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.handler.execution.ExecutionHandler;
import org.jboss.netty.handler.execution.MemoryAwareThreadPoolExecutor;
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
import org.jboss.netty.util.ObjectSizeEstimator;
import org.jboss.netty.util.Timer;
/**
* This implementation of the {@link AbstractTrafficShapingHandler} is for global
@ -31,8 +30,8 @@ import org.jboss.netty.util.ObjectSizeEstimator;
* The general use should be as follow:<br>
* <ul>
* <li>Create your unique GlobalTrafficShapingHandler like:<br><br>
* <tt>GlobalTrafficShapingHandler myHandler = new GlobalTrafficShapingHandler(executor);</tt><br><br>
* executor could be created using <tt>Executors.newCachedThreadPool();</tt><br>
* <tt>GlobalTrafficShapingHandler myHandler = new GlobalTrafficShapingHandler(timer);</tt><br><br>
* timer could be created using <tt>HashedWheelTimer<tt><br>
* <tt>pipeline.addLast("GLOBAL_TRAFFIC_SHAPING", myHandler);</tt><br><br>
*
* <b>Note that this handler has a Pipeline Coverage of "all" which means only one such handler must be created
@ -52,7 +51,7 @@ import org.jboss.netty.util.ObjectSizeEstimator;
* {@link OrderedMemoryAwareThreadPoolExecutor} or {@link MemoryAwareThreadPoolExecutor}).<br>
* <tt>pipeline.addLast("GLOBAL_TRAFFIC_SHAPING", myHandler);</tt><br><br>
* </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>
* <tt>myHandler.releaseExternalResources();</tt><br>
* </li>
@ -64,96 +63,61 @@ public class GlobalTrafficShapingHandler extends AbstractTrafficShapingHandler {
* Create the global TrafficCounter
*/
void createGlobalTrafficCounter() {
TrafficCounter tc = new TrafficCounter(this, executor, "GlobalTC",
checkInterval);
setTrafficCounter(tc);
tc.start();
TrafficCounter tc;
if (timer != null) {
tc = new TrafficCounter(this, timer, "GlobalTC",
checkInterval);
setTrafficCounter(tc);
tc.start();
}
}
/**
* @param executor
* @param writeLimit
* @param readLimit
* @param checkInterval
*/
public GlobalTrafficShapingHandler(Executor executor, long writeLimit,
public GlobalTrafficShapingHandler(Timer timer, long writeLimit,
long readLimit, long checkInterval) {
super(executor, writeLimit, readLimit, checkInterval);
super(timer, writeLimit, readLimit, checkInterval);
createGlobalTrafficCounter();
}
/**
* @param executor
* @param writeLimit
* @param readLimit
*/
public GlobalTrafficShapingHandler(Executor executor, long writeLimit,
public GlobalTrafficShapingHandler(Timer timer, long writeLimit,
long readLimit) {
super(executor, writeLimit, readLimit);
createGlobalTrafficCounter();
}
/**
* @param executor
* @param checkInterval
*/
public GlobalTrafficShapingHandler(Executor executor, long checkInterval) {
super(executor, checkInterval);
super(timer, writeLimit, readLimit);
createGlobalTrafficCounter();
}
/**
* @param executor
*/
public GlobalTrafficShapingHandler(Executor executor) {
super(executor);
public GlobalTrafficShapingHandler(Timer timer, long checkInterval) {
super(timer, checkInterval);
createGlobalTrafficCounter();
}
public GlobalTrafficShapingHandler(Timer timer) {
super(timer);
createGlobalTrafficCounter();
}
/**
* @param objectSizeEstimator
* @param executor
* @param writeLimit
* @param readLimit
* @param checkInterval
*/
public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Executor executor, long writeLimit, long readLimit,
Timer timer, long writeLimit, long readLimit,
long checkInterval) {
super(objectSizeEstimator, executor, writeLimit, readLimit,
super(objectSizeEstimator, timer, writeLimit, readLimit,
checkInterval);
createGlobalTrafficCounter();
}
/**
* @param objectSizeEstimator
* @param executor
* @param writeLimit
* @param readLimit
*/
public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Executor executor, long writeLimit, long readLimit) {
super(objectSizeEstimator, executor, writeLimit, readLimit);
Timer timer, long writeLimit, long readLimit) {
super(objectSizeEstimator, timer, writeLimit, readLimit);
createGlobalTrafficCounter();
}
/**
* @param objectSizeEstimator
* @param executor
* @param checkInterval
*/
public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Executor executor, long checkInterval) {
super(objectSizeEstimator, executor, checkInterval);
Timer timer, long checkInterval) {
super(objectSizeEstimator, timer, checkInterval);
createGlobalTrafficCounter();
}
/**
* @param objectSizeEstimator
* @param executor
*/
public GlobalTrafficShapingHandler(ObjectSizeEstimator objectSizeEstimator,
Executor executor) {
super(objectSizeEstimator, executor);
Timer timer) {
super(objectSizeEstimator, timer);
createGlobalTrafficCounter();
}
}