aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1067207 - in /aries/trunk: blueprint/blueprint-annotation-impl/ blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/ blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/ bl...
Date Fri, 04 Feb 2011 16:13:33 GMT
Author: timothyjward
Date: Fri Feb  4 16:13:32 2011
New Revision: 1067207

URL: http://svn.apache.org/viewvc?rev=1067207&view=rev
Log:
ARIES-567 - Add a common utility for safe unregistration

Added:
    aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/
    aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
    aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/util/
    aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
    aries/trunk/util/src/main/java/org/apache/aries/util/tracker/SingleServiceTracker.java
      - copied, changed from r1067146, aries/trunk/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java
Removed:
    aries/trunk/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java
Modified:
    aries/trunk/blueprint/blueprint-annotation-impl/pom.xml
    aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/Activator.java
    aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/CmManagedServiceFactory.java
    aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/ManagedObjectManager.java
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
    aries/trunk/jmx/jmx-blueprint-core/pom.xml
    aries/trunk/jmx/jmx-blueprint-core/src/main/java/org/apache/aries/jmx/blueprint/impl/BlueprintState.java
    aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java
    aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/GlobalPersistenceManager.java
    aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/CountingEntityManagerFactory.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
    aries/trunk/quiesce/quiesce-manager/pom.xml
    aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/Activator.java
    aries/trunk/transaction/pom.xml
    aries/trunk/transaction/transaction-manager/pom.xml
    aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/TransactionManagerService.java
    aries/trunk/transaction/transaction-wrappers/pom.xml
    aries/trunk/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/Activator.java
    aries/trunk/util/src/main/java/org/apache/aries/util/AriesFrameworkUtil.java
    aries/trunk/util/src/test/java/org/apache/aries/util/SingleServiceTrackerTest.java

Modified: aries/trunk/blueprint/blueprint-annotation-impl/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-annotation-impl/pom.xml?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-annotation-impl/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-annotation-impl/pom.xml Fri Feb  4 16:13:32 2011
@@ -57,6 +57,10 @@
           <artifactId>org.apache.aries.blueprint.annotation.api</artifactId>
       </dependency>
       <dependency>
+          <groupId>org.apache.aries</groupId>
+          <artifactId>org.apache.aries.util</artifactId>
+      </dependency>
+      <dependency>
           <groupId>org.osgi</groupId>
           <artifactId>org.osgi.core</artifactId>
           <scope>provided</scope>

Modified: aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/Activator.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/Activator.java
(original)
+++ aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/Activator.java
Fri Feb  4 16:13:32 2011
@@ -19,11 +19,12 @@ package org.apache.aries.blueprint.annot
 import java.util.Dictionary;
 import java.util.Hashtable;
 
+import org.apache.aries.blueprint.annotation.service.BlueprintAnnotationScanner;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
-import org.apache.aries.blueprint.annotation.service.BlueprintAnnotationScanner;
 
 public class Activator implements BundleActivator {
 
@@ -36,9 +37,7 @@ public class Activator implements Bundle
     }
 
     public void stop(BundleContext context) {
-        if (sr != null) {
-            sr.unregister();
-        }
+      AriesFrameworkUtil.safeUnregisterService(sr);
     }
    
 }

Modified: aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/CmManagedServiceFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/CmManagedServiceFactory.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/CmManagedServiceFactory.java
(original)
+++ aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/CmManagedServiceFactory.java
Fri Feb  4 16:13:32 2011
@@ -35,6 +35,7 @@ import org.apache.aries.blueprint.Servic
 import org.apache.aries.blueprint.container.ServiceListener;
 import org.apache.aries.blueprint.utils.JavaUtils;
 import org.apache.aries.blueprint.utils.ReflectionUtils;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -100,9 +101,7 @@ public class CmManagedServiceFactory {
     }
 
     public void destroy() {
-        if (registration != null) {
-            registration.unregister();
-        }
+        AriesFrameworkUtil.safeUnregisterService(registration);
         for (Map.Entry<ServiceRegistration, Object> entry : services.entrySet()) {
             destroy(entry.getValue(), entry.getKey(), BUNDLE_STOPPING);
         }
@@ -119,7 +118,7 @@ public class CmManagedServiceFactory {
             }
         }
         destroyComponent(component, code);
