Simplified container integration by removing unused features
This commit is contained in:
parent
3f7fff3fa5
commit
1ae76562b7
17
pom.xml
17
pom.xml
@ -107,20 +107,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.guice</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring</artifactId>
|
||||
<version>2.5.6.SEC01</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging frameworks - completely optional -->
|
||||
<dependency>
|
||||
@ -428,12 +414,9 @@
|
||||
<windowtitle>${project.name} API Reference (${project.version}, r${buildNumber})</windowtitle>
|
||||
<additionalparam>
|
||||
-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/
|
||||
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @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);
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class NioClientSocketChannelFactoryProvider extends
|
||||
AbstractChannelFactoryProvider<NioClientSocketChannelFactory> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class NioDatagramChannelFactoryProvider extends
|
||||
AbstractChannelFactoryProvider<NioDatagramChannelFactory> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class NioServerSocketChannelFactoryProvider extends
|
||||
AbstractChannelFactoryProvider<NioServerSocketChannelFactory> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class OioClientSocketChannelFactoryProvider extends
|
||||
AbstractChannelFactoryProvider<OioClientSocketChannelFactory> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class OioDatagramChannelFactoryProvider extends
|
||||
AbstractChannelFactoryProvider<OioDatagramChannelFactory> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class OioServerSocketChannelFactoryProvider extends
|
||||
AbstractChannelFactoryProvider<OioServerSocketChannelFactory> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* <a href="http://code.google.com/p/google-guice/">Google Guice</a> integration.
|
||||
*
|
||||
* @apiviz.exclude
|
||||
*/
|
||||
package org.jboss.netty.container.guice;
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public abstract class AbstractChannelFactoryProvider<T extends ChannelFactory> implements Provider<T> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @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;
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
@ -52,77 +29,19 @@ import org.osgi.framework.ServiceRegistration;
|
||||
*/
|
||||
public class NettyBundleActivator implements BundleActivator {
|
||||
|
||||
private final List<ServiceRegistration> registrations =
|
||||
new ArrayList<ServiceRegistration>();
|
||||
|
||||
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<ServiceRegistration> registrationsCopy =
|
||||
new ArrayList<ServiceRegistration>(registrations);
|
||||
registrations.clear();
|
||||
for (ServiceRegistration r: registrationsCopy) {
|
||||
r.unregister();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @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());
|
||||
}
|
||||
}
|
@ -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 <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @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;
|
||||
}
|
||||
}
|
@ -18,104 +18,7 @@
|
||||
xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
|
||||
xmlns="urn:jboss:bean-deployer:2.0">
|
||||
|
||||
<bean name="org.jboss.netty.internal.ResourceFactory"
|
||||
class="org.jboss.netty.container.microcontainer.NettyResourceFactory" />
|
||||
|
||||
<bean name="org.jboss.netty.internal.ChannelFactoryExecutor"
|
||||
class="java.util.concurrent.Executor">
|
||||
<depends>org.jboss.netty.internal.ResourceFactory</depends>
|
||||
<constructor factoryMethod="getChannelFactoryExecutor">
|
||||
<factory bean="org.jboss.netty.internal.ResourceFactory"/>
|
||||
</constructor>
|
||||
</bean>
|
||||
<bean name="org.jboss.netty.internal.LoggerConfigurator"
|
||||
class="org.jboss.netty.container.microcontainer.NettyLoggerConfigurator" />
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory">
|
||||
<alias>org.jboss.netty.channel.socket.ClientSocketChannelFactory</alias>
|
||||
<depends>org.jboss.netty.internal.ChannelFactoryExecutor</depends>
|
||||
<constructor>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
</constructor>
|
||||
</bean>
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory">
|
||||
<alias>org.jboss.netty.channel.socket.ServerSocketChannelFactory</alias>
|
||||
<depends>org.jboss.netty.internal.ChannelFactoryExecutor</depends>
|
||||
<constructor>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
</constructor>
|
||||
</bean>
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory">
|
||||
<depends>org.jboss.netty.internal.ChannelFactoryExecutor</depends>
|
||||
<constructor>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
</constructor>
|
||||
</bean>
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory">
|
||||
<depends>org.jboss.netty.internal.ChannelFactoryExecutor</depends>
|
||||
<constructor>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
</constructor>
|
||||
</bean>
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory">
|
||||
<depends>org.jboss.netty.internal.ChannelFactoryExecutor</depends>
|
||||
<constructor>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
</constructor>
|
||||
</bean>
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory">
|
||||
<alias>org.jboss.netty.channel.socket.DatagramChannelFactory</alias>
|
||||
<depends>org.jboss.netty.internal.ChannelFactoryExecutor</depends>
|
||||
<constructor>
|
||||
<parameter class="java.util.concurrent.Executor">
|
||||
<inject bean="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</parameter>
|
||||
</constructor>
|
||||
</bean>
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.local.DefaultLocalClientChannelFactory"
|
||||
class="org.jboss.netty.channel.local.DefaultLocalClientChannelFactory">
|
||||
<alias>org.jboss.netty.channel.local.LocalClientChannelFactory</alias>
|
||||
</bean>
|
||||
|
||||
<bean mode="On Demand"
|
||||
name="org.jboss.netty.channel.local.DefaultLocalServerChannelFactory"
|
||||
class="org.jboss.netty.channel.local.DefaultLocalServerChannelFactory">
|
||||
<alias>org.jboss.netty.channel.local.LocalServerChannelFactory</alias>
|
||||
</bean>
|
||||
</deployment>
|
@ -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">
|
||||
|
||||
<bean id="org.jboss.netty.internal.ResourceFactory"
|
||||
class="org.jboss.netty.container.spring.NettyResourceFactory"
|
||||
<bean id="org.jboss.netty.internal.LoggerConfigurator"
|
||||
class="org.jboss.netty.container.spring.NettyLoggerConfigurator"
|
||||
scope="singleton" />
|
||||
|
||||
<bean id="org.jboss.netty.internal.ChannelFactoryExecutor"
|
||||
factory-bean="org.jboss.netty.internal.ResourceFactory"
|
||||
factory-method="getChannelFactoryExecutor"
|
||||
scope="singleton" />
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory">
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</bean>
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory">
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</bean>
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory">
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</bean>
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory">
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</bean>
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory">
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</bean>
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory"
|
||||
class="org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory">
|
||||
<constructor-arg ref="org.jboss.netty.internal.ChannelFactoryExecutor"/>
|
||||
</bean>
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.local.DefaultLocalClientChannelFactory"
|
||||
class="org.jboss.netty.channel.local.DefaultLocalClientChannelFactory">
|
||||
</bean>
|
||||
|
||||
<bean lazy-init="true" scope="singleton"
|
||||
name="org.jboss.netty.channel.local.DefaultLocalServerChannelFactory"
|
||||
class="org.jboss.netty.channel.local.DefaultLocalServerChannelFactory">
|
||||
</bean>
|
||||
|
||||
<alias name="org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory"
|
||||
alias="org.jboss.netty.channel.socket.ClientSocketChannelFactory" />
|
||||
<alias name="org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory"
|
||||
alias="org.jboss.netty.channel.socket.ServerSocketChannelFactory" />
|
||||
<alias name="org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory"
|
||||
alias="org.jboss.netty.channel.socket.DatagramChannelFactory" />
|
||||
<alias name="org.jboss.netty.channel.local.DefaultLocalClientChannelFactory"
|
||||
alias="org.jboss.netty.channel.local.LocalClientChannelFactory" />
|
||||
<alias name="org.jboss.netty.channel.local.DefaultLocalServerChannelFactory"
|
||||
alias="org.jboss.netty.channel.local.LocalServerChannelFactory" />
|
||||
</beans>
|
||||
|
Loading…
Reference in New Issue
Block a user