tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1505 cleaning cxf bus at then end of its usage
Date Wed, 04 Feb 2015 12:52:11 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop 40105b482 -> e9c8bb3a6


TOMEE-1505 cleaning cxf bus at then end of its usage


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e9c8bb3a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e9c8bb3a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e9c8bb3a

Branch: refs/heads/develop
Commit: e9c8bb3a601c205a89c0e74b0597bf075f53b815
Parents: 40105b4
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Wed Feb 4 13:52:07 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Wed Feb 4 13:52:07 2015 +0100

----------------------------------------------------------------------
 .../openejb/server/cxf/rs/CxfRSService.java     |  6 +++++
 .../server/cxf/transport/util/CxfUtil.java      | 24 +++++++++++++++-----
 .../apache/openejb/server/cxf/CxfService.java   |  8 +++++++
 3 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/e9c8bb3a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
index ddf4535..fff5734 100644
--- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
+++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java
@@ -184,6 +184,12 @@ public class CxfRSService extends RESTService {
     }
 
     @Override
+    public void stop() throws ServiceException {
+        super.stop();
+        CxfUtil.release();
+    }
+
+    @Override
     protected void beforeStart() {
         super.beforeStart();
         destinationFactory = new HTTPTransportFactory();

http://git-wip-us.apache.org/repos/asf/tomee/blob/e9c8bb3a/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
b/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
index 97e9184..83f3beb 100644
--- a/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
+++ b/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.server.cxf.transport.util;
 
+import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.BindingFactory;
@@ -69,13 +70,23 @@ public final class CxfUtil {
     public static final String DEBUG = "debug";
     public static final String BUS_PREFIX = "org.apache.openejb.cxf.bus.";
     public static final String BUS_CONFIGURED_FLAG = "openejb.cxf.bus.configured";
-    private static final AtomicReference<Bus> DEFAULT_BUS = new AtomicReference<Bus>();
+    private static final AtomicReference<Bus> DEFAULT_BUS = new AtomicReference<>();
+    private static final AtomicInteger USER_COUNT = new AtomicInteger();
     private static Map<String, BindingFactory> bindingFactoryMap;
 
     private CxfUtil() {
         // no-op
     }
 
+    public static void release() { // symmetric of configureBus(), when last caller of configureBus()
is calls this bus is destroyed
+        if (USER_COUNT.decrementAndGet() == 0) {
+            final Bus b = DEFAULT_BUS.get();
+            if (b != null) {
+                b.shutdown(true);
+            }
+        }
+    }
+
     public static boolean hasService(final String name) {
         return bindingFactoryMap != null && bindingFactoryMap.containsKey(name);
     }
@@ -133,7 +144,7 @@ public final class CxfUtil {
     public static void clearBusLoader(final ClassLoader old) {
         final ClassLoader loader = CxfUtil.getBus().getExtension(ClassLoader.class);
         if (loader != null && CxfContainerClassLoader.class.isInstance(loader)
-            && (old == null || !CxfContainerClassLoader.class.isInstance(old))) {
+                && (old == null || !CxfContainerClassLoader.class.isInstance(old)))
{
             CxfContainerClassLoader.class.cast(loader).clear();
         }
         Thread.currentThread().setContextClassLoader(old);
@@ -181,7 +192,7 @@ public final class CxfUtil {
 
             if (!DataBinding.class.isInstance(instance)) {
                 throw new OpenEJBRuntimeException(instance + " is not a " + DataBinding.class.getName()
-                    + ", please check configuration of service [id=" + databinding + "]");
+                        + ", please check configuration of service [id=" + databinding +
"]");
             }
             svrFactory.setDataBinding((DataBinding) instance);
         }
@@ -237,11 +248,12 @@ public final class CxfUtil {
     }
 
     public static void configureBus() {
-        final SystemInstance systemInstance = SystemInstance.get();
-        if (systemInstance.getProperties().containsKey(BUS_CONFIGURED_FLAG)) { // jaxws and
jaxrs for instance
+        if (USER_COUNT.incrementAndGet() > 1) {
             return;
         }
 
+        final SystemInstance systemInstance = SystemInstance.get();
+
         final Bus bus = getBus();
 
         // ensure cxf classes are loaded from container to avoid conflicts with app
@@ -273,7 +285,7 @@ public final class CxfUtil {
         }
 
         final ServiceConfiguration configuration = new ServiceConfiguration(systemInstance.getProperties(),
-            systemInstance.getComponent(OpenEjbConfiguration.class).facilities.services);
+                systemInstance.getComponent(OpenEjbConfiguration.class).facilities.services);
 
         final Collection<ServiceInfo> serviceInfos = configuration.getAvailableServices();
         Properties properties = configuration.getProperties();

http://git-wip-us.apache.org/repos/asf/tomee/blob/e9c8bb3a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
index 0b97de8..454835e 100644
--- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
+++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java
@@ -25,6 +25,7 @@ import org.apache.openejb.assembler.classic.util.ServiceConfiguration;
 import org.apache.openejb.core.ivm.naming.JaxWsServiceReference;
 import org.apache.openejb.core.webservices.PortData;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.server.ServiceException;
 import org.apache.openejb.server.cxf.client.SaajInterceptor;
 import org.apache.openejb.server.cxf.client.WebServiceInjectionConfigurator;
 import org.apache.openejb.server.cxf.ejb.EjbWsContainer;
@@ -53,6 +54,7 @@ public class CxfService extends WsService {
         return "cxf";
     }
 
+    @Override
     public void init(final Properties props) throws java.lang.Exception {
         super.init(props);
         CxfUtil.configureBus();
@@ -66,6 +68,12 @@ public class CxfService extends WsService {
     }
 
     @Override
+    public void stop() throws ServiceException {
+        super.stop();
+        CxfUtil.release();
+    }
+
+    @Override
     protected void setWsdl(final HttpListener listener, final String wsdl) {
         if (CxfWsContainer.class.isInstance(listener)) {
             CxfWsContainer.class.cast(listener).setWsldUrl(wsdl);


Mime
View raw message