* Static variables should come before member fields
* Removed unused members
This commit is contained in:
Trustin Lee 2011-11-22 16:32:01 +09:00
parent 5c2c8d9d1d
commit 1ac6c75d39
2 changed files with 25 additions and 24 deletions

View File

@ -85,36 +85,40 @@ import org.jboss.netty.util.internal.ExecutorUtil;
*/ */
public class NioClientSocketChannelFactory implements ClientSocketChannelFactory { public class NioClientSocketChannelFactory implements ClientSocketChannelFactory {
private static final int DEFAULT_BOSS_COUNT = 1;
private final Executor bossExecutor; private final Executor bossExecutor;
private final Executor workerExecutor; private final Executor workerExecutor;
private final NioClientSocketPipelineSink sink; private final NioClientSocketPipelineSink sink;
private static final int DEFAULT_BOSS_COUNT = 1;
/** /**
* Creates a new instance. Calling this constructor is same with calling * Creates a new instance. Calling this constructor is same with calling
* {@link #NioClientSocketChannelFactory(Executor, Executor, int)} with 2 * * {@link #NioClientSocketChannelFactory(Executor, Executor, int, int)} with
* the number of available processors in the machine. The number of * 1 and (2 * the number of available processors in the machine) for
* <tt>bossCount</tt> and <tt>workerCount</tt> respectively. The number of
* available processors is obtained by {@link Runtime#availableProcessors()}. * available processors is obtained by {@link Runtime#availableProcessors()}.
* *
* @param bossExecutor * @param bossExecutor
* the {@link Executor} which will execute the boss thread * the {@link Executor} which will execute the boss thread
* @param workerExecutor * @param workerExecutor
* the {@link Executor} which will execute the I/O worker threads * the {@link Executor} which will execute the worker threads
*/ */
public NioClientSocketChannelFactory( public NioClientSocketChannelFactory(
Executor bossExecutor, Executor workerExecutor) { Executor bossExecutor, Executor workerExecutor) {
this(bossExecutor, workerExecutor, SelectorUtil.DEFAULT_IO_THREADS); this(bossExecutor, workerExecutor, DEFAULT_BOSS_COUNT, SelectorUtil.DEFAULT_IO_THREADS);
} }
/** /**
* Creates a new instance. * Creates a new instance. Calling this constructor is same with calling
* {@link #NioClientSocketChannelFactory(Executor, Executor, int, int)} with
* 1 as <tt>bossCount</tt>.
* *
* @param bossExecutor * @param bossExecutor
* the {@link Executor} which will execute the boss thread * the {@link Executor} which will execute the boss thread
* @param workerExecutor * @param workerExecutor
* the {@link Executor} which will execute the I/O worker threads * the {@link Executor} which will execute the worker threads
* @param workerCount * @param workerCount
* the maximum number of I/O worker threads * the maximum number of worker threads
*/ */
public NioClientSocketChannelFactory( public NioClientSocketChannelFactory(
Executor bossExecutor, Executor workerExecutor, Executor bossExecutor, Executor workerExecutor,
@ -132,7 +136,7 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
* @param bossCount * @param bossCount
* the maximum number of boss threads * the maximum number of boss threads
* @param workerCount * @param workerCount
* the maximum number of I/O worker threads * the maximum number of worker threads
*/ */
public NioClientSocketChannelFactory( public NioClientSocketChannelFactory(
Executor bossExecutor, Executor workerExecutor, Executor bossExecutor, Executor workerExecutor,
@ -157,7 +161,8 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
this.bossExecutor = bossExecutor; this.bossExecutor = bossExecutor;
this.workerExecutor = workerExecutor; this.workerExecutor = workerExecutor;
sink = new NioClientSocketPipelineSink(bossExecutor, workerExecutor, bossCount, workerCount); sink = new NioClientSocketPipelineSink(
bossExecutor, workerExecutor, bossCount, workerCount);
} }

View File

@ -58,33 +58,29 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
static final InternalLogger logger = static final InternalLogger logger =
InternalLoggerFactory.getInstance(NioClientSocketPipelineSink.class); InternalLoggerFactory.getInstance(NioClientSocketPipelineSink.class);
private static final int DEFAULT_BOSS_COUNT = 1;
final Executor bossExecutor; final Executor bossExecutor;
private final int numBosses;
private final Boss bosses[]; private final Boss bosses[];
private final NioWorker[] workers; private final NioWorker[] workers;
private final AtomicInteger bossIndex = new AtomicInteger(); private final AtomicInteger bossIndex = new AtomicInteger();
private final AtomicInteger workerIndex = new AtomicInteger(); private final AtomicInteger workerIndex = new AtomicInteger();
NioClientSocketPipelineSink(Executor bossExecutor, Executor workerExecutor, int workerCount) { NioClientSocketPipelineSink(
this(bossExecutor, workerExecutor, DEFAULT_BOSS_COUNT, workerCount); Executor bossExecutor, Executor workerExecutor,
} int bossCount, int workerCount) {
NioClientSocketPipelineSink(Executor bossExecutor, Executor workerExecutor, int bossCount, int workerCount) {
this.bossExecutor = bossExecutor; this.bossExecutor = bossExecutor;
this.numBosses = bossCount;
bosses = new Boss[bossCount];
for (int i = 0; i < bosses.length; i ++) {
bosses[i] = new Boss();
}
workers = new NioWorker[workerCount]; workers = new NioWorker[workerCount];
for (int i = 0; i < workers.length; i ++) { for (int i = 0; i < workers.length; i ++) {
workers[i] = new NioWorker(workerExecutor); workers[i] = new NioWorker(workerExecutor);
} }
bosses = new Boss[numBosses];
for (int i = 0; i < numBosses; ++i) {
bosses[i] = new Boss();
}
} }
@Override @Override