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
|
|
|
|
2012-04-29 18:40:55 +09:00
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
|
2012-12-18 07:23:42 +01:00
|
|
|
/**
|
|
|
|
* Abstract base class for {@link EventLoopGroup} implementations that handles their tasks with multiple threads at
|
|
|
|
* 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()) {
|
|
|
|
logger.debug("io.netty.eventLoopThreads: {}", DEFAULT_EVENT_LOOP_THREADS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-03 17:15:25 +09:00
|
|
|
protected MultithreadEventLoopGroup(int nThreads, ThreadFactory threadFactory, Object... args) {
|
2013-06-27 10:39:39 +09: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();
|
|
|
|
}
|
|
|
|
|
2012-04-29 18:40:55 +09:00
|
|
|
@Override
|
|
|
|
public ChannelFuture register(Channel channel) {
|
2012-08-10 20:17:18 +09:00
|
|
|
return next().register(channel);
|
2012-04-29 18:40:55 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-12-30 17:40:24 +01:00
|
|
|
public ChannelFuture register(Channel channel, ChannelPromise promise) {
|
|
|
|
return next().register(channel, promise);
|
2012-04-29 18:40:55 +09:00
|
|
|
}
|
|
|
|
}
|