Allow specifying 0 as the default number of threads when instantiating an EventLoopGroup

- Fixes #1426
- We already allow a user instantiate an EventLoopGroup with the default number of threads via the default constructor, so I think it's OK although it's not always optimal.
This commit is contained in:
Trustin Lee 2013-06-27 10:39:39 +09:00
parent 1c57e3830c
commit 734ec51ac9
7 changed files with 18 additions and 18 deletions

View File

@ -18,8 +18,8 @@ package io.netty.channel;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.DefaultAttributeMap; import io.netty.util.DefaultAttributeMap;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -715,7 +715,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
if (promise.isCancelled()) { if (promise.isCancelled()) {
// If cancelled, release all unwritten messages and recycle. // If cancelled, release all unwritten messages and recycle.
for (int i = messageIndex; i < messageCount; i ++) { for (int i = messageIndex; i < messageCount; i ++) {
ByteBufUtil.release(messages.get(i)); ReferenceCountUtil.release(messages.get(i));
} }
messages.recycle(); messages.recycle();
if (!outboundBuffer.next()) { if (!outboundBuffer.next()) {

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBufUtil; import io.netty.util.ReferenceCountUtil;
import java.net.SocketAddress; import java.net.SocketAddress;
@ -81,7 +81,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
reject(promise); reject(promise);
int size = msgs.size(); int size = msgs.size();
for (int i = 0; i < size; i ++) { for (int i = 0; i < size; i ++) {
ByteBufUtil.release(msgs.get(i)); ReferenceCountUtil.release(msgs.get(i));
} }
} }

View File

@ -19,7 +19,7 @@
*/ */
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBufUtil; import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -228,7 +228,7 @@ final class ChannelOutboundBuffer {
try { try {
for (int i = currentMessageIndex; i < currentMessages.size(); i++) { for (int i = currentMessageIndex; i < currentMessages.size(); i++) {
Object msg = currentMessages.get(i); Object msg = currentMessages.get(i);
ByteBufUtil.release(msg); ReferenceCountUtil.release(msg);
} }
} finally { } finally {
currentMessages.recycle(); currentMessages.recycle();

View File

@ -15,8 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel.Unsafe; import io.netty.channel.Channel.Unsafe;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.EventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
@ -970,7 +970,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
"Discarded inbound message {} that reached at the tail of the pipeline. " + "Discarded inbound message {} that reached at the tail of the pipeline. " +
"Please check your pipeline configuration.", m); "Please check your pipeline configuration.", m);
ByteBufUtil.release(m); ReferenceCountUtil.release(m);
} }
if (length != 1) { if (length != 1) {

View File

@ -31,7 +31,7 @@ public abstract class MultithreadEventLoopGroup extends MultithreadEventExecutor
private static final InternalLogger logger = InternalLoggerFactory.getInstance(MultithreadEventLoopGroup.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(MultithreadEventLoopGroup.class);
public static final int DEFAULT_EVENT_LOOP_THREADS; private static final int DEFAULT_EVENT_LOOP_THREADS;
static { static {
DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt( DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt(
@ -43,7 +43,7 @@ public abstract class MultithreadEventLoopGroup extends MultithreadEventExecutor
} }
protected MultithreadEventLoopGroup(int nThreads, ThreadFactory threadFactory, Object... args) { protected MultithreadEventLoopGroup(int nThreads, ThreadFactory threadFactory, Object... args) {
super(nThreads, threadFactory, args); super(nThreads == 0? DEFAULT_EVENT_LOOP_THREADS : nThreads, threadFactory, args);
} }
@Override @Override

View File

@ -26,10 +26,10 @@ import java.util.concurrent.ThreadFactory;
public class LocalEventLoopGroup extends MultithreadEventLoopGroup { public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
/** /**
* Create a new instance which used {@link #DEFAULT_EVENT_LOOP_THREADS} number of Threads * Create a new instance with the default number of threads.
*/ */
public LocalEventLoopGroup() { public LocalEventLoopGroup() {
this(DEFAULT_EVENT_LOOP_THREADS); this(0);
} }
/** /**

View File

@ -29,15 +29,15 @@ import java.util.concurrent.ThreadFactory;
public class NioEventLoopGroup extends MultithreadEventLoopGroup { public class NioEventLoopGroup extends MultithreadEventLoopGroup {
/** /**
* Create a new instance using {@link #DEFAULT_EVENT_LOOP_THREADS} number of threads, the default * Create a new instance using the default number of threads, the default {@link ThreadFactory} and
* {@link ThreadFactory} and the {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}. * the {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
*/ */
public NioEventLoopGroup() { public NioEventLoopGroup() {
this(DEFAULT_EVENT_LOOP_THREADS); this(0);
} }
/** /**
* Create a new instance using nThreads number of threads, {@link ThreadFactory} and the * Create a new instance using the specified number of threads, {@link ThreadFactory} and the
* {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}. * {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
*/ */
public NioEventLoopGroup(int nThreads) { public NioEventLoopGroup(int nThreads) {
@ -45,7 +45,7 @@ public class NioEventLoopGroup extends MultithreadEventLoopGroup {
} }
/** /**
* Create a new instance using nThreads number of threads, the given {@link ThreadFactory} and the * Create a new instance using the specified number of threads, the given {@link ThreadFactory} and the
* {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}. * {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
*/ */
public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory) { public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
@ -53,7 +53,7 @@ public class NioEventLoopGroup extends MultithreadEventLoopGroup {
} }
/** /**
* Create a new instance using nThreads number of threads, the given {@link ThreadFactory} and the given * Create a new instance using the specified number of threads, the given {@link ThreadFactory} and the given
* {@link SelectorProvider}. * {@link SelectorProvider}.
*/ */
public NioEventLoopGroup( public NioEventLoopGroup(