* Replaced duplicate executor shutdown code with ExecutorShutdownUtil.shutdown()

* Applied the same workaround which was applied to ExecutorShutdownUtil.shutdown() to NioProviderMetadata
This commit is contained in:
Trustin Lee 2009-01-02 16:57:15 +00:00
parent 4032940e51
commit e9b841757a
9 changed files with 22 additions and 99 deletions

View File

@ -391,7 +391,12 @@ class NioProviderMetadata {
if (loop != null) {
loop.done = true;
executor.shutdownNow();
try {
executor.shutdownNow();
} catch (NullPointerException ex) {
// Some JDK throws NPE here, but shouldn't.
}
try {
for (;;) {
loop.selector.wakeup();

View File

@ -32,13 +32,13 @@ import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelPipelineException;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.util.DummyHandler;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -62,16 +62,7 @@ public abstract class AbstractSocketClientBootstrapTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor);
}
protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor);

View File

@ -32,7 +32,6 @@ import java.net.Socket;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelException;
@ -45,6 +44,7 @@ import org.jboss.netty.channel.ChildChannelStateEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.channel.socket.SocketChannelConfig;
import org.jboss.netty.util.DummyHandler;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -68,16 +68,7 @@ public abstract class AbstractSocketServerBootstrapTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor);
}
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);

View File

@ -31,7 +31,6 @@ import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.jboss.netty.bootstrap.ClientBootstrap;
@ -47,6 +46,7 @@ import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -77,16 +77,7 @@ public abstract class AbstractSocketEchoTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor);
}
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);

View File

@ -31,7 +31,6 @@ import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.jboss.netty.bootstrap.ClientBootstrap;
@ -47,6 +46,7 @@ import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -77,16 +77,7 @@ public abstract class AbstractSocketFixedLengthEchoTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor);
}
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);

View File

@ -31,7 +31,6 @@ import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.jboss.netty.bootstrap.ClientBootstrap;
@ -45,6 +44,7 @@ import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -83,16 +83,7 @@ public abstract class AbstractSocketCompatibleObjectStreamEchoTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor);
}
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);

View File

@ -31,7 +31,6 @@ import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.jboss.netty.bootstrap.ClientBootstrap;
@ -45,6 +44,7 @@ import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -83,16 +83,7 @@ public abstract class AbstractSocketObjectStreamEchoTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor);
}
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);

View File

@ -31,7 +31,6 @@ import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.jboss.netty.bootstrap.ClientBootstrap;
@ -47,6 +46,7 @@ import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
import org.jboss.netty.handler.codec.frame.Delimiters;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -85,16 +85,7 @@ public abstract class AbstractSocketStringEchoTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor);
}
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);

View File

@ -31,7 +31,6 @@ import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLEngine;
@ -54,6 +53,7 @@ import org.jboss.netty.handler.execution.ExecutionHandler;
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.ExecutorShutdownUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -88,26 +88,7 @@ public abstract class AbstractSocketSslEchoTest {
@AfterClass
public static void destroy() {
executor.shutdownNow();
for (;;) {
try {
if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
eventExecutor.shutdownNow();
for (;;) {
try {
if (eventExecutor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
// Ignore.
}
}
ExecutorShutdownUtil.shutdown(executor, eventExecutor);
}
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);