You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2010/12/23 16:49:28 UTC

svn commit: r1052302 - in /incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook: SpiFly/src/org/apache/aries/spifly/ SpiFlyTests/src/org/apache/aries/spifly/

Author: davidb
Date: Thu Dec 23 15:49:27 2010
New Revision: 1052302

URL: http://svn.apache.org/viewvc?rev=1052302&view=rev
Log:
Added some comments.

Modified:
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/MultiDelegationClassloader.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/TCCLSetterVisitor.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/WeavingData.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java?rev=1052302&r1=1052301&r2=1052302&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Activator.java Thu Dec 23 15:49:27 2010
@@ -42,13 +42,14 @@ import org.osgi.util.tracker.BundleTrack
 import org.osgi.util.tracker.ServiceTracker;
 
 public class Activator implements BundleActivator {
+    // Provide static access to this activator. The bundle must therefore be a singleton.
     static Activator activator;
 
     private BundleContext bundleContext;
     private ServiceRegistration<WeavingHook> weavingHookService;
-    private LogServiceTracker lst;
+    private LogServiceTracker logServiceTracker;
     private List<LogService> logServices = new CopyOnWriteArrayList<LogService>();
-    private BundleTracker<List<ServiceRegistration<?>>> bt;
+    private BundleTracker<List<ServiceRegistration<?>>> bundleTracker;
 
     private final ConcurrentMap<String, SortedMap<Long, Bundle>> registeredProviders = 
             new ConcurrentHashMap<String, SortedMap<Long, Bundle>>();
@@ -59,25 +60,25 @@ public class Activator implements Bundle
     public synchronized void start(BundleContext context) throws Exception {
         bundleContext = context;
         
-        lst = new LogServiceTracker(context);
-        lst.open();
+        logServiceTracker = new LogServiceTracker(context);
+        logServiceTracker.open();
 
         WeavingHook wh = new ClientWeavingHook(context);
         weavingHookService = context.registerService(WeavingHook.class, wh,
                 null);
 
-        bt = new BundleTracker<List<ServiceRegistration<?>>>(context,
+        bundleTracker = new BundleTracker<List<ServiceRegistration<?>>>(context,
                 Bundle.ACTIVE, new ProviderBundleTrackerCustomizer(this, context.getBundle()));
-        bt.open();
+        bundleTracker.open();
         
         activator = this;
     }
 
     public synchronized void stop(BundleContext context) throws Exception {
         activator = null;
-        bt.close();
+        bundleTracker.close();
         weavingHookService.unregister();
-        lst.close();
+        logServiceTracker.close();
     }
 
     void log(int level, String message) {
@@ -96,24 +97,6 @@ public class Activator implements Bundle
         }
     }
 
-    private class LogServiceTracker extends ServiceTracker<LogService, LogService> {
-        public LogServiceTracker(BundleContext context) {
-            super(context, LogService.class, null);
-        }
-
-        public LogService addingService(ServiceReference<LogService> reference) {
-            LogService svc = super.addingService(reference);
-            if (svc != null)
-                logServices.add(svc);
-            return svc;
-        }
-
-        @Override
-        public void removedService(ServiceReference<LogService> reference, LogService service) {
-            logServices.remove(service);
-        }        
-    }
-
     public void registerProviderBundle(String registrationClassName, Bundle bundle) {        
         registeredProviders.putIfAbsent(registrationClassName, Collections.synchronizedSortedMap(new TreeMap<Long, Bundle>()));
         SortedMap<Long, Bundle> map = registeredProviders.get(registrationClassName);
@@ -139,6 +122,7 @@ public class Activator implements Bundle
             Map<Pair<Integer, String>, String> args) {
         Map<ConsumerRestriction, List<BundleDescriptor>> restrictions = consumerRestrictions.get(consumer);
         if (restrictions == null) {
+            // Null means: no restrictions
             return null;
         }
         
@@ -148,6 +132,7 @@ public class Activator implements Bundle
             }
         }
         
+        // Empty collection: nothing matches
         return Collections.emptySet();
     }
 
@@ -170,4 +155,22 @@ public class Activator implements Bundle
     }
 
     // TODO unRegisterConsumerBundle();
