Merged ChannelFactoryModule and ExecutorModule into NettyModule - advanced users can still assemble providers by themselves
This commit is contained in:
parent
6f728177f8
commit
3cf57afd3d
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* 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.container.guice;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.util.ExecutorShutdownUtil;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
/**
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class ExecutorModule extends AbstractModule {
|
||||
|
||||
private final Executor executor;
|
||||
|
||||
public ExecutorModule(Executor executor) {
|
||||
if (executor == null) {
|
||||
throw new NullPointerException("executor");
|
||||
}
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public void terminateExecutor() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Executor.class).
|
||||
annotatedWith(ChannelFactoryResources.getInstance()).
|
||||
toInstance(executor);
|
||||
}
|
||||
}
|
@ -22,12 +22,17 @@
|
||||
*/
|
||||
package org.jboss.netty.container.guice;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
|
||||
import org.jboss.netty.channel.socket.ServerSocketChannelFactory;
|
||||
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 com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
@ -37,10 +42,25 @@ import com.google.inject.Scopes;
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class ChannelFactoryModule extends AbstractModule {
|
||||
public class NettyModule extends AbstractModule {
|
||||
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public void destroy() {
|
||||
ExecutorShutdownUtil.shutdown(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
if (executor.isShutdown()) {
|
||||
throw new IllegalStateException(
|
||||
"Executor has been shut down already.");
|
||||
}
|
||||
|
||||
bind(Executor.class).
|
||||
annotatedWith(ChannelFactoryResources.getInstance()).
|
||||
toInstance(executor);
|
||||
|
||||
bind(ClientSocketChannelFactory.class).
|
||||
toProvider(NioClientSocketChannelFactoryProvider.class).
|
||||
in(Scopes.SINGLETON);
|
Loading…
Reference in New Issue
Block a user