servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r707354 - in /servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator: Activator.java OsgiLocator.java
Date Thu, 23 Oct 2008 11:45:56 GMT
Author: gnodet
Date: Thu Oct 23 04:45:55 2008
New Revision: 707354

URL: http://svn.apache.org/viewvc?rev=707354&view=rev
Log:
Add debug logging to the specs' osgi stuff

Modified:
    servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/Activator.java
    servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java

Modified: servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/Activator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/Activator.java?rev=707354&r1=707353&r2=707354&view=diff
==============================================================================
--- servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/Activator.java
(original)
+++ servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/Activator.java
Thu Oct 23 04:45:55 2008
@@ -34,33 +34,60 @@
 
 public class Activator implements BundleActivator, SynchronousBundleListener {
 
-    private BundleContext bundleContext;
+    private static boolean debug = false;
+
     private ConcurrentMap<Long, Map<String, Callable<Class>>> factories
= new ConcurrentHashMap<Long, Map<String, Callable<Class>>>();
 
+    private BundleContext bundleContext;
+
+    static {
+        try {
+            String prop = System.getProperty("org.apache.servicemix.specs.debug");
+            debug = prop != null && !"false".equals(prop);
+        } catch (Throwable t) { }
+    }
+
+    /**
+     * <p>Output debugging messages.</p>
+     *
+     * @param msg <code>String</code> to print to <code>stderr</code>.
+     */
+    private void debugPrintln(String msg) {
+        if (debug) {
+            System.err.println("Spec(" + bundleContext.getBundle().getBundleId() + "): "
+ msg);
+        }
+    }
+
     public synchronized void start(BundleContext bundleContext) throws Exception {
         this.bundleContext = bundleContext;
+        debugPrintln("activating");
         bundleContext.addBundleListener(this);
         for (Bundle bundle : bundleContext.getBundles()) {
             register(bundle);
         }
+        debugPrintln("activated");
     }
 
     public synchronized void stop(BundleContext bundleContext) throws Exception {
+        debugPrintln("deactivating");
+        bundleContext.removeBundleListener(this);
         while (!factories.isEmpty()) {
             unregister(factories.keySet().iterator().next());
         }
+        debugPrintln("deactivated");
         this.bundleContext = null;
     }
 
     public void bundleChanged(BundleEvent event) {
         if (event.getType() == BundleEvent.RESOLVED) {
             register(event.getBundle());
-        } else if (event.getType() == BundleEvent.UNRESOLVED) {
+        } else if (event.getType() == BundleEvent.UNRESOLVED || event.getType() == BundleEvent.UNINSTALLED)
{
             unregister(event.getBundle().getBundleId());
         }
     }
 
     protected void register(final Bundle bundle) {
+        debugPrintln("checking bundle " + bundle.getBundleId());
         Map<String, Callable<Class>> map = factories.get(bundle.getBundleId());
         Enumeration e = bundle.findEntries("META-INF/services/", "*", false);
         if (e != null) {
@@ -77,16 +104,27 @@
                 }
                 map.put(factoryId, new Callable<Class>() {
                     public Class call() throws Exception {
-                        BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(),
"UTF-8"));
-                        String factoryClassName = br.readLine();
-                        br.close();
-                        return bundle.loadClass(factoryClassName);
+                        try {
+                            debugPrintln("creating factory for key: " + factoryId);
+                            BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(),
"UTF-8"));
+                            String factoryClassName = br.readLine();
+                            br.close();
+                            debugPrintln("factory implementation: " + factoryClassName);
+                            return bundle.loadClass(factoryClassName);
+                        } catch (Exception e) {
+                            debugPrintln("exception caught while creating factory: " + e);
+                            throw e;
+                        } catch (Error e) {
+                            debugPrintln("error caught while creating factory: " + e);
+                            throw e;
+                        }
                     }
                 });
             }
         }
         if (map != null) {
             for (Map.Entry<String, Callable<Class>> entry : map.entrySet()) {
+                debugPrintln("registering service for key " + entry.getKey());
                 OsgiLocator.register(entry.getKey(), entry.getValue());
             }
         }
@@ -96,6 +134,7 @@
         Map<String, Callable<Class>> map = factories.remove(bundleId);
         if (map != null) {
             for (Map.Entry<String, Callable<Class>> entry : map.entrySet()) {
+                debugPrintln("unregistering service for key " + entry.getKey());
                 OsgiLocator.unregister(entry.getKey(), entry.getValue());
             }
         }

Modified: servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java?rev=707354&r1=707353&r2=707354&view=diff
==============================================================================
--- servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
(original)
+++ servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
Thu Oct 23 04:45:55 2008
@@ -26,6 +26,9 @@
 
     private static Map<String, List<Callable<Class>>> factories;
 
+    private OsgiLocator() {
+    }
+
     public static synchronized void unregister(String id, Callable<Class> factory)
{
         if (factories != null) {
             List<Callable<Class>> l = factories.get(id);



Mime
View raw message