* Renamed ExecutorShutdownUtil to ExecutorUtil
* Added ExternalResourceUtil
This commit is contained in:
parent
5a2491576c
commit
c4b1e5a011
@ -31,7 +31,7 @@ import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
|
||||
import org.jboss.netty.channel.socket.SocketChannel;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
|
||||
/**
|
||||
* A {@link ClientSocketChannelFactory} which creates a client-side NIO-based
|
||||
@ -145,6 +145,6 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
}
|
||||
|
||||
public void releaseExternalResources() {
|
||||
ExecutorShutdownUtil.shutdown(bossExecutor, workerExecutor);
|
||||
ExecutorUtil.terminate(bossExecutor, workerExecutor);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelSink;
|
||||
import org.jboss.netty.channel.socket.ServerSocketChannel;
|
||||
import org.jboss.netty.channel.socket.ServerSocketChannelFactory;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
|
||||
/**
|
||||
* A {@link ServerSocketChannelFactory} which creates a server-side NIO-based
|
||||
@ -148,6 +148,6 @@ public class NioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
}
|
||||
|
||||
public void releaseExternalResources() {
|
||||
ExecutorShutdownUtil.shutdown(bossExecutor, workerExecutor);
|
||||
ExecutorUtil.terminate(bossExecutor, workerExecutor);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
|
||||
import org.jboss.netty.channel.socket.SocketChannel;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
|
||||
/**
|
||||
* A {@link ClientSocketChannelFactory} which creates a client-side blocking
|
||||
@ -105,6 +105,6 @@ public class OioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
}
|
||||
|
||||
public void releaseExternalResources() {
|
||||
ExecutorShutdownUtil.shutdown(workerExecutor);
|
||||
ExecutorUtil.terminate(workerExecutor);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelSink;
|
||||
import org.jboss.netty.channel.socket.ServerSocketChannel;
|
||||
import org.jboss.netty.channel.socket.ServerSocketChannelFactory;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
|
||||
/**
|
||||
* A {@link ServerSocketChannelFactory} which creates a server-side blocking
|
||||
@ -130,6 +130,6 @@ public class OioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
}
|
||||
|
||||
public void releaseExternalResources() {
|
||||
ExecutorShutdownUtil.shutdown(bossExecutor, workerExecutor);
|
||||
ExecutorUtil.terminate(bossExecutor, workerExecutor);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory;
|
||||
import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
import org.jboss.netty.util.UnterminatableExecutor;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
@ -48,7 +48,7 @@ public class NettyModule extends AbstractModule {
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,7 +27,7 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.logging.JBossLoggerFactory;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
import org.jboss.netty.util.UnterminatableExecutor;
|
||||
|
||||
/**
|
||||
@ -54,7 +54,7 @@ public class NettyResourceFactory {
|
||||
|
||||
public synchronized void stop() {
|
||||
if (executor != null) {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory;
|
||||
import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.logging.OsgiLoggerFactory;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
@ -78,7 +78,7 @@ public class NettyBundleActivator implements BundleActivator {
|
||||
public void stop(BundleContext ctx) throws Exception {
|
||||
unregisterAll();
|
||||
if (executor != null) {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
executor = null;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import org.jboss.netty.logging.CommonsLoggerFactory;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
import org.jboss.netty.util.UnterminatableExecutor;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@ -53,7 +53,7 @@ public class NettyResourceFactory implements InitializingBean, DisposableBean {
|
||||
|
||||
public synchronized void destroy() {
|
||||
if (executor != null) {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
executor = null;
|
||||
|
@ -29,7 +29,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelPipelineCoverage;
|
||||
import org.jboss.netty.channel.ChannelUpstreamHandler;
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
import org.jboss.netty.util.ExecutorUtil;
|
||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
|
||||
/**
|
||||
@ -88,7 +88,7 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ExternalResourc
|
||||
* and wait for its termination.
|
||||
*/
|
||||
public void releaseExternalResources() {
|
||||
ExecutorShutdownUtil.shutdown(getExecutor());
|
||||
ExecutorUtil.terminate(getExecutor());
|
||||
}
|
||||
|
||||
public void handleUpstream(
|
||||
|
@ -27,7 +27,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Shuts down a list of {@link Executor}s. {@link #shutdown(Executor...)} will
|
||||
* Shuts down a list of {@link Executor}s. {@link #terminate(Executor...)} will
|
||||
* shut down all specified {@link ExecutorService}s immediately and wait for
|
||||
* their termination. An {@link Executor} which is not an {@link ExecutorService}
|
||||
* will be ignored silently.
|
||||
@ -36,12 +36,12 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class ExecutorShutdownUtil {
|
||||
public class ExecutorUtil {
|
||||
|
||||
/**
|
||||
* Shuts down the specified executors.
|
||||
*/
|
||||
public static void shutdown(Executor... executors) {
|
||||
public static void terminate(Executor... executors) {
|
||||
Executor[] executorsCopy = new Executor[executors.length];
|
||||
for (int i = 0; i < executors.length; i ++) {
|
||||
if (executors[i] == null) {
|
||||
@ -74,7 +74,7 @@ public class ExecutorShutdownUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private ExecutorShutdownUtil() {
|
||||
private ExecutorUtil() {
|
||||
super();
|
||||
}
|
||||
}
|
54
src/main/java/org/jboss/netty/util/ExternalResourceUtil.java
Normal file
54
src/main/java/org/jboss/netty/util/ExternalResourceUtil.java
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.util;
|
||||
|
||||
/**
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class ExternalResourceUtil {
|
||||
|
||||
/**
|
||||
* Releases the specified {@link ExternalResourceReleasable}s.
|
||||
*/
|
||||
public static void release(ExternalResourceReleasable... releasables) {
|
||||
ExternalResourceReleasable[] releasablesCopy =
|
||||
new ExternalResourceReleasable[releasables.length];
|
||||
|
||||
for (int i = 0; i < releasables.length; i ++) {
|
||||
if (releasables[i] == null) {
|
||||
throw new NullPointerException("releasables[" + i + "]");
|
||||
}
|
||||
releasablesCopy[i] = releasables[i];
|
||||
}
|
||||
|
||||
for (ExternalResourceReleasable e: releasablesCopy) {
|
||||
e.releaseExternalResources();
|
||||
}
|
||||
}
|
||||
|
||||
private ExternalResourceUtil() {
|
||||
super();
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ 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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -62,7 +62,7 @@ public abstract class AbstractSocketClientBootstrapTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor);
|
||||
|
@ -44,7 +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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -68,7 +68,7 @@ public abstract class AbstractSocketServerBootstrapTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
|
||||
|
@ -46,7 +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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -77,7 +77,7 @@ public abstract class AbstractSocketEchoTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
|
||||
|
@ -46,7 +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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -77,7 +77,7 @@ public abstract class AbstractSocketFixedLengthEchoTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
|
||||
|
@ -44,7 +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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -83,7 +83,7 @@ public abstract class AbstractSocketCompatibleObjectStreamEchoTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
|
||||
|
@ -44,7 +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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -83,7 +83,7 @@ public abstract class AbstractSocketObjectStreamEchoTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
|
||||
|
@ -46,7 +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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -85,7 +85,7 @@ public abstract class AbstractSocketStringEchoTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
ExecutorUtil.terminate(executor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
|
||||
|
@ -53,7 +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.jboss.netty.util.ExecutorUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -88,7 +88,7 @@ public abstract class AbstractSocketSslEchoTest {
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor, eventExecutor);
|
||||
ExecutorUtil.terminate(executor, eventExecutor);
|
||||
}
|
||||
|
||||
protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);
|
||||
|
Loading…
x
Reference in New Issue
Block a user