cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r1037346 - in /cxf/trunk: api/src/main/java/org/apache/cxf/ maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ rt/core/src/test/java/org/apache/cxf/bus/spring/
Date Sat, 20 Nov 2010 22:31:29 GMT
Author: bimargulies
Date: Sat Nov 20 22:31:29 2010
New Revision: 1037346

URL: http://svn.apache.org/viewvc?rev=1037346&view=rev
Log:
Hold the defaultBus as a weak reference: CXF-3142.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java?rev=1037346&r1=1037345&r2=1037346&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java Sat Nov 20 22:31:29 2010
@@ -22,6 +22,7 @@ package org.apache.cxf;
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.lang.ref.WeakReference;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.WeakHashMap;
@@ -36,7 +37,7 @@ public abstract class BusFactory {
     public static final String BUS_FACTORY_PROPERTY_NAME = "org.apache.cxf.bus.factory";
     public static final String DEFAULT_BUS_FACTORY = "org.apache.cxf.bus.CXFBusFactory";
 
-    protected static Bus defaultBus;
+    protected static WeakReference<Bus> defaultBus;
     protected static Map<Thread, Bus> threadBusses = new WeakHashMap<Thread, Bus>();
 
     private static final Logger LOG = LogUtils.getL7dLogger(BusFactory.class, "APIMessages");
@@ -67,11 +68,16 @@ public abstract class BusFactory {
      * @return the default bus.
      */
     public static synchronized Bus getDefaultBus(boolean createIfNeeded) {
-        if (defaultBus == null
+        if ((defaultBus == null || defaultBus.get() == null)
             && createIfNeeded) {
-            defaultBus = newInstance().createBus();
+            defaultBus = new WeakReference<Bus>(newInstance().createBus());
+        }
+        if (defaultBus == null) {
+            // never set up.
+            return null;
+        } else {
+            return defaultBus.get();
         }
-        return defaultBus;
     }
     
     /**
@@ -79,7 +85,11 @@ public abstract class BusFactory {
      * @param bus the default bus.
      */
     public static synchronized void setDefaultBus(Bus bus) {
-        defaultBus = bus;
+        if (bus == null) {
+            defaultBus = null;
+        } else {
+            defaultBus = new WeakReference<Bus>(bus);
+        }
         setThreadDefaultBus(bus);
     }
     
@@ -154,11 +164,12 @@ public abstract class BusFactory {
                 threadBusses.put(Thread.currentThread(), bus);
             }
         }
-        
-        if (defaultBus == null) {
-            defaultBus = bus;            
+        // The default bus may have gc-ed itself out of existence, in which case we 
+        // take over for it.
+        if (defaultBus == null || defaultBus.get() == null) {
+            defaultBus = new WeakReference<Bus>(bus);            
             return true;
-        }
+        } 
         return false;
     }
 

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java?rev=1037346&r1=1037345&r2=1037346&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java
Sat Nov 20 22:31:29 2010
@@ -118,5 +118,6 @@ public class ClassLoaderSwitcher {
             }
         }
         System.getProperties().putAll(origProps);
+        origContextClassloader = null; // don't hold a reference.
     }
 }

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java?rev=1037346&r1=1037345&r2=1037346&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java (original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java Sat
Nov 20 22:31:29 2010
@@ -169,7 +169,7 @@ public class SpringBusFactoryTest extend
         assertTrue("@PostConstruct annotated method has not been called.", te.postConstructMethodCalled);
         assertTrue("@PreDestroy annoated method has been called already.", !te.preDestroyMethodCalled);
         bus.shutdown(true);
-        assertTrue("@PreDestroy annoated method has not been called.", te.preDestroyMethodCalled);
+        assertTrue("@PreDestroy annotated method has not been called.", te.preDestroyMethodCalled);
         
     }
 



Mime
View raw message