Don't close the Selector if no keys are registered. See #471
This commit is contained in:
parent
2c318d397b
commit
5189bb1f3f
|
@ -128,6 +128,11 @@ abstract class AbstractNioWorker implements Worker {
|
|||
this(executor, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated Use {@link #AbstractNioWorker(Executor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public AbstractNioWorker(Executor executor, boolean allowShutdownOnIdle) {
|
||||
this.executor = executor;
|
||||
this.allowShutdownOnIdle = allowShutdownOnIdle;
|
||||
|
|
|
@ -34,6 +34,7 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker>
|
|||
private final AbstractNioWorker[] workers;
|
||||
private final AtomicInteger workerIndex = new AtomicInteger();
|
||||
private final Executor workerExecutor;
|
||||
private final boolean allowShutDownOnIdle;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
|
@ -42,6 +43,7 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker>
|
|||
* @param allowShutdownOnIdle allow the {@link Worker}'s to shutdown when there is not
|
||||
* {@link Channel} is registered with it
|
||||
* @param workerCount the count of {@link Worker}'s to create
|
||||
* @deprecated use {@link #AbstractNioWorkerPool(Executor, int)}
|
||||
*/
|
||||
AbstractNioWorkerPool(Executor workerExecutor, int workerCount, boolean allowShutDownOnIdle) {
|
||||
if (workerExecutor == null) {
|
||||
|
@ -55,12 +57,23 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker>
|
|||
workers = new AbstractNioWorker[workerCount];
|
||||
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i] = createWorker(workerExecutor, allowShutDownOnIdle);
|
||||
workers[i] = createWorker(workerExecutor);
|
||||
}
|
||||
this.allowShutDownOnIdle = allowShutDownOnIdle;
|
||||
this.workerExecutor = workerExecutor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
* @param workerExecutor the {@link Executor} to use for the {@link Worker}'s
|
||||
* @param workerCount the count of {@link Worker}'s to create
|
||||
*/
|
||||
AbstractNioWorkerPool(Executor workerExecutor, int workerCount) {
|
||||
this(workerExecutor, workerCount, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link Worker} which uses the given {@link Executor} to service IO
|
||||
*
|
||||
|
@ -69,9 +82,22 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker>
|
|||
* @param allowShutdownOnIdle allow the {@link Worker} to shutdown when there is not
|
||||
* {@link Channel} is registered with it
|
||||
* @return worker the new {@link Worker}
|
||||
* @deprecated use {@link #createWorker(Executor)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected abstract E createWorker(Executor executor, boolean allowShutdownOnIdle);
|
||||
|
||||
/**
|
||||
* Create a new {@link Worker} which uses the given {@link Executor} to service IO
|
||||
*
|
||||
*
|
||||
* @param executor the {@link Executor} to use
|
||||
* @return worker the new {@link Worker}
|
||||
*/
|
||||
protected E createWorker(Executor executor) {
|
||||
return createWorker(executor, allowShutDownOnIdle);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public E nextWorker() {
|
||||
return (E) workers[Math.abs(workerIndex.getAndIncrement() % workers.length)];
|
||||
|
|
|
@ -146,7 +146,7 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
|
|||
public NioClientSocketChannelFactory(
|
||||
Executor bossExecutor, Executor workerExecutor,
|
||||
int bossCount, int workerCount) {
|
||||
this(bossExecutor, bossCount, new NioWorkerPool(workerExecutor, workerCount, true));
|
||||
this(bossExecutor, bossCount, new NioWorkerPool(workerExecutor, workerCount));
|
||||
}
|
||||
|
||||
public NioClientSocketChannelFactory(
|
||||
|
|
|
@ -133,7 +133,7 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
|||
* the maximum number of I/O worker threads
|
||||
*/
|
||||
public NioDatagramChannelFactory(final Executor workerExecutor, final int workerCount) {
|
||||
this(new NioDatagramWorkerPool(workerExecutor, workerCount, true));
|
||||
this(new NioDatagramWorkerPool(workerExecutor, workerCount));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,7 +180,7 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
|||
*/
|
||||
public NioDatagramChannelFactory(final Executor workerExecutor,
|
||||
final int workerCount, InternetProtocolFamily family) {
|
||||
this(new NioDatagramWorkerPool(workerExecutor, workerCount, true), family);
|
||||
this(new NioDatagramWorkerPool(workerExecutor, workerCount), family);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,6 +51,11 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
|||
super(executor);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated use {@link #NioDatagramWorker(Executor)}
|
||||
*/
|
||||
@Deprecated
|
||||
NioDatagramWorker(final Executor executor, boolean allowShutdownOnIdle) {
|
||||
super(executor, allowShutdownOnIdle);
|
||||
}
|
||||
|
|
|
@ -25,10 +25,18 @@ import java.util.concurrent.Executor;
|
|||
*/
|
||||
public class NioDatagramWorkerPool extends AbstractNioWorkerPool<NioDatagramWorker> {
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #NioDatagramWorkerPool(Executor, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public NioDatagramWorkerPool(Executor executor, int workerCount, boolean allowShutdownOnIdle) {
|
||||
super(executor, workerCount, allowShutdownOnIdle);
|
||||
}
|
||||
|
||||
public NioDatagramWorkerPool(Executor executor, int workerCount) {
|
||||
super(executor, workerCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NioDatagramWorker createWorker(Executor executor, boolean allowShutdownOnIdle) {
|
||||
return new NioDatagramWorker(executor, allowShutdownOnIdle);
|
||||
|
|
|
@ -128,7 +128,7 @@ public class NioServerSocketChannelFactory implements ServerSocketChannelFactory
|
|||
public NioServerSocketChannelFactory(
|
||||
Executor bossExecutor, Executor workerExecutor,
|
||||
int workerCount) {
|
||||
this(bossExecutor, new NioWorkerPool(workerExecutor, workerCount, true));
|
||||
this(bossExecutor, new NioWorkerPool(workerExecutor, workerCount));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,6 +92,8 @@ class NioServerSocketPipelineSink extends AbstractNioChannelSink {
|
|||
close(channel, future);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ public class NioWorker extends AbstractNioWorker {
|
|||
super(executor);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated use {@link #NioWorker(Executor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public NioWorker(Executor executor, boolean allowShutdownOnIdle) {
|
||||
super(executor, allowShutdownOnIdle);
|
||||
}
|
||||
|
|
|
@ -25,10 +25,18 @@ import java.util.concurrent.Executor;
|
|||
*/
|
||||
public class NioWorkerPool extends AbstractNioWorkerPool<NioWorker> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated use {@link #NioWorkerPool(Executor, int)}
|
||||
*/
|
||||
public NioWorkerPool(Executor executor, int workerCount, boolean allowShutdownOnIdle) {
|
||||
super(executor, workerCount, allowShutdownOnIdle);
|
||||
}
|
||||
|
||||
public NioWorkerPool(Executor workerExecutor, int workerCount) {
|
||||
super(workerExecutor, workerCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NioWorker createWorker(Executor executor, boolean allowShutdownOnIdle) {
|
||||
return new NioWorker(executor, allowShutdownOnIdle);
|
||||
|
|
Loading…
Reference in New Issue
Block a user