-        registration.unregister();
+        AriesFrameworkUtil.safeUnregisterService(registration);
     }
     
     public Map<ServiceRegistration, Object> getServiceMap() {

Modified: aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/ManagedObjectManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/ManagedObjectManager.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/ManagedObjectManager.java
(original)
+++ aries/trunk/blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/ManagedObjectManager.java
Fri Feb  4 16:13:32 2011
@@ -25,6 +25,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
@@ -60,7 +61,7 @@ public class ManagedObjectManager {
             reg.remove(cm);
             if (reg.isEmpty()) {
                 map.remove(key);
-                reg.getRegistration().unregister();
+                AriesFrameworkUtil.safeUnregisterService(reg.getRegistration());
             }
         }
     }

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
(original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
Fri Feb  4 16:13:32 2011
@@ -62,6 +62,7 @@ import org.apache.aries.blueprint.reflec
 import org.apache.aries.blueprint.utils.HeaderParser;
 import org.apache.aries.blueprint.utils.JavaUtils;
 import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -812,9 +813,7 @@ public class BlueprintContainerImpl impl
         if (timeoutFuture != null) {
             timeoutFuture.cancel(false);
         }
-        if (registration != null) {
-            registration.unregister();
-        }
+        AriesFrameworkUtil.safeUnregisterService(registration);
         if (handlerSet != null) {
             handlerSet.removeListener(this);
             handlerSet.destroy();
@@ -845,9 +844,7 @@ public class BlueprintContainerImpl impl
         if (timeoutFuture != null) {
             timeoutFuture.cancel(false);
         }
-        if (registration != null) {
-            registration.unregister();
-        }
+        AriesFrameworkUtil.safeUnregisterService(registration);
         if (handlerSet != null) {
             handlerSet.removeListener(this);
             handlerSet.destroy();

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
(original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
Fri Feb  4 16:13:32 2011
@@ -39,9 +39,10 @@ import org.apache.aries.blueprint.namesp
 import org.apache.aries.blueprint.utils.HeaderParser;
 import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
 import org.apache.aries.proxy.ProxyManager;
-import org.apache.aries.util.SingleServiceTracker;
-import org.apache.aries.util.SingleServiceTracker.SingleServiceListener;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.apache.aries.util.tracker.RecursiveBundleTracker;
+import org.apache.aries.util.tracker.SingleServiceTracker;
+import org.apache.aries.util.tracker.SingleServiceTracker.SingleServiceListener;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -154,10 +155,9 @@ public class BlueprintExtender implement
         	bt.close();
         }
         
-        parserServiceReg.unregister();
-        
-        if (quiesceParticipantReg != null) 
-          	quiesceParticipantReg.unregister();
+        AriesFrameworkUtil.safeUnregisterService(parserServiceReg);
+
+        AriesFrameworkUtil.safeUnregisterService(quiesceParticipantReg);
 
         // Orderly shutdown of containers
         while (!containers.isEmpty()) {

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
(original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
Fri Feb  4 16:13:32 2011
@@ -44,6 +44,7 @@ import org.apache.aries.blueprint.proxy.
 import org.apache.aries.blueprint.utils.JavaUtils;
 import org.apache.aries.blueprint.utils.ReflectionUtils;
 import org.apache.aries.proxy.InvocationHandlerWrapper;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkUtil;
@@ -197,9 +198,7 @@ public class ServiceRecipe extends Abstr
                     listener.unregister(service, registrationProperties);
                 }
             }
-            if (reg != null) {
-                reg.unregister();
-            }
+            AriesFrameworkUtil.safeUnregisterService(reg);
             
             registration.compareAndSet(reg, null);
         }

Modified: aries/trunk/jmx/jmx-blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-blueprint-core/pom.xml?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-blueprint-core/pom.xml (original)
+++ aries/trunk/jmx/jmx-blueprint-core/pom.xml Fri Feb  4 16:13:32 2011
@@ -50,6 +50,10 @@
             <artifactId>org.apache.aries.jmx.blueprint.api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries</groupId>
+            <artifactId>org.apache.aries.util</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>

Modified: aries/trunk/jmx/jmx-blueprint-core/src/main/java/org/apache/aries/jmx/blueprint/impl/BlueprintState.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-blueprint-core/src/main/java/org/apache/aries/jmx/blueprint/impl/BlueprintState.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-blueprint-core/src/main/java/org/apache/aries/jmx/blueprint/impl/BlueprintState.java
(original)
+++ aries/trunk/jmx/jmx-blueprint-core/src/main/java/org/apache/aries/jmx/blueprint/impl/BlueprintState.java
Fri Feb  4 16:13:32 2011
@@ -38,6 +38,7 @@ import javax.management.openmbean.Tabula
 
 import org.apache.aries.jmx.blueprint.BlueprintStateMBean;
 import org.apache.aries.jmx.blueprint.codec.OSGiBlueprintEvent;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.container.BlueprintEvent;
@@ -107,11 +108,8 @@ public class BlueprintState extends Noti
 
     public void postDeregister() {
         if (registrations.decrementAndGet() < 1) {
-            try {
-                listenerReg.unregister();
-            } catch(Exception e) {
-                // ignore
-            }
+            AriesFrameworkUtil.safeUnregisterService(listenerReg); 
+          
             if (eventDispatcher != null) {
                 eventDispatcher.shutdown(); 
             }

Modified: aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java (original)
+++ aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java Fri Feb
 4 16:13:32 2011
@@ -24,6 +24,7 @@ import java.util.logging.Logger;
 
 import javax.naming.spi.ObjectFactory;
 
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -54,7 +55,7 @@ public class Activator implements Bundle
     }
 
     public void stop(BundleContext context) {
-        reg.unregister();
+        AriesFrameworkUtil.safeUnregisterService(reg);
     }
 
 }

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java Fri Feb
 4 16:13:32 2011
@@ -23,8 +23,9 @@ import java.util.Hashtable;
 import javax.naming.spi.ObjectFactory;
 
 import org.apache.aries.proxy.ProxyManager;
-import org.apache.aries.util.SingleServiceTracker;
-import org.apache.aries.util.SingleServiceTracker.SingleServiceListener;
+import org.apache.aries.util.AriesFrameworkUtil;
+import org.apache.aries.util.tracker.SingleServiceTracker;
+import org.apache.aries.util.tracker.SingleServiceTracker.SingleServiceListener;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -62,8 +63,8 @@ public class Activator implements Bundle
     @Override
     public void stop(BundleContext context) {
       proxyManager.close();
-      if (osgiUrlReg != null) osgiUrlReg.unregister();
-      if (blueprintUrlReg != null) blueprintUrlReg.unregister();
+      AriesFrameworkUtil.safeUnregisterService(osgiUrlReg);
+      AriesFrameworkUtil.safeUnregisterService(blueprintUrlReg);
     }
   
 
@@ -79,7 +80,7 @@ public class Activator implements Bundle
   @Override
   public void serviceLost() 
   {
-    if (osgiUrlReg != null) osgiUrlReg.unregister();
+    AriesFrameworkUtil.safeUnregisterService(osgiUrlReg);
     osgiUrlReg = null;
   }
 

Modified: aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/GlobalPersistenceManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/GlobalPersistenceManager.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/GlobalPersistenceManager.java
(original)
+++ aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/GlobalPersistenceManager.java
Fri Feb  4 16:13:32 2011
@@ -29,6 +29,7 @@ import java.util.Map.Entry;
 import org.apache.aries.jpa.container.context.PersistenceContextProvider;
 import org.apache.aries.jpa.container.context.transaction.impl.DestroyCallback;
 import org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -189,7 +190,7 @@ public class GlobalPersistenceManager im
   public void quiesceBundle(Bundle bundleToQuiesce, final DestroyCallback callback) {
     //If this is our bundle then get all the managers to clean up everything
     if(bundleToQuiesce == bundle) {
-      unregister(pcpReg);
+      AriesFrameworkUtil.safeUnregisterService(pcpReg);
       pcpReg = null;
       final Collection<Entry<Bundle, PersistenceContextManager>> mgrs = new ArrayList<Entry<Bundle,
PersistenceContextManager>>();
       synchronized (this) {
@@ -255,8 +256,8 @@ public class GlobalPersistenceManager im
 
   public void stop(BundleContext context) throws Exception {
     //Clean up
-    unregister(pcpReg);
-    unregister(quiesceReg);
+    AriesFrameworkUtil.safeUnregisterService(pcpReg);
+    AriesFrameworkUtil.safeUnregisterService(quiesceReg);
     if(quiesceTidyUp != null)
       quiesceTidyUp.callback();
     Collection<PersistenceContextManager> mgrs = new ArrayList<PersistenceContextManager>();
@@ -269,19 +270,6 @@ public class GlobalPersistenceManager im
     
     registry.close();
   }
-
-  /**
-   * Clean up a registration without throwing an exception
-   * @param reg
-   */
-  private void unregister(ServiceRegistration reg) {
-    if(reg != null)
-      try {
-        reg.unregister();
-      } catch (IllegalStateException ise) {
-        //we don't care
-      }
-  }
   
   public Bundle getBundle() {
     return bundle;

Modified: aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
(original)
+++ aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
Fri Feb  4 16:13:32 2011
@@ -36,6 +36,7 @@ import org.apache.aries.jpa.container.Pe
 import org.apache.aries.jpa.container.context.PersistenceContextProvider;
 import org.apache.aries.jpa.container.context.transaction.impl.DestroyCallback;
 import org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -103,11 +104,7 @@ public class PersistenceContextManager e
   public void close() {
     super.close();
     for (ServiceRegistration reg : entityManagerRegistrations.values()) {
-      try {
-        reg.unregister();
-      } catch (IllegalStateException ise) {
-        //This is no worry, the framework has done our job for us
-      }
+      AriesFrameworkUtil.safeUnregisterService(reg);
     }
   }
 
@@ -325,7 +322,7 @@ public class PersistenceContextManager e
       }
       //If we were live-locked then unregister the registration here
       if(recoverFromLiveLock)
-        reg.unregister();
+        AriesFrameworkUtil.safeUnregisterService(reg);
     }
   }
   
@@ -384,7 +381,7 @@ public class PersistenceContextManager e
     }
     //If we found the registration then unregister it outside the synchronized.
     if (reg != null) {
-      reg.unregister();
+      AriesFrameworkUtil.safeUnregisterService(reg);
     }
   }
 

Added: aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java?rev=1067207&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
(added)
+++ aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
Fri Feb  4 16:13:32 2011
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.aries.util;
+
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * A fake class for testing
+ */
+public final class AriesFrameworkUtil 
+{
+  
+  /**
+   * Safely unregister the supplied ServiceRegistration, for when you don't
+   * care about the potential IllegalStateException and don't want
+   * it to run wild through your code
+   * 
+   * @param reg The {@link ServiceRegistration}, may be null
+   */
+  public static void safeUnregisterService(ServiceRegistration reg) 
+  {
+    if(reg != null) {
+      try {
+        reg.unregister();
+      } catch (IllegalStateException e) {
+        //This can be safely ignored
+      }
+    }
+  }
+}

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/CountingEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/CountingEntityManagerFactory.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/CountingEntityManagerFactory.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/CountingEntityManagerFactory.java
Fri Feb  4 16:13:32 2011
@@ -31,6 +31,7 @@ import javax.persistence.criteria.Criter
 import javax.persistence.metamodel.Metamodel;
 
 import org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.NamedCallback;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.ServiceRegistration;
 
 /**
@@ -100,7 +101,7 @@ public class CountingEntityManagerFactor
     this.reg.compareAndSet(null, reg);
     this.callback.compareAndSet(null, callback);
     if(count.get() == 0) {
-      PersistenceBundleManager.unregister(this.reg.getAndSet(null));
+      AriesFrameworkUtil.safeUnregisterService(this.reg.getAndSet(null));
       this.callback.set(null);
       callback.callback(name);
     }
@@ -111,7 +112,7 @@ public class CountingEntityManagerFactor
     if(count.decrementAndGet() == 0) {
       NamedCallback c = callback.getAndSet(null);
       if(c != null) {
-        PersistenceBundleManager.unregister(reg.getAndSet(null));
+        AriesFrameworkUtil.safeUnregisterService(reg.getAndSet(null));
         c.callback(name);
       }
     }

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
Fri Feb  4 16:13:32 2011
@@ -36,6 +36,7 @@ import javax.persistence.spi.Persistence
 import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
 import org.apache.aries.jpa.container.PersistenceUnitConstants;
 import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -177,12 +178,7 @@ public class EntityManagerFactoryManager
     //If we have registrations then unregister them
     if(registrations != null) {
       for(Entry<String, ServiceRegistration> entry : registrations.entrySet()) {
-        try {
-          entry.getValue().unregister();
-        } catch (Exception e) {
-          _logger.error("There was an error unregistering the EntityManagerFactory services
for bundle " 
-              + bundle.getSymbolicName() + "_" + bundle.getVersion() , e);
-        }
+        AriesFrameworkUtil.safeUnregisterService(entry.getValue());
         emfs.get(entry.getKey()).clearQuiesce();
       }
       // remember to set registrations to be null

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
Fri Feb  4 16:13:32 2011
@@ -45,6 +45,7 @@ import org.apache.aries.jpa.container.pa
 import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParserException;
 import org.apache.aries.jpa.container.parsing.impl.PersistenceDescriptorParserImpl;
 import org.apache.aries.jpa.container.unit.impl.ManagedPersistenceUnitInfoFactoryImpl;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.apache.aries.util.VersionRange;
 import org.apache.aries.util.tracker.RecursiveBundleTracker;
 import org.osgi.framework.Bundle;
@@ -636,25 +637,12 @@ public class PersistenceBundleManager im
 
   public void stop(BundleContext context) throws Exception {
     close();
-    unregister(parserReg);
-    unregister(quiesceReg);
+    AriesFrameworkUtil.safeUnregisterService(parserReg);
+    AriesFrameworkUtil.safeUnregisterService(quiesceReg);
     if(quiesceParticipant != null)
       quiesceParticipant.callback();
   }
   
-  /**
-   * Clean up a registration without throwing an exception
-   * @param reg
-   */
-  static void unregister(ServiceRegistration reg) {
-    if(reg != null)
-      try {
-        reg.unregister();
-      } catch (IllegalStateException ise) {
-        //we don't care
-      }
-  }
-  
   public BundleContext getCtx() {
     return ctx;
   }
@@ -665,7 +653,7 @@ public class PersistenceBundleManager im
     
     if(thisBundle) {
       quiesce.compareAndSet(false, true);
-      unregister(quiesceReg);
+      AriesFrameworkUtil.safeUnregisterService(quiesceReg);
     }
     
     Collection<EntityManagerFactoryManager> toDestroyNow = new ArrayList<EntityManagerFactoryManager>();

Added: aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java?rev=1067207&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
(added)
+++ aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
Fri Feb  4 16:13:32 2011
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.aries.util;
+
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * A fake class for testing
+ */
+public final class AriesFrameworkUtil 
+{
+  
+  /**
+   * Safely unregister the supplied ServiceRegistration, for when you don't
+   * care about the potential IllegalStateException and don't want
+   * it to run wild through your code
+   * 
+   * @param reg The {@link ServiceRegistration}, may be null
+   */
+  public static void safeUnregisterService(ServiceRegistration reg) 
+  {
+    if(reg != null) {
+      try {
+        reg.unregister();
+      } catch (IllegalStateException e) {
+        //This can be safely ignored
+      }
+    }
+  }
+}

Modified: aries/trunk/quiesce/quiesce-manager/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/quiesce/quiesce-manager/pom.xml?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/quiesce/quiesce-manager/pom.xml (original)
+++ aries/trunk/quiesce/quiesce-manager/pom.xml Fri Feb  4 16:13:32 2011
@@ -56,6 +56,10 @@
             <artifactId>org.apache.aries.quiesce.api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries</groupId>
+            <artifactId>org.apache.aries.util</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>

Modified: aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/Activator.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/Activator.java
(original)
+++ aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/Activator.java
Fri Feb  4 16:13:32 2011
@@ -17,6 +17,7 @@
 package org.apache.aries.quiesce.manager.impl;
 
 import org.apache.aries.quiesce.manager.QuiesceManager;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -30,10 +31,8 @@ public class Activator implements Bundle
         serviceReg = bundleContext.registerService(QuiesceManager.class.getName(), manager,
null);
     }
 
