[jboss-cvs] JBossAS SVN: r102661 - in projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment: internal and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Mar 20 03:11:00 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-20 03:10:59 -0400 (Sat, 20 Mar 2010)
New Revision: 102661

Modified:
   projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
   projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
Log:
Remove dependency on compendium

Modified: projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java	2010-03-20 06:12:15 UTC (rev 102660)
+++ projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java	2010-03-20 07:10:59 UTC (rev 102661)
@@ -35,8 +35,11 @@
 import org.jboss.osgi.spi.util.ConstantsHelper;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * A basic service that manages bundle lifecycle interceptors.
@@ -44,50 +47,55 @@
  * @author thomas.diesler at jboss.com
  * @since 15-Oct-2009
  */
-public abstract class AbstractLifecycleInterceptorService implements LifecycleInterceptorService 
+public abstract class AbstractLifecycleInterceptorService implements LifecycleInterceptorService, ServiceListener
 {
    // Provide logging
    private static final Logger log = Logger.getLogger(AbstractLifecycleInterceptorService.class);
 
    // The system bundle context
    private BundleContext context;
-   
+
    // The interceptor chain
    private List<LifecycleInterceptor> interceptorChain = new ArrayList<LifecycleInterceptor>();
-   
+
    protected AbstractLifecycleInterceptorService(BundleContext context)
    {
       if (context == null)
          throw new IllegalStateException("Null context");
       this.context = context;
-      
-      // Track the LifecycleInterceptor services
-      ServiceTracker tracker = new ServiceTracker(context, LifecycleInterceptor.class.getName(), null)
+
+      String filter = "(" + Constants.OBJECTCLASS + "=" + LifecycleInterceptor.class.getName() + ")";
+      try
       {
-         @Override
-         public Object addingService(ServiceReference reference)
-         {
-            LifecycleInterceptor interceptor = (LifecycleInterceptor)super.addingService(reference);
-            addInterceptor(interceptor);
-            return interceptor;
-         }
+         context.addServiceListener(this, filter);
+      }
+      catch (InvalidSyntaxException ex)
+      {
+         // ignore
+      }
+   }
 
-         @Override
-         public void removedService(ServiceReference reference, Object service)
-         {
-            super.removedService(reference, service);
-            LifecycleInterceptor interceptor = (LifecycleInterceptor)service;
-            removeInterceptor(interceptor);
-         }
-      };
-      tracker.open();
-   }
-   
    public BundleContext getSystemContext()
    {
       return context;
    }
 
