* Removed an unnecessary log statement in the OSGi BundleActivator impl
* Added UnterminatableExecutor * Prohibited an attempt to release the shared resources when initialized via containers
This commit is contained in:
parent
04af4356ef
commit
587d623789
@ -33,6 +33,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
|||||||
import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory;
|
import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory;
|
||||||
import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory;
|
import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory;
|
||||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||||
|
import org.jboss.netty.util.UnterminatableExecutor;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
@ -57,6 +58,8 @@ public class NettyModule extends AbstractModule {
|
|||||||
"Executor has been shut down already.");
|
"Executor has been shut down already.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Executor executor = new UnterminatableExecutor(this.executor);
|
||||||
|
|
||||||
bind(Executor.class).
|
bind(Executor.class).
|
||||||
annotatedWith(ChannelFactoryResource.class).
|
annotatedWith(ChannelFactoryResource.class).
|
||||||
toInstance(executor);
|
toInstance(executor);
|
||||||
|
@ -28,6 +28,7 @@ import java.util.concurrent.Executors;
|
|||||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||||
import org.jboss.netty.logging.JBossLoggerFactory;
|
import org.jboss.netty.logging.JBossLoggerFactory;
|
||||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||||
|
import org.jboss.netty.util.UnterminatableExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||||
@ -35,27 +36,30 @@ import org.jboss.netty.util.ExecutorShutdownUtil;
|
|||||||
* @version $Rev$, $Date$
|
* @version $Rev$, $Date$
|
||||||
*/
|
*/
|
||||||
public class NettyResourceFactory {
|
public class NettyResourceFactory {
|
||||||
private volatile Executor channelFactoryExecutor;
|
private Executor executor;
|
||||||
|
private Executor unterminatableExecutor;
|
||||||
|
|
||||||
public void create() {
|
public synchronized void create() {
|
||||||
channelFactoryExecutor = Executors.newCachedThreadPool();
|
executor = Executors.newCachedThreadPool();
|
||||||
|
unterminatableExecutor = new UnterminatableExecutor(executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
InternalLoggerFactory.setDefaultFactory(new JBossLoggerFactory());
|
InternalLoggerFactory.setDefaultFactory(new JBossLoggerFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public synchronized void stop() {
|
||||||
if (channelFactoryExecutor != null) {
|
if (executor != null) {
|
||||||
ExecutorShutdownUtil.shutdown(channelFactoryExecutor);
|
ExecutorShutdownUtil.shutdown(executor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public synchronized void destroy() {
|
||||||
channelFactoryExecutor = null;
|
executor = null;
|
||||||
|
unterminatableExecutor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Executor getChannelFactoryExecutor() {
|
public Executor getChannelFactoryExecutor() {
|
||||||
return channelFactoryExecutor;
|
return unterminatableExecutor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,8 @@ public class NettyBundleActivator implements BundleActivator {
|
|||||||
|
|
||||||
public void start(BundleContext ctx) throws Exception {
|
public void start(BundleContext ctx) throws Exception {
|
||||||
initLoggerFactory(ctx);
|
initLoggerFactory(ctx);
|
||||||
InternalLoggerFactory.getInstance(NettyBundleActivator.class).info("YAY");
|
|
||||||
|
|
||||||
executor = Executors.newCachedThreadPool();
|
Executor executor = this.executor = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
// The default transport is NIO.
|
// The default transport is NIO.
|
||||||
register(ctx,
|
register(ctx,
|
||||||
@ -77,8 +76,10 @@ public class NettyBundleActivator implements BundleActivator {
|
|||||||
|
|
||||||
public void stop(BundleContext ctx) throws Exception {
|
public void stop(BundleContext ctx) throws Exception {
|
||||||
unregisterAll();
|
unregisterAll();
|
||||||
ExecutorShutdownUtil.shutdown(executor);
|
if (executor != null) {
|
||||||
executor = null;
|
ExecutorShutdownUtil.shutdown(executor);
|
||||||
|
executor = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLoggerFactory(BundleContext ctx) {
|
private void initLoggerFactory(BundleContext ctx) {
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
*
|
||||||
|
* Copyright 2009, 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;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables shutdown of an {@link Executor} by wrapping the {@link Executor}.
|
||||||
|
*
|
||||||
|
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||||
|
* @author Trustin Lee (tlee@redhat.com)
|
||||||
|
* @version $Rev$, $Date$
|
||||||
|
*/
|
||||||
|
public class UnterminatableExecutor implements Executor {
|
||||||
|
|
||||||
|
private final Executor executor;
|
||||||
|
|
||||||
|
public UnterminatableExecutor(Executor executor) {
|
||||||
|
if (executor == null) {
|
||||||
|
throw new NullPointerException("executor");
|
||||||
|
}
|
||||||
|
this.executor = executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(Runnable command) {
|
||||||
|
executor.execute(command);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user