Author: alessio.soldano(a)jboss.com
Date: 2009-10-08 13:48:03 -0400 (Thu, 08 Oct 2009)
New Revision: 10868
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/ClientSocketChannelFactoryProvider.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/DefaultClientSocketChannelFactoryProvider.java
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyTransportHandler.java
Log:
[JBWS-2781] Adding ClientSocketChannelFactoryProvider interface users can implement to
provide their own factories (relies on the usual ServiceLoader system)
[JBWS-2753] The DefaultClientSocketChannelFactoryProvider recycle the
SocketChannelFactory, reducing resources/memory consumption.
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/ClientSocketChannelFactoryProvider.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/ClientSocketChannelFactoryProvider.java
(rev 0)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/ClientSocketChannelFactoryProvider.java 2009-10-08
17:48:03 UTC (rev 10868)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ws.core.client.transport;
+
+import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
+
+/**
+ * Provide the org.jboss.netty.channel.socket.ClientSocketChannelFactory
+ * instances to be used each time the JBossWS Netty transport layer
+ * requires a new channel factory to later create a channel.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 08-Oct-2009
+ *
+ */
+public interface ClientSocketChannelFactoryProvider
+{
+ public ClientSocketChannelFactory getClientSocketChannelFactoryInstance();
+}
Property changes on:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/ClientSocketChannelFactoryProvider.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/DefaultClientSocketChannelFactoryProvider.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/DefaultClientSocketChannelFactoryProvider.java
(rev 0)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/DefaultClientSocketChannelFactoryProvider.java 2009-10-08
17:48:03 UTC (rev 10868)
@@ -0,0 +1,61 @@
+/*
+ * 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.ws.core.client.transport;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
+import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
+
+/**
+ * The default provider of Netty ClientSocketChannelFactory.
+ * This basically returns a singleton NioClientSocketChannelFactory using
+ * cached thread pools for both boss and worker executors.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 08-Oct-2009
+ *
+ */
+public class DefaultClientSocketChannelFactoryProvider implements
ClientSocketChannelFactoryProvider
+{
+ private static Executor bossExecutor = Executors.newCachedThreadPool();
+ private static Executor workerExecutor = Executors.newCachedThreadPool();
+
+ private static ClientSocketChannelFactory factory;
+
+ public ClientSocketChannelFactory getClientSocketChannelFactoryInstance()
+ {
+ return getFactory();
+ }
+
+ private static synchronized ClientSocketChannelFactory getFactory()
+ {
+ if (factory == null)
+ {
+ factory = new NioClientSocketChannelFactory(bossExecutor, workerExecutor);
+ }
+ return factory;
+ }
+
+}
Property changes on:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/DefaultClientSocketChannelFactoryProvider.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyTransportHandler.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyTransportHandler.java 2009-10-08
15:55:09 UTC (rev 10867)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/client/transport/NettyTransportHandler.java 2009-10-08
17:48:03 UTC (rev 10868)
@@ -41,6 +41,7 @@
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.ws.Constants;
+import org.jboss.wsf.spi.util.ServiceLoader;
/**
* This handles the Netty channels, allowing for a
@@ -58,7 +59,7 @@
private URL url;
private ChannelFuture connectFuture;
private Channel channel;
- private ChannelFactory factory;
+ private static ClientSocketChannelFactoryProvider factoryProvider;
//the idle cache
private static KeepAliveCache cache = new KeepAliveCache();
private static boolean keepAliveProp = true;
@@ -72,9 +73,6 @@
//the keep alive timeout in seconds
private int keepAliveTimeout;
- private static Executor bossExecutor = Executors.newCachedThreadPool();
- private static Executor workerExecutor = Executors.newCachedThreadPool();
-
static
{
String keepAlive = AccessController.doPrivileged(new
java.security.PrivilegedAction<String>() {
@@ -91,13 +89,14 @@
{
keepAliveProp = true;
}
+ factoryProvider =
(ClientSocketChannelFactoryProvider)ServiceLoader.loadService(ClientSocketChannelFactoryProvider.class.getName(),
+ DefaultClientSocketChannelFactoryProvider.class.getName());
}
private NettyTransportHandler(URL url, ChannelPipelineFactory pipelineFactory)
{
this.url = url;
-
- factory = new NioClientSocketChannelFactory(bossExecutor, workerExecutor);
+ ChannelFactory factory = factoryProvider.getClientSocketChannelFactoryInstance();
ClientBootstrap bootstrap = new ClientBootstrap(factory);
bootstrap.setPipelineFactory(pipelineFactory);