+    
+    private class LogServiceTracker extends ServiceTracker<LogService, LogService> {
+        public LogServiceTracker(BundleContext context) {
+            super(context, LogService.class, null);
+        }
+
+        public LogService addingService(ServiceReference<LogService> reference) {
+            LogService svc = super.addingService(reference);
+            if (svc != null)
+                logServices.add(svc);
+            return svc;
+        }
+
+        @Override
+        public void removedService(ServiceReference<LogService> reference, LogService service) {
+            logServices.remove(service);
+        }        
+    }
 }

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/MultiDelegationClassloader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/MultiDelegationClassloader.java?rev=1052302&r1=1052301&r2=1052302&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/MultiDelegationClassloader.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/MultiDelegationClassloader.java Thu Dec 23 15:49:27 2010
@@ -26,6 +26,12 @@ import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
 
+/** A classloader that delegates to a number of other classloaders.
+ * This classloader can be used if a single classloader is needed that has
+ * vibisility of a number of other classloaders. For example if a Thread Context
+ * Classloader is needed that has visibility of a number of bundles so that 
+ * ServiceLoader.load() can find all the services provided by these bundles.
+ */
 public class MultiDelegationClassloader extends ClassLoader {
     private final ClassLoader[] delegates;
     

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java?rev=1052302&r1=1052301&r2=1052302&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java Thu Dec 23 15:49:27 2010
@@ -18,6 +18,9 @@
  */
 package org.apache.aries.spifly;
 
+/**
+ * A simple holder object for a pair of objects.
+ */
 public class Pair <A, B> {
     private final A left;
     private final B right;

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java?rev=1052302&r1=1052301&r2=1052302&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java Thu Dec 23 15:49:27 2010
@@ -33,6 +33,9 @@ import org.osgi.framework.ServiceRegistr
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
 
+/**
+ * Listens for new bundles being installed and registers them as service providers if applicable.
+ */
 public class ProviderBundleTrackerCustomizer implements BundleTrackerCustomizer<List<ServiceRegistration<?>>> {
     final Activator activator;
     final Bundle spiBundle;
@@ -40,8 +43,7 @@ public class ProviderBundleTrackerCustom
     public ProviderBundleTrackerCustomizer(Activator a, Bundle b) {
         activator = a;
         spiBundle = b;
-        
-        
+                
         // TODO handle pre-existing bundles.
     }
 

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/TCCLSetterVisitor.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/TCCLSetterVisitor.java?rev=1052302&r1=1052301&r2=1052302&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/TCCLSetterVisitor.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/TCCLSetterVisitor.java Thu Dec 23 15:49:27 2010
@@ -30,7 +30,7 @@ import org.objectweb.asm.Type;
 
 /**
  * This class implements an ASM ClassVisitor which puts the appropriate ThreadContextClassloader
- * calls around applicable method invocations. 
+ * calls around applicable method invocations. It does the actual bytecode weaving.
  */
 public class TCCLSetterVisitor extends ClassAdapter implements ClassVisitor, Opcodes {
     private static final String GENERATED_METHOD_NAME = "$$FCCL$$";

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/WeavingData.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/WeavingData.java?rev=1052302&r1=1052301&r2=1052302&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/WeavingData.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/WeavingData.java Thu Dec 23 15:49:27 2010
@@ -20,12 +20,21 @@ package org.apache.aries.spifly;
 
 import java.util.Arrays;
 
-
+/** Contains information needed for the byte code weaver.
+ */
 public class WeavingData {
     private final String className;
     private final String methodName;
     private final String[] argClasses;
-    
+
+    /**
+     * Constructor.
+     * @param className The class name of the call that needs to be woven.
+     * @param methodName The method name of the call that needs to be woven.
+     * @param argClasses The overload (class names of the signature) of the call
+     * that needs to be woven. If <code>null</code> then all overloads of the method
+     * need to be woven.
+     */
     public WeavingData(String className, String methodName, String[] argClasses) {
         this.className = className;
         this.methodName = methodName;

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java?rev=1052302&r1=1052301&r2=1052302&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java Thu Dec 23 15:49:27 2010
@@ -508,6 +508,7 @@ public class ClientWeavingHookTest {
         Bundle testBundle = ((BundleReference) getClass().getClassLoader()).getBundle();
         
         Set<String> resources = new HashSet<String>(); // findEntries happens to sometimes return duplicates in Eclipse
+        // This findEntries call is quite slow, can we do something that's a bit faster?
         Enumeration<URL> entries = testBundle.findEntries("/", null, true);
         for (URL entry : Collections.list(entries)) {
             String s = entry.toExternalForm();