+   @Override
+   public void serviceChanged(ServiceEvent event)
+   {
+      ServiceReference reference = event.getServiceReference();
+      LifecycleInterceptor interceptor = (LifecycleInterceptor)context.getService(reference);
+      switch (event.getType())
+      {
+         case ServiceEvent.REGISTERED:
+            addInterceptor(interceptor);
+            break;
+         case ServiceEvent.UNREGISTERING:
+            removeInterceptor(interceptor);
+            break;
+      }
+   }
+
    /**
     * Add a LifecycleInterceptor to the service.
     * 
@@ -100,20 +108,20 @@
    {
       if (interceptor == null)
          throw new IllegalArgumentException("Null interceptor");
-      
+
       log.debug("Add interceptor: " + new InterceptorWrapper(interceptor));
-      
+
       synchronized (interceptorChain)
       {
          Set<LifecycleInterceptor> unsortedSet = new HashSet<LifecycleInterceptor>();
          unsortedSet.addAll(interceptorChain);
          unsortedSet.add(interceptor);
-         
+
          List<LifecycleInterceptor> sortedList = new ArrayList<LifecycleInterceptor>();
-         
+
          // Add interceptors with no inputs first 
          Iterator<LifecycleInterceptor> itUnsorted = unsortedSet.iterator();
-         while(itUnsorted.hasNext())
+         while (itUnsorted.hasNext())
          {
             LifecycleInterceptor aux = itUnsorted.next();
             if (aux.getInput() == null)
@@ -131,16 +139,16 @@
             if (auxOutput != null)
                providedOutputs.addAll(auxOutput);
          }
-         
+
          // Add interceptors with sattisfied inputs 
          itUnsorted = unsortedSet.iterator();
-         while(itUnsorted.hasNext())
+         while (itUnsorted.hasNext())
          {
             LifecycleInterceptor aux = itUnsorted.next();
             Set<Class<?>> input = aux.getInput();
             if (input == null)
                throw new IllegalStateException("Interceptor with no inputs should have been added already");
-            
+
             if (providedOutputs.containsAll(input))
             {
                addWithRelativeOrder(sortedList, aux);
@@ -153,7 +161,7 @@
          {
             addWithRelativeOrder(sortedList, aux);
          }
-         
+
          // Log the interceptor order
          StringBuffer buffer = new StringBuffer();
          for (LifecycleInterceptor aux : sortedList)
@@ -162,7 +170,7 @@
             buffer.append("\n  " + wrapper.toLongString());
          }
          log.debug("Resulting interceptor chain" + buffer.toString());
-         
+
          // Use the sorted result as the new interceptor chain
          interceptorChain.clear();
          interceptorChain.addAll(sortedList);
@@ -174,12 +182,12 @@
       Set<Class<?>> providedOutputs = new HashSet<Class<?>>();
       int relOrder = interceptor.getRelativeOrder();
       Set<Class<?>> input = interceptor.getInput();
-      
+
       for (int i = 0; i < sortedList.size(); i++)
       {
          LifecycleInterceptor aux = sortedList.get(i);
          int auxOrder = aux.getRelativeOrder();
-         
+
          // Add if all inputs are satisfied and the rel order is less or equal
          boolean inputsProvided = (input == null || providedOutputs.containsAll(input));
          if (inputsProvided && relOrder <= auxOrder)
@@ -193,11 +201,11 @@
          if (auxOutput != null)
             providedOutputs.addAll(auxOutput);
       }
-      
+
       // If not added yet, add at end
       sortedList.add(interceptor);
    }
-   
+
    /**
     * Remove an LifecycleInterceptor to the service.
     * 
@@ -207,9 +215,9 @@
    {
       if (interceptor == null)
          throw new IllegalArgumentException("Null interceptor");
-      
+
       log.debug("Remove interceptor: " + new InterceptorWrapper(interceptor));
-      
+
       synchronized (interceptorChain)
       {
          interceptorChain.remove(interceptor);
@@ -238,16 +246,16 @@
          // Nothing to do
          if (interceptorChain.size() == 0)
             return;
-         
+
          InvocationContext inv = getInvocationContext(bundle);
          if (inv == null)
             throw new IllegalStateException("Cannot get invocation context for: " + bundle);
-         
+
          // Call the interceptor chain
          for (LifecycleInterceptor aux : interceptorChain)
          {
             Set<Class<?>> input = aux.getInput();
-            
+
             boolean doInvocation = true;
             if (input != null)
             {
@@ -261,7 +269,7 @@
                   }
                }
             }
-            
+
             if (doInvocation == true)
             {
                InterceptorWrapper wrapper = new InterceptorWrapper(aux);

Modified: projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
===================================================================
--- projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java	2010-03-20 06:12:15 UTC (rev 102660)
+++ projects/jboss-osgi/projects/runtime/deployment/trunk/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java	2010-03-20 07:10:59 UTC (rev 102661)
@@ -42,7 +42,6 @@
 import org.osgi.framework.Version;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
-import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * A {@link DeployerService} that installs/uninstalls the bundles directly on the OSGi framework.
@@ -56,7 +55,6 @@
    private static final Logger log = Logger.getLogger(SystemDeployerService.class);
 
    private BundleContext context;
-   private ServiceTracker startLevelTracker;
 
    public SystemDeployerService(BundleContext context)
    {
@@ -188,11 +186,7 @@
 
    private StartLevel getStartLevel()
    {
-      if (startLevelTracker == null)
-      {
-         startLevelTracker = new ServiceTracker(context, StartLevel.class.getName(), null);
-         startLevelTracker.open();
-      }
-      return (StartLevel)startLevelTracker.getService();
+      ServiceReference sref = context.getServiceReference(StartLevel.class.getName());
+      return sref != null ? (StartLevel)context.getService(sref) : null;
    }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list