-
     public void stop(BundleContext bundleContext) throws Exception {
-    	if (serviceReg != null)
-    		serviceReg.unregister();
+      AriesFrameworkUtil.safeUnregisterService(serviceReg);
     }
 
 }
\ No newline at end of file

Modified: aries/trunk/transaction/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/pom.xml?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/transaction/pom.xml (original)
+++ aries/trunk/transaction/pom.xml Fri Feb  4 16:13:32 2011
@@ -81,6 +81,11 @@
                 <version>1.1.1</version>
             </dependency>
             <dependency>
+                <groupId>org.apache.aries</groupId>
+                <artifactId>org.apache.aries.util</artifactId>
+                <version>0.4-SNAPSHOT</version> 
+            </dependency>
+            <dependency>
                 <groupId>org.apache.aries.blueprint</groupId>
                 <artifactId>org.apache.aries.blueprint</artifactId>
                 <version>0.4-SNAPSHOT</version>

Modified: aries/trunk/transaction/transaction-manager/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-manager/pom.xml?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-manager/pom.xml (original)
+++ aries/trunk/transaction/transaction-manager/pom.xml Fri Feb  4 16:13:32 2011
@@ -66,6 +66,11 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.apache.aries</groupId>
+            <artifactId>org.apache.aries.util</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>

