james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1142618 - /james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/osgi/AbstractServiceTracker.java
Date Mon, 04 Jul 2011 10:56:40 GMT
Author: norman
Date: Mon Jul  4 10:56:40 2011
New Revision: 1142618

URL: http://svn.apache.org/viewvc?rev=1142618&view=rev
Log:
Make sure we keep track of all ServiceReferences. See JAMES-835

Modified:
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/osgi/AbstractServiceTracker.java

Modified: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/osgi/AbstractServiceTracker.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/osgi/AbstractServiceTracker.java?rev=1142618&r1=1142617&r2=1142618&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/osgi/AbstractServiceTracker.java
(original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/osgi/AbstractServiceTracker.java
Mon Jul  4 10:56:40 2011
@@ -19,7 +19,9 @@
 package org.apache.james.container.spring.osgi;
 
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.List;
 import java.util.Properties;
 
 import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -53,7 +55,7 @@ public abstract class AbstractServiceTra
     private BundleContext context;
     private BeanFactory factory;
     private String configuredClass;
-    private ServiceRegistration reg;
+    private final List<ServiceRegistration> reg = new ArrayList<ServiceRegistration>();
 
     @Override
     public void setBeanFactory(BeanFactory factory) throws BeansException {
@@ -105,18 +107,24 @@ public abstract class AbstractServiceTra
                         registry.registerBeanDefinition(getComponentName(), def);
 
                         // register the bean as service in the BundleContext
-                        reg = b.getBundleContext().registerService(clazz.getName(), factory.getBean(getComponentName(),
clazz), p);
+                        reg.add(b.getBundleContext().registerService(clazz.getName(), factory.getBean(getComponentName(),
clazz), p));
                     }
                 }
             }
             break;
         case BundleEvent.STOPPED:
             if (reg != null) {
-
-                // Check if we need to unregister the service
-                if (b.equals(reg.getReference().getBundle())) {
-                    reg.unregister();
+                List<ServiceRegistration> removed = new ArrayList<ServiceRegistration>();
+                for (int i = 0; i < reg.size(); i++) {
+                    ServiceRegistration sr = reg.get(i);
+                    // Check if we need to unregister the service
+                    if (b.equals(sr.getReference().getBundle())) {
+                        sr.unregister();
+                        removed.add(sr);
+                    } 
                 }
+                reg.removeAll(removed);
+               
             }
             break;
         default:
@@ -132,7 +140,9 @@ public abstract class AbstractServiceTra
 
         // Get the configuration for the class
         configuredClass = config.getString("[@class]");
-        context.addBundleListener(this);
+        if (context != null) {
+            context.addBundleListener(this);
+        }
     }
 
     @Override



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message