2012-06-04 13:31:44 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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.
|
|
|
|
*/
|
2012-04-29 18:40:55 +09:00
|
|
|
package io.netty.channel;
|
|
|
|
|
2013-04-03 17:49:30 +09:00
|
|
|
import io.netty.util.concurrent.DefaultThreadFactory;
|
2013-03-05 21:41:19 +01:00
|
|
|
import io.netty.util.concurrent.MultithreadEventExecutorGroup;
|
2013-04-03 17:49:30 +09:00
|
|
|
import io.netty.util.internal.SystemPropertyUtil;
|
|
|
|
import io.netty.util.internal.logging.InternalLogger;
|
|
|
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
2013-03-05 21:41:19 +01:00
|
|
|
|
2013-08-20 18:42:56 +02:00
|
|
|
import java.util.concurrent.Executor;
|
2012-04-29 18:40:55 +09:00
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
|
2012-12-18 07:23:42 +01:00
|
|
|
/**
|
2014-04-24 21:12:51 +09:00
|
|
|
* Abstract base class for {@link EventLoopGroup} implementations that handles their tasks with multiple threads at
|
2012-12-18 07:23:42 +01:00
|
|
|
* the same time.
|
|
|
|
*/
|
2012-08-10 20:17:18 +09:00
|
|
|
public abstract class MultithreadEventLoopGroup extends MultithreadEventExecutorGroup implements EventLoopGroup {
|
2012-04-29 18:40:55 +09:00
|
|
|
|
2013-04-03 17:49:30 +09:00
|
|
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(MultithreadEventLoopGroup.class);
|
|
|
|
|
2013-06-27 10:39:39 +09:00
|
|
|
private static final int DEFAULT_EVENT_LOOP_THREADS;
|
2013-04-03 17:49:30 +09:00
|
|
|
|
|
|
|
static {
|
|
|
|
DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt(
|
|
|
|
"io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
|
|
|
|
|
|
|
|
if (logger.isDebugEnabled()) {
|
2013-07-02 09:23:29 +09:00
|
|
|
logger.debug("-Dio.netty.eventLoopThreads: {}", DEFAULT_EVENT_LOOP_THREADS);
|
2013-04-03 17:49:30 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-20 18:42:56 +02:00
|
|
|
/**
|
|
|
|
* @see {@link MultithreadEventExecutorGroup#MultithreadEventExecutorGroup(int, Executor, Object...)}
|
|
|
|
*/
|
|
|
|
protected MultithreadEventLoopGroup(int nThreads, Executor executor, Object... args) {
|
|
|
|
super(nThreads == 0 ? DEFAULT_EVENT_LOOP_THREADS : nThreads, executor, args);
|
|
|
|
}
|
|
|
|
|
2013-07-14 18:04:33 +02:00
|
|
|
/**
|
|
|
|
* @see {@link MultithreadEventExecutorGroup#MultithreadEventExecutorGroup(int, ThreadFactory, Object...)}
|
|
|
|
*/
|
2013-04-03 17:15:25 +09:00
|
|
|
protected MultithreadEventLoopGroup(int nThreads, ThreadFactory threadFactory, Object... args) {
|
2013-08-20 18:42:56 +02:00
|
|
|
super(nThreads == 0 ? DEFAULT_EVENT_LOOP_THREADS : nThreads, threadFactory, args);
|
2012-04-29 18:40:55 +09:00
|
|
|
}
|
|
|
|
|
2013-04-03 17:49:30 +09:00
|
|
|
@Override
|
|
|
|
protected ThreadFactory newDefaultThreadFactory() {
|
|
|
|
return new DefaultThreadFactory(getClass(), Thread.MAX_PRIORITY);
|
|
|
|
}
|
|
|
|
|
2012-08-10 20:17:18 +09:00
|
|
|
@Override
|
|
|
|
public EventLoop next() {
|
|
|
|
return (EventLoop) super.next();
|
|
|
|
}
|
2013-11-06 21:14:07 +09:00
|
|
|
|
2014-04-25 13:44:04 +09:00
|
|
|
@Override
|
|
|
|
protected abstract EventLoop newChild(Executor executor, Object... args) throws Exception;
|
|
|
|
|
2013-11-06 21:14:07 +09:00
|
|
|
@Override
|
2014-04-22 14:38:10 +02:00
|
|
|
public ChannelFuture register(Channel channel) {
|
|
|
|
return next().register(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture register(Channel channel, ChannelPromise promise) {
|
|
|
|
return next().register(channel, promise);
|
|
|
|
}
|
2012-04-29 18:40:55 +09:00
|
|
|
}
|