Modified: aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/TransactionManagerService.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/TransactionManagerService.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/TransactionManagerService.java
(original)
+++ aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/TransactionManagerService.java
Fri Feb  4 16:13:32 2011
@@ -31,6 +31,7 @@ import javax.transaction.UserTransaction
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ConfigurationException;
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
 import org.apache.geronimo.transaction.manager.TransactionLog;
 import org.apache.geronimo.transaction.manager.XidFactory;
@@ -166,9 +167,8 @@ public class TransactionManagerService {
     }
 
     public void close() throws Exception {
-        if (serviceRegistration != null) {
-            serviceRegistration.unregister();
-        }
+        AriesFrameworkUtil.safeUnregisterService(serviceRegistration);
+      
         if (transactionLog instanceof HOWLLog) {
             ((HOWLLog) transactionLog).doStop();
         }

Modified: aries/trunk/transaction/transaction-wrappers/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-wrappers/pom.xml?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-wrappers/pom.xml (original)
+++ aries/trunk/transaction/transaction-wrappers/pom.xml Fri Feb  4 16:13:32 2011
@@ -47,6 +47,10 @@
             <artifactId>org.apache.aries.transaction.manager</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries</groupId>
+            <artifactId>org.apache.aries.util</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>

Modified: aries/trunk/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/Activator.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/Activator.java
(original)
+++ aries/trunk/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/Activator.java
Fri Feb  4 16:13:32 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.transaction.jdbc;
 
+import org.apache.aries.util.AriesFrameworkUtil;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
@@ -105,7 +106,7 @@ public class Activator implements Bundle
 
   public void removedService(ServiceReference ref, Object service)
   {
-    ((ServiceRegistration)service).unregister();
+    AriesFrameworkUtil.safeUnregisterService((ServiceRegistration)service);
   }
 
   public void serviceChanged(ServiceEvent event)

Modified: aries/trunk/util/src/main/java/org/apache/aries/util/AriesFrameworkUtil.java
URL: http://svn.apache.org/viewvc/aries/trunk/util/src/main/java/org/apache/aries/util/AriesFrameworkUtil.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/util/src/main/java/org/apache/aries/util/AriesFrameworkUtil.java (original)
+++ aries/trunk/util/src/main/java/org/apache/aries/util/AriesFrameworkUtil.java Fri Feb 
4 16:13:32 2011
@@ -24,6 +24,7 @@ import org.apache.aries.util.internal.Fe
 import org.apache.aries.util.internal.FrameworkUtilWorker;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceRegistration;
 
 public final class AriesFrameworkUtil 
 {
@@ -91,4 +92,22 @@ public final class AriesFrameworkUtil 
     }
     return worker.getClassLoader(b);
   }
+  
+  /**
+   * Safely unregister the supplied ServiceRegistration, for when you don't
+   * care about the potential IllegalStateException and don't want
+   * it to run wild through your code
+   * 
+   * @param reg The {@link ServiceRegistration}, may be null
+   */
+  public static void safeUnregisterService(ServiceRegistration reg) 
+  {
+    if(reg != null) {
+      try {
+        reg.unregister();
+      } catch (IllegalStateException e) {
+        //This can be safely ignored
+      }
+    }
+  }
 }
\ No newline at end of file

Copied: aries/trunk/util/src/main/java/org/apache/aries/util/tracker/SingleServiceTracker.java
(from r1067146, aries/trunk/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java)
URL: http://svn.apache.org/viewvc/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/SingleServiceTracker.java?p2=aries/trunk/util/src/main/java/org/apache/aries/util/tracker/SingleServiceTracker.java&p1=aries/trunk/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java&r1=1067146&r2=1067207&rev=1067207&view=diff
==============================================================================
--- aries/trunk/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java (original)
+++ aries/trunk/util/src/main/java/org/apache/aries/util/tracker/SingleServiceTracker.java
Fri Feb  4 16:13:32 2011
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.util;
+package org.apache.aries.util.tracker;
 
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;

Modified: aries/trunk/util/src/test/java/org/apache/aries/util/SingleServiceTrackerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/util/src/test/java/org/apache/aries/util/SingleServiceTrackerTest.java?rev=1067207&r1=1067206&r2=1067207&view=diff
==============================================================================
--- aries/trunk/util/src/test/java/org/apache/aries/util/SingleServiceTrackerTest.java (original)
+++ aries/trunk/util/src/test/java/org/apache/aries/util/SingleServiceTrackerTest.java Fri
Feb  4 16:13:32 2011
@@ -21,7 +21,8 @@ package org.apache.aries.util;
 import org.apache.aries.mocks.BundleContextMock;
 import org.apache.aries.unittest.mocks.MethodCall;
 import org.apache.aries.unittest.mocks.Skeleton;
-import org.apache.aries.util.SingleServiceTracker.SingleServiceListener;
+import org.apache.aries.util.tracker.SingleServiceTracker;
+import org.apache.aries.util.tracker.SingleServiceTracker.SingleServiceListener;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;



Mime
View raw message