cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1560912 - in /cxf/trunk/rt/transports/http-netty/netty-client/src: main/java/org/apache/cxf/transport/http/netty/client/ test/java/org/apache/cxf/transport/http/netty/client/
Date Fri, 24 Jan 2014 07:39:27 GMT
Author: ningjiang
Date: Fri Jan 24 07:39:27 2014
New Revision: 1560912

URL: http://svn.apache.org/r1560912
Log:
CXF-5511 close the EventLoopGroup when the bus is shutdown

Modified:
    cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
    cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
    cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
    cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactoryTest.java

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java?rev=1560912&r1=1560911&r2=1560912&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
Fri Jan 24 07:39:27 2014
@@ -63,6 +63,7 @@ import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.nio.NioSocketChannel;
 import io.netty.handler.codec.http.HttpContent;
 import io.netty.handler.codec.http.HttpResponse;
@@ -80,7 +81,8 @@ public class NettyHttpConduit extends UR
         super(b, ei, t);
         factory = conduitFactory;
         bootstrap = new Bootstrap();
-        bootstrap.group(factory.getEventLoopGroup());
+        EventLoopGroup eventLoopGroup = bus.getExtension(EventLoopGroup.class);
+        bootstrap.group(eventLoopGroup);
         bootstrap.channel(NioSocketChannel.class);
     }
     

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java?rev=1560912&r1=1560911&r2=1560912&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
Fri Jan 24 07:39:27 2014
@@ -23,7 +23,7 @@ import java.io.IOException;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.buslifecycle.BusLifeCycleListener;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transport.http.HTTPConduitFactory;
@@ -34,15 +34,9 @@ import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 
 
-@NoJSR250Annotations
-public class NettyHttpConduitFactory implements BusLifeCycleListener, HTTPConduitFactory
{
-
-    boolean isShutdown;
-    
-    final EventLoopGroup eventLoopGroup; 
+public class NettyHttpConduitFactory implements HTTPConduitFactory {
 
     public NettyHttpConduitFactory() {
-        eventLoopGroup = new NioEventLoopGroup();
     }
 
     @Override
@@ -51,6 +45,15 @@ public class NettyHttpConduitFactory imp
                                      EndpointInfo localInfo,
                                      EndpointReferenceType target)
         throws IOException {
+        // need to check if the EventLoopGroup is created or not
+        // if not create a new EventLoopGroup for it
+        EventLoopGroup eventLoopGroup = bus.getExtension(EventLoopGroup.class);
+        if (eventLoopGroup == null) {
+            final EventLoopGroup group = new NioEventLoopGroup();
+            // register a BusLifeCycleListener for it
+            bus.setExtension(group, EventLoopGroup.class);
+            registerBusLifeListener(bus, group);
+        }
         return new NettyHttpConduit(bus, localInfo, target, this);
     }
     
@@ -59,30 +62,32 @@ public class NettyHttpConduitFactory imp
                                      EndpointInfo localInfo,
                                      EndpointReferenceType target)
         throws IOException {
-        return new NettyHttpConduit(bus, localInfo, target, this);
-    }
-
-    @Override
-    public void initComplete() {
-        isShutdown = false;
-    }
-
-    @Override
-    public void preShutdown() {
-        isShutdown = true;
-    }
-
-    @Override
-    public void postShutdown() {
-        eventLoopGroup.shutdownGracefully().syncUninterruptibly();
-    }
-
-    public boolean isShutdown() {
-        return isShutdown;
+        return createConduit(null, bus, localInfo, target);
     }
     
-    public EventLoopGroup getEventLoopGroup() {
-        return eventLoopGroup;
+    protected void registerBusLifeListener(Bus bus, final EventLoopGroup group) {
+        BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
+        if (null != lifeCycleManager) {
+            lifeCycleManager.registerLifeCycleListener(new BusLifeCycleListener() {
+
+                @Override
+                public void initComplete() {
+                    // do nothing here
+                }
+
+                @Override
+                public void preShutdown() {
+                    // do nothing here
+                }
+
+                @Override
+                public void postShutdown() {
+                    // shutdown the EventLoopGroup
+                    group.shutdownGracefully().syncUninterruptibly();
+                }
+                
+            });
+        }  
     }
 
 }

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java?rev=1560912&r1=1560911&r2=1560912&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
Fri Jan 24 07:39:27 2014
@@ -36,6 +36,7 @@ import org.apache.cxf.transport.http.HTT
 import org.apache.cxf.transport.http.HTTPConduitConfigurer;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 
+
 public class NettyHttpTransportFactory extends AbstractTransportFactory implements ConduitInitiator
{
 
     public static final List<String> DEFAULT_NAMESPACES = Arrays
@@ -46,6 +47,8 @@ public class NettyHttpTransportFactory e
      */
     private static final Set<String> URI_PREFIXES = new HashSet<String>();
     
+   
+    
     static {
         URI_PREFIXES.add("netty://");
     }
@@ -90,6 +93,8 @@ public class NettyHttpTransportFactory e
         return address;
     }
     
+    
+    
     @Override
     public Conduit getConduit(EndpointInfo endpointInfo, Bus bus) throws IOException {
         return getConduit(endpointInfo, endpointInfo.getTarget(), bus);
@@ -118,5 +123,6 @@ public class NettyHttpTransportFactory e
         conduit.finalizeConfig();
         return conduit;
     }
-
+    
+    
 }

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactoryTest.java?rev=1560912&r1=1560911&r2=1560912&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactoryTest.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactoryTest.java
Fri Jan 24 07:39:27 2014
@@ -18,16 +18,24 @@
  */
 package org.apache.cxf.transport.http.netty.client;
 
+import javax.xml.namespace.QName;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.transport.http.HTTPConduitFactory;
+
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import io.netty.channel.EventLoopGroup;
+
+
+
 public class NettyHttpConduitFactoryTest extends Assert {
     Bus bus;
 
@@ -64,6 +72,35 @@ public class NettyHttpConduitFactoryTest
         assertNotNull("Cannot get HTTPConduitFactory", factory);
 
         assertTrue(NettyHttpConduitFactory.class.isInstance(factory));
+        
 
     }
+    
+    @Test
+    public void testShutdownEventLoopGroup() throws Exception {
+        bus = BusFactory.getDefaultBus(true);
+
+        assertNotNull("Cannot get bus", bus);
+
+        // Make sure we got the Transport Factory.
+        NettyHttpTransportFactory factory =
+                bus.getExtension(NettyHttpTransportFactory.class);
+        assertNotNull("Cannot get NettyHttpTransportFactory", factory);
+
+        ServiceInfo serviceInfo = new ServiceInfo();
+        serviceInfo.setName(new QName("bla", "Service"));        
+        EndpointInfo ei = new EndpointInfo(serviceInfo, "");
+        ei.setName(new QName("bla", "Port"));
+        ei.setAddress("netty://foo");
+        
+        // The EventLoopGroup is put into bus when create a new netty http conduit
+        factory.getConduit(ei, null, bus);
+        
+        bus.shutdown(true);
+        
+        EventLoopGroup eventLoopGroup = bus.getExtension(EventLoopGroup.class);
+        assertNotNull("We should find the EventLoopGroup here.", eventLoopGroup);
+        assertTrue("The eventLoopGroup should be shutdown.", eventLoopGroup.isShutdown());
+ 
+    }
 }



Mime
View raw message