Add special subclasses of MemoryAwareThreadPoolExecutor and
OrderedMemoryAwareThreadPoolExecutor which should be used for SEDA processing. See #111
This commit is contained in:
parent
7397bba454
commit
b9e869545c
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.handler.execution.seda;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import io.netty.handler.execution.MemoryAwareThreadPoolExecutor;
|
||||||
|
import io.netty.util.ObjectSizeEstimator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass of {@link MemoryAwareThreadPoolExecutor} which has all the same semantics as {@link MemoryAwareThreadPoolExecutor}. The only difference is that it will not keep track of the memory usage
|
||||||
|
* of downstream events.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* For more details see {@link MemoryAwareThreadPoolExecutor}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SedaMemoryAwareThreadPoolExecutor extends MemoryAwareThreadPoolExecutor{
|
||||||
|
|
||||||
|
public SedaMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize, long keepAliveTime, TimeUnit unit, ObjectSizeEstimator objectSizeEstimator, ThreadFactory threadFactory) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit, objectSizeEstimator, threadFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SedaMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize, long keepAliveTime, TimeUnit unit, ThreadFactory threadFactory) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit, threadFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SedaMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize, long keepAliveTime, TimeUnit unit) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SedaMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't count if {@link Runnable} is an instance of {@link ChannelDownstreamEventRunnable}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean shouldCount(Runnable task) {
|
||||||
|
if (!(task instanceof ChannelDownstreamEventRunnable)) {
|
||||||
|
return super.shouldCount(task);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 The Netty Project
|
||||||
|
*
|
||||||
|
* The Netty Project licenses this file to you under the Apache License,
|
||||||
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at:
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.handler.execution.seda;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
||||||
|
import io.netty.util.ObjectSizeEstimator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass of {@link OrderedMemoryAwareThreadPoolExecutor} which has all the same semantics as {@link OrderedMemoryAwareThreadPoolExecutor}. The only difference is that it will not keep track of the memory usage
|
||||||
|
* of downstream events .
|
||||||
|
*
|
||||||
|
* For more details see {@link OrderedMemoryAwareThreadPoolExecutor}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SedaOrderedMemoryAwareThreadPoolExecutor extends OrderedMemoryAwareThreadPoolExecutor{
|
||||||
|
|
||||||
|
public SedaOrderedMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize, long keepAliveTime, TimeUnit unit, ObjectSizeEstimator objectSizeEstimator, ThreadFactory threadFactory) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit, objectSizeEstimator, threadFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SedaOrderedMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize, long keepAliveTime, TimeUnit unit, ThreadFactory threadFactory) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit, threadFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SedaOrderedMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize, long keepAliveTime, TimeUnit unit) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SedaOrderedMemoryAwareThreadPoolExecutor(int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize) {
|
||||||
|
super(corePoolSize, maxChannelMemorySize, maxTotalMemorySize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't count if {@link Runnable} is an instance of {@link ChannelDownstreamEventRunnable}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean shouldCount(Runnable task) {
|
||||||
|
if (!(task instanceof ChannelDownstreamEventRunnable)) {
|
||||||
|
return super.shouldCount(task);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -18,13 +18,13 @@ package io.netty.handler.execution.seda;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import io.netty.handler.execution.ChannelEventRunnable;
|
import io.netty.handler.execution.ChannelEventRunnable;
|
||||||
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
|
||||||
import io.netty.util.internal.ExecutorUtil;
|
import io.netty.util.internal.ExecutorUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link SedaExecutor} which use two different {@link Executor}'s. One is used for upstream events and one for downstream events.
|
* {@link SedaExecutor} which use two different {@link Executor}'s. One is used for upstream events and one for downstream events.
|
||||||
*
|
*
|
||||||
* You should use an {@link OrderedMemoryAwareThreadPoolExecutor} if you care about the order of thread-execution. In most cases this should be the case
|
* You should use an {@link SedaOrderedMemoryAwareThreadPoolExecutor} if you care about the order of thread-execution. In most cases this should be the case
|
||||||
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user