From 1ae76562b7cb8cc6d2093b8373723a4c79fea277 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 31 Mar 2010 03:20:47 +0000 Subject: [PATCH] Simplified container integration by removing unused features --- pom.xml | 17 --- .../netty/container/guice/NettyModule.java | 130 ------------------ ...NioClientSocketChannelFactoryProvider.java | 48 ------- .../NioDatagramChannelFactoryProvider.java | 48 ------- ...NioServerSocketChannelFactoryProvider.java | 48 ------- ...OioClientSocketChannelFactoryProvider.java | 48 ------- .../OioDatagramChannelFactoryProvider.java | 48 ------- ...OioServerSocketChannelFactoryProvider.java | 48 ------- .../netty/container/guice/package-info.java | 22 --- .../NettyLoggerConfigurator.java} | 23 +--- .../microcontainer/NettyResourceFactory.java | 66 --------- .../container/osgi/NettyBundleActivator.java | 83 +---------- .../NettyLoggerConfigurator.java} | 26 ++-- .../spring/NettyResourceFactory.java | 63 --------- src/main/resources/META-INF/jboss-beans.xml | 101 +------------- .../jboss/netty/container/spring/beans.xml | 68 +-------- 16 files changed, 20 insertions(+), 867 deletions(-) delete mode 100644 src/main/java/org/jboss/netty/container/guice/NettyModule.java delete mode 100644 src/main/java/org/jboss/netty/container/guice/NioClientSocketChannelFactoryProvider.java delete mode 100644 src/main/java/org/jboss/netty/container/guice/NioDatagramChannelFactoryProvider.java delete mode 100644 src/main/java/org/jboss/netty/container/guice/NioServerSocketChannelFactoryProvider.java delete mode 100644 src/main/java/org/jboss/netty/container/guice/OioClientSocketChannelFactoryProvider.java delete mode 100644 src/main/java/org/jboss/netty/container/guice/OioDatagramChannelFactoryProvider.java delete mode 100644 src/main/java/org/jboss/netty/container/guice/OioServerSocketChannelFactoryProvider.java delete mode 100644 src/main/java/org/jboss/netty/container/guice/package-info.java rename src/main/java/org/jboss/netty/container/{guice/AbstractChannelFactoryProvider.java => microcontainer/NettyLoggerConfigurator.java} (57%) delete mode 100644 src/main/java/org/jboss/netty/container/microcontainer/NettyResourceFactory.java rename src/main/java/org/jboss/netty/container/{guice/ChannelFactoryResource.java => spring/NettyLoggerConfigurator.java} (54%) delete mode 100644 src/main/java/org/jboss/netty/container/spring/NettyResourceFactory.java diff --git a/pom.xml b/pom.xml index bdad7c8598..1725f7f9cb 100644 --- a/pom.xml +++ b/pom.xml @@ -107,20 +107,6 @@ - - com.google.code.guice - guice - 1.0 - compile - true - - - org.springframework - spring - 2.5.6.SEC01 - compile - true - @@ -428,12 +414,9 @@ ${project.name} API Reference (${project.version}, r${buildNumber}) -link http://java.sun.com/javase/6/docs/api/ - -link http://docs.jboss.org/xnio/latest/api/ -link http://code.google.com/apis/protocolbuffers/docs/reference/java/ -link http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/ -link http://www.osgi.org/javadoc/r4v41/ - -link http://google-guice.googlecode.com/svn/trunk/javadoc/ - -link http://static.springframework.org/spring/docs/2.5.x/api/ -link http://www.slf4j.org/apidocs/ -link http://commons.apache.org/logging/commons-logging-1.1.1/apidocs/ -link http://logging.apache.org/log4j/1.2/apidocs/ diff --git a/src/main/java/org/jboss/netty/container/guice/NettyModule.java b/src/main/java/org/jboss/netty/container/guice/NettyModule.java deleted file mode 100644 index 6af28efa81..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/NettyModule.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -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.ChannelFactory; -import org.jboss.netty.channel.local.DefaultLocalClientChannelFactory; -import org.jboss.netty.channel.local.DefaultLocalServerChannelFactory; -import org.jboss.netty.channel.local.LocalClientChannelFactory; -import org.jboss.netty.channel.local.LocalServerChannelFactory; -import org.jboss.netty.channel.socket.ClientSocketChannelFactory; -import org.jboss.netty.channel.socket.DatagramChannelFactory; -import org.jboss.netty.channel.socket.ServerSocketChannelFactory; -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; -import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; -import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory; -import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory; -import org.jboss.netty.util.internal.ExecutorUtil; -import org.jboss.netty.util.internal.UnterminatableExecutor; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Scopes; - -/** - * A Guice {@link Module} that defines the bindings for all known - * {@link ChannelFactory}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - * - * @apiviz.landmark - */ -public class NettyModule extends AbstractModule { - - private final ExecutorService executor = Executors.newCachedThreadPool(); - - /** - * Releases all resources created by this module. - */ - public void destroy() { - ExecutorUtil.terminate(executor); - } - - @Override - protected void configure() { - if (executor.isShutdown()) { - throw new IllegalStateException( - "Executor has been shut down already."); - } - - Executor executor = new UnterminatableExecutor(this.executor); - - bind(Executor.class). - annotatedWith(ChannelFactoryResource.class). - toInstance(executor); - - bind(ClientSocketChannelFactory.class). - toProvider(NioClientSocketChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(ServerSocketChannelFactory.class). - toProvider(NioServerSocketChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(DatagramChannelFactory.class). - toProvider(OioDatagramChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(NioClientSocketChannelFactory.class). - toProvider(NioClientSocketChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(NioServerSocketChannelFactory.class). - toProvider(NioServerSocketChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(NioDatagramChannelFactory.class). - toProvider(NioDatagramChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(OioClientSocketChannelFactory.class). - toProvider(OioClientSocketChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(OioServerSocketChannelFactory.class). - toProvider(OioServerSocketChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - bind(OioDatagramChannelFactory.class). - toProvider(OioDatagramChannelFactoryProvider.class). - in(Scopes.SINGLETON); - - // Local transports - bind(LocalClientChannelFactory.class). - to(DefaultLocalClientChannelFactory.class). - in(Scopes.SINGLETON); - - bind(LocalServerChannelFactory.class). - to(DefaultLocalServerChannelFactory.class). - in(Scopes.SINGLETON); - - bind(DefaultLocalClientChannelFactory.class). - to(DefaultLocalClientChannelFactory.class). - in(Scopes.SINGLETON); - - bind(DefaultLocalServerChannelFactory.class). - to(DefaultLocalServerChannelFactory.class). - in(Scopes.SINGLETON); - } -} diff --git a/src/main/java/org/jboss/netty/container/guice/NioClientSocketChannelFactoryProvider.java b/src/main/java/org/jboss/netty/container/guice/NioClientSocketChannelFactoryProvider.java deleted file mode 100644 index fdbcd07136..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/NioClientSocketChannelFactoryProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.guice; - -import java.util.concurrent.Executor; - -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; - -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * A {@link Provider} that creates a new {@link NioClientSocketChannelFactory}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class NioClientSocketChannelFactoryProvider extends - AbstractChannelFactoryProvider { - - /** - * Creates a new provider with the {@code executor} injected via the - * {@link ChannelFactoryResource} annotation. - */ - @Inject - public NioClientSocketChannelFactoryProvider( - @ChannelFactoryResource Executor executor) { - super(executor); - } - - public NioClientSocketChannelFactory get() { - return new NioClientSocketChannelFactory(executor, executor); - } -} diff --git a/src/main/java/org/jboss/netty/container/guice/NioDatagramChannelFactoryProvider.java b/src/main/java/org/jboss/netty/container/guice/NioDatagramChannelFactoryProvider.java deleted file mode 100644 index 1919576619..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/NioDatagramChannelFactoryProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.guice; - -import java.util.concurrent.Executor; - -import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory; - -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * A {@link Provider} that creates a new {@link NioDatagramChannelFactory}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class NioDatagramChannelFactoryProvider extends - AbstractChannelFactoryProvider { - - /** - * Creates a new provider with the {@code executor} injected via the - * {@link ChannelFactoryResource} annotation. - */ - @Inject - public NioDatagramChannelFactoryProvider( - @ChannelFactoryResource Executor executor) { - super(executor); - } - - public NioDatagramChannelFactory get() { - return new NioDatagramChannelFactory(executor); - } -} diff --git a/src/main/java/org/jboss/netty/container/guice/NioServerSocketChannelFactoryProvider.java b/src/main/java/org/jboss/netty/container/guice/NioServerSocketChannelFactoryProvider.java deleted file mode 100644 index 121d357c69..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/NioServerSocketChannelFactoryProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.guice; - -import java.util.concurrent.Executor; - -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; - -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * A {@link Provider} that creates a new {@link NioServerSocketChannelFactory}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class NioServerSocketChannelFactoryProvider extends - AbstractChannelFactoryProvider { - - /** - * Creates a new provider with the {@code executor} injected via the - * {@link ChannelFactoryResource} annotation. - */ - @Inject - public NioServerSocketChannelFactoryProvider( - @ChannelFactoryResource Executor executor) { - super(executor); - } - - public NioServerSocketChannelFactory get() { - return new NioServerSocketChannelFactory(executor, executor); - } -} diff --git a/src/main/java/org/jboss/netty/container/guice/OioClientSocketChannelFactoryProvider.java b/src/main/java/org/jboss/netty/container/guice/OioClientSocketChannelFactoryProvider.java deleted file mode 100644 index 9737140127..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/OioClientSocketChannelFactoryProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.guice; - -import java.util.concurrent.Executor; - -import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; - -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * A {@link Provider} that creates a new {@link OioClientSocketChannelFactory}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class OioClientSocketChannelFactoryProvider extends - AbstractChannelFactoryProvider { - - /** - * Creates a new provider with the {@code executor} injected via the - * {@link ChannelFactoryResource} annotation. - */ - @Inject - public OioClientSocketChannelFactoryProvider( - @ChannelFactoryResource Executor executor) { - super(executor); - } - - public OioClientSocketChannelFactory get() { - return new OioClientSocketChannelFactory(executor); - } -} diff --git a/src/main/java/org/jboss/netty/container/guice/OioDatagramChannelFactoryProvider.java b/src/main/java/org/jboss/netty/container/guice/OioDatagramChannelFactoryProvider.java deleted file mode 100644 index f469778a2e..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/OioDatagramChannelFactoryProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.guice; - -import java.util.concurrent.Executor; - -import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory; - -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * A {@link Provider} that creates a new {@link OioDatagramChannelFactory}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class OioDatagramChannelFactoryProvider extends - AbstractChannelFactoryProvider { - - /** - * Creates a new provider with the {@code executor} injected via the - * {@link ChannelFactoryResource} annotation. - */ - @Inject - public OioDatagramChannelFactoryProvider( - @ChannelFactoryResource Executor executor) { - super(executor); - } - - public OioDatagramChannelFactory get() { - return new OioDatagramChannelFactory(executor); - } -} diff --git a/src/main/java/org/jboss/netty/container/guice/OioServerSocketChannelFactoryProvider.java b/src/main/java/org/jboss/netty/container/guice/OioServerSocketChannelFactoryProvider.java deleted file mode 100644 index 1531fed366..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/OioServerSocketChannelFactoryProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.guice; - -import java.util.concurrent.Executor; - -import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory; - -import com.google.inject.Inject; -import com.google.inject.Provider; - -/** - * A {@link Provider} that creates a new {@link OioServerSocketChannelFactory}. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class OioServerSocketChannelFactoryProvider extends - AbstractChannelFactoryProvider { - - /** - * Creates a new provider with the {@code executor} injected via the - * {@link ChannelFactoryResource} annotation. - */ - @Inject - public OioServerSocketChannelFactoryProvider( - @ChannelFactoryResource Executor executor) { - super(executor); - } - - public OioServerSocketChannelFactory get() { - return new OioServerSocketChannelFactory(executor, executor); - } -} diff --git a/src/main/java/org/jboss/netty/container/guice/package-info.java b/src/main/java/org/jboss/netty/container/guice/package-info.java deleted file mode 100644 index 2c7b7d1145..0000000000 --- a/src/main/java/org/jboss/netty/container/guice/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * Google Guice integration. - * - * @apiviz.exclude - */ -package org.jboss.netty.container.guice; diff --git a/src/main/java/org/jboss/netty/container/guice/AbstractChannelFactoryProvider.java b/src/main/java/org/jboss/netty/container/microcontainer/NettyLoggerConfigurator.java similarity index 57% rename from src/main/java/org/jboss/netty/container/guice/AbstractChannelFactoryProvider.java rename to src/main/java/org/jboss/netty/container/microcontainer/NettyLoggerConfigurator.java index df99484723..705c5c9b75 100644 --- a/src/main/java/org/jboss/netty/container/guice/AbstractChannelFactoryProvider.java +++ b/src/main/java/org/jboss/netty/container/microcontainer/NettyLoggerConfigurator.java @@ -13,29 +13,20 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.jboss.netty.container.guice; +package org.jboss.netty.container.microcontainer; -import java.util.concurrent.Executor; - -import org.jboss.netty.channel.ChannelFactory; - -import com.google.inject.Provider; +import org.jboss.netty.logging.InternalLoggerFactory; +import org.jboss.netty.logging.JBossLoggerFactory; /** - * A skeletal {@link Provider} implementation for a {@link ChannelFactory}. + * A bean that configures the default {@link InternalLoggerFactory}. * * @author The Netty Project * @author Trustin Lee * @version $Rev$, $Date$ */ -public abstract class AbstractChannelFactoryProvider implements Provider { - - protected final Executor executor; - - protected AbstractChannelFactoryProvider(Executor executor) { - if (executor == null) { - throw new NullPointerException("executor"); - } - this.executor = executor; +public class NettyLoggerConfigurator { + public NettyLoggerConfigurator() { + InternalLoggerFactory.setDefaultFactory(new JBossLoggerFactory()); } } diff --git a/src/main/java/org/jboss/netty/container/microcontainer/NettyResourceFactory.java b/src/main/java/org/jboss/netty/container/microcontainer/NettyResourceFactory.java deleted file mode 100644 index 1f925916fd..0000000000 --- a/src/main/java/org/jboss/netty/container/microcontainer/NettyResourceFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.microcontainer; - -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.logging.InternalLoggerFactory; -import org.jboss.netty.logging.JBossLoggerFactory; -import org.jboss.netty.util.internal.ExecutorUtil; -import org.jboss.netty.util.internal.UnterminatableExecutor; - -/** - * A factory bean that provides the common resources required by - * {@link ChannelFactory} implementations. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class NettyResourceFactory { - private Executor executor; - private Executor unterminatableExecutor; - - public synchronized void create() { - if (executor != null) { - return; - } - - executor = Executors.newCachedThreadPool(); - unterminatableExecutor = new UnterminatableExecutor(executor); - } - - public void start() { - InternalLoggerFactory.setDefaultFactory(new JBossLoggerFactory()); - } - - public synchronized void stop() { - if (executor != null) { - ExecutorUtil.terminate(executor); - } - } - - public synchronized void destroy() { - executor = null; - unterminatableExecutor = null; - } - - public synchronized Executor getChannelFactoryExecutor() { - return unterminatableExecutor; - } -} diff --git a/src/main/java/org/jboss/netty/container/osgi/NettyBundleActivator.java b/src/main/java/org/jboss/netty/container/osgi/NettyBundleActivator.java index 4a4f0b5ab9..e7c78a3077 100644 --- a/src/main/java/org/jboss/netty/container/osgi/NettyBundleActivator.java +++ b/src/main/java/org/jboss/netty/container/osgi/NettyBundleActivator.java @@ -15,36 +15,13 @@ */ package org.jboss.netty.container.osgi; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.channel.local.DefaultLocalClientChannelFactory; -import org.jboss.netty.channel.local.DefaultLocalServerChannelFactory; -import org.jboss.netty.channel.local.LocalClientChannelFactory; -import org.jboss.netty.channel.local.LocalServerChannelFactory; -import org.jboss.netty.channel.socket.ClientSocketChannelFactory; -import org.jboss.netty.channel.socket.DatagramChannelFactory; -import org.jboss.netty.channel.socket.ServerSocketChannelFactory; -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; -import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; -import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory; -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.internal.ExecutorUtil; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; /** - * An OSGi {@link BundleActivator} that configures logging and registered - * all {@link ChannelFactory} implementations as OSGi services. + * An OSGi {@link BundleActivator} that configures logging. * * @author The Netty Project * @author Trustin Lee @@ -52,77 +29,19 @@ import org.osgi.framework.ServiceRegistration; */ public class NettyBundleActivator implements BundleActivator { - private final List registrations = - new ArrayList(); - - private Executor executor; private OsgiLoggerFactory loggerFactory; public void start(BundleContext ctx) throws Exception { // Switch the internal logger to the OSGi LogService. loggerFactory = new OsgiLoggerFactory(ctx); InternalLoggerFactory.setDefaultFactory(loggerFactory); - - // Prepare the resources required for creating ChannelFactories. - Executor executor = this.executor = Executors.newCachedThreadPool(); - - // The default transport is NIO. - register(ctx, - new NioClientSocketChannelFactory(executor, executor), - ClientSocketChannelFactory.class); - register(ctx, - new NioServerSocketChannelFactory(executor, executor), - ServerSocketChannelFactory.class); - // ... except for the datagram transport. - register(ctx, - new OioDatagramChannelFactory(executor), - DatagramChannelFactory.class); - - // Local transports - register(ctx, - new DefaultLocalClientChannelFactory(), - LocalClientChannelFactory.class); - register(ctx, - new DefaultLocalServerChannelFactory(), - LocalServerChannelFactory.class); - - // Miscellaneous transports - register(ctx, new OioClientSocketChannelFactory(executor)); - register(ctx, new OioServerSocketChannelFactory(executor, executor)); - register(ctx, new NioDatagramChannelFactory(executor)); } public void stop(BundleContext ctx) throws Exception { - unregisterAll(); - if (executor != null) { - ExecutorUtil.terminate(executor); - executor = null; - } - if (loggerFactory != null) { InternalLoggerFactory.setDefaultFactory(loggerFactory.getFallback()); loggerFactory.destroy(); loggerFactory = null; } } - - private void register(BundleContext ctx, ChannelFactory factory, Class... factoryTypes) { - Properties props = new Properties(); - props.setProperty("category", "netty"); - - registrations.add(ctx.registerService(factory.getClass().getName(), factory, props)); - - for (Class t: factoryTypes) { - registrations.add(ctx.registerService(t.getName(), factory, props)); - } - } - - private void unregisterAll() { - List registrationsCopy = - new ArrayList(registrations); - registrations.clear(); - for (ServiceRegistration r: registrationsCopy) { - r.unregister(); - } - } } diff --git a/src/main/java/org/jboss/netty/container/guice/ChannelFactoryResource.java b/src/main/java/org/jboss/netty/container/spring/NettyLoggerConfigurator.java similarity index 54% rename from src/main/java/org/jboss/netty/container/guice/ChannelFactoryResource.java rename to src/main/java/org/jboss/netty/container/spring/NettyLoggerConfigurator.java index 2a09539fb0..c00036b719 100644 --- a/src/main/java/org/jboss/netty/container/guice/ChannelFactoryResource.java +++ b/src/main/java/org/jboss/netty/container/spring/NettyLoggerConfigurator.java @@ -13,30 +13,20 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.jboss.netty.container.guice; +package org.jboss.netty.container.spring; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.jboss.netty.channel.ChannelFactory; - -import com.google.inject.BindingAnnotation; +import org.jboss.netty.logging.CommonsLoggerFactory; +import org.jboss.netty.logging.InternalLoggerFactory; /** - * A parameter or a field annotated with this annotation will be injected with - * the resource required to run a {@link ChannelFactory}. + * A bean that configures the default {@link InternalLoggerFactory}. * * @author The Netty Project * @author Trustin Lee * @version $Rev$, $Date$ */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.PARAMETER}) -@BindingAnnotation -@Documented -public @interface ChannelFactoryResource { - // No value required +public class NettyLoggerConfigurator { + public NettyLoggerConfigurator() { + InternalLoggerFactory.setDefaultFactory(new CommonsLoggerFactory()); + } } diff --git a/src/main/java/org/jboss/netty/container/spring/NettyResourceFactory.java b/src/main/java/org/jboss/netty/container/spring/NettyResourceFactory.java deleted file mode 100644 index 5150d9836d..0000000000 --- a/src/main/java/org/jboss/netty/container/spring/NettyResourceFactory.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.container.spring; - -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.logging.CommonsLoggerFactory; -import org.jboss.netty.logging.InternalLoggerFactory; -import org.jboss.netty.util.internal.ExecutorUtil; -import org.jboss.netty.util.internal.UnterminatableExecutor; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; - -/** - * A factory bean that provides the common resources required by - * {@link ChannelFactory} implementations. - * - * @author The Netty Project - * @author Trustin Lee - * @version $Rev$, $Date$ - */ -public class NettyResourceFactory implements InitializingBean, DisposableBean { - private Executor executor; - private Executor unterminatableExecutor; - - public synchronized void afterPropertiesSet() { - if (executor != null) { - return; - } - - executor = Executors.newCachedThreadPool(); - unterminatableExecutor = new UnterminatableExecutor(executor); - InternalLoggerFactory.setDefaultFactory(new CommonsLoggerFactory()); - } - - public synchronized void destroy() { - if (executor != null) { - ExecutorUtil.terminate(executor); - } - - executor = null; - unterminatableExecutor = null; - } - - public synchronized Executor getChannelFactoryExecutor() { - return unterminatableExecutor; - } -} diff --git a/src/main/resources/META-INF/jboss-beans.xml b/src/main/resources/META-INF/jboss-beans.xml index 3856531b3f..00a106e1ae 100644 --- a/src/main/resources/META-INF/jboss-beans.xml +++ b/src/main/resources/META-INF/jboss-beans.xml @@ -18,104 +18,7 @@ xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd" xmlns="urn:jboss:bean-deployer:2.0"> - - - - org.jboss.netty.internal.ResourceFactory - - - - + - - org.jboss.netty.channel.socket.ClientSocketChannelFactory - org.jboss.netty.internal.ChannelFactoryExecutor - - - - - - - - - - - - org.jboss.netty.channel.socket.ServerSocketChannelFactory - org.jboss.netty.internal.ChannelFactoryExecutor - - - - - - - - - - - - org.jboss.netty.internal.ChannelFactoryExecutor - - - - - - - - - org.jboss.netty.internal.ChannelFactoryExecutor - - - - - - - - - org.jboss.netty.internal.ChannelFactoryExecutor - - - - - - - - - - - - org.jboss.netty.channel.socket.DatagramChannelFactory - org.jboss.netty.internal.ChannelFactoryExecutor - - - - - - - - - org.jboss.netty.channel.local.LocalClientChannelFactory - - - - org.jboss.netty.channel.local.LocalServerChannelFactory - \ No newline at end of file diff --git a/src/main/resources/org/jboss/netty/container/spring/beans.xml b/src/main/resources/org/jboss/netty/container/spring/beans.xml index b5c41b06db..2fec0fc4d8 100644 --- a/src/main/resources/org/jboss/netty/container/spring/beans.xml +++ b/src/main/resources/org/jboss/netty/container/spring/beans.xml @@ -18,72 +18,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -