aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1762489 - /aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/internal/Activator.java
Date Tue, 27 Sep 2016 14:05:52 GMT
Author: gnodet
Date: Tue Sep 27 14:05:52 2016
New Revision: 1762489

URL: http://svn.apache.org/viewvc?rev=1762489&view=rev
Log:
[ARIES-1621] Aries Transaction Manager is published to the OSGi registry then immediately
re-published

Modified:
    aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/internal/Activator.java

Modified: aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/internal/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/internal/Activator.java?rev=1762489&r1=1762488&r2=1762489&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/internal/Activator.java
(original)
+++ aries/trunk/transaction/transaction-manager/src/main/java/org/apache/aries/transaction/internal/Activator.java
Tue Sep 27 14:05:52 2016
@@ -17,13 +17,15 @@
 package org.apache.aries.transaction.internal;
 
 import java.util.Dictionary;
+import java.util.Enumeration;
 import java.util.Hashtable;
 
-import org.apache.aries.transaction.internal.NLS;
-import org.apache.aries.transaction.internal.TransactionManagerService;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.slf4j.Logger;
@@ -39,14 +41,36 @@ public class Activator implements Bundle
 
     private BundleContext bundleContext;
     private TransactionManagerService manager;
+    private Dictionary properties;
 
     public void start(BundleContext bundleContext) throws Exception {
         this.bundleContext = bundleContext;
         // Make sure TransactionManager comes up even if no config admin is installed
-        updated(null);
+        Dictionary properties = getInitialConfig();
+        updated(properties);
         bundleContext.registerService(ManagedService.class.getName(), this, getProps());
     }
 
+    private Dictionary<String, Object> getInitialConfig() {
+        try {
+            ServiceReference<ConfigurationAdmin> ref = bundleContext.getServiceReference(ConfigurationAdmin.class);
+            if (ref != null) {
+                ConfigurationAdmin configurationAdmin = bundleContext.getService(ref);
+                if (configurationAdmin != null) {
+                    try {
+                        Configuration config = configurationAdmin.getConfiguration(PID);
+                        return config.getProperties();
+                    } finally {
+                        bundleContext.ungetService(ref);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            // Ignore
+        }
+        return null;
+    }
+
     private Dictionary<String, Object> getProps() {
         Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put(Constants.SERVICE_PID, PID);
@@ -61,12 +85,35 @@ public class Activator implements Bundle
         if (properties == null) {
             properties = getProps();
         }
-        deleted();
-        manager = new TransactionManagerService(PID, properties, bundleContext);
-        try {
-            manager.start();
-        } catch (Exception e) {
-            log.error(NLS.MESSAGES.getMessage("exception.tx.manager.start"), e);
+        if (!equals(this.properties, properties)) {
+            deleted();
+            this.properties = properties;
+            manager = new TransactionManagerService(PID, properties, bundleContext);
+            try {
+                manager.start();
+            } catch (Exception e) {
+                log.error(NLS.MESSAGES.getMessage("exception.tx.manager.start"), e);
+            }
+        }
+    }
+
+    private boolean equals(Dictionary<String, Object> d1, Dictionary<String, Object>
d2) {
+        if (d1 == d2) {
+            return true;
+        } else if (d1 == null ^ d2 == null) {
+            return false;
+        } else if (d1.size() != d2.size()) {
+            return false;
+        } else {
+            for (Enumeration<String> e1 = d1.keys(); e1.hasMoreElements();) {
+                String key = e1.nextElement();
+                Object v1 = d1.get(key);
+                Object v2 = d2.get(key);
+                if (v1 != v2 && (v2 == null || !v2.equals(v1))) {
+                    return false;
+                }
+            }
+            return true;
         }
     }
 



Mime
View raw message