[jboss-cvs] JBossAS SVN: r95267 - in projects/jboss-osgi: projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 21 03:28:16 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-10-21 03:28:16 -0400 (Wed, 21 Oct 2009)
New Revision: 95267

Modified:
   projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
   projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
Log:
Use RTE for BundleInfo, Deployment construction
Provide Depployemnt lazily

Modified: projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/hotdeploy/internal/DeploymentScannerImpl.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -39,7 +39,6 @@
 import org.jboss.osgi.deployment.scanner.DeploymentScannerService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.slf4j.Logger;
@@ -104,7 +103,7 @@
       String scandir = scanLocation.getAbsolutePath();
       if (scandir.startsWith(osgiHome))
          scandir = "..." + scandir.substring(osgiHome.length());
-      
+
       log.info("Start DeploymentScanner: [scandir=" + scandir + ",interval=" + scanInterval + "ms]");
       scannerThread = new ScannerThread(context, this);
       lastChange = System.currentTimeMillis();
@@ -132,7 +131,7 @@
 
       if (oldDiff + newDiff > 0)
          lastChange = System.currentTimeMillis();
-      
+
       lastScan = currScan;
       scanCount++;
 
@@ -180,7 +179,7 @@
       }
 
       logBundleDeployments("OLD diff", diff);
-      
+
       // Undeploy the bundles through the DeployerService
       if (diff.size() > 0)
       {
@@ -194,7 +193,7 @@
             log.error("Cannot undeploy bundles", ex);
          }
       }
-      
+
       return diff.size();
    }
 
@@ -226,18 +225,18 @@
             log.error("Cannot deploy bundles", ex);
          }
       }
-      
+
       return diff.size();
    }
 
    public Deployment[] getBundleDeployments()
    {
       List<Deployment> bundles = new ArrayList<Deployment>();
-      
+
       File[] listFiles = scanLocation.listFiles();
       if (listFiles == null)
          log.warn("Cannot list files in: " + scanLocation);
-         
+
       if (listFiles != null)
       {
          for (File file : listFiles)
@@ -246,27 +245,20 @@
             Deployment dep = deploymentCache.get(bundleURL.toExternalForm());
             if (dep == null)
             {
-               try
-               {
-                  // hot-deploy bundles are started automatically
-                  dep = deployer.createDeployment(bundleURL);
-                  dep.setAutoStart(true);
-                  
-                  deploymentCache.put(bundleURL.toExternalForm(), dep);
-               }
-               catch (BundleException ex)
-               {
-                  log.warn("Cannot obtain bundle deployment for: " + file);
-               }
+               // hot-deploy bundles are started automatically
+               dep = deployer.createDeployment(bundleURL);
+               dep.setAutoStart(true);
+
+               deploymentCache.put(bundleURL.toExternalForm(), dep);
             }
             bundles.add(dep);
          }
       }
-      
+
       Deployment[] arr = new Deployment[bundles.size()];
       return bundles.toArray(arr);
    }
-   
+
    private void initScanner(BundleContext context)
    {
       scanInterval = 2000;
@@ -323,7 +315,7 @@
       }
       return bundle;
    }
-   
+
    private URL toURL(File file)
    {
       try

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/testing/internal/RemoteRuntime.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -127,7 +127,7 @@
          BundleInfo.createBundleInfo(archiveURL);
          return true;
       }
-      catch (BundleException ex)
+      catch (RuntimeException ex)
       {
          return false;
       }

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -33,7 +33,6 @@
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 
 /**
@@ -50,7 +49,7 @@
    private String symbolicName;
    private String version;
 
-   public static BundleInfo createBundleInfo(String location) throws BundleException
+   public static BundleInfo createBundleInfo(String location)
    {
       if (location == null)
          throw new IllegalArgumentException("Location cannot be null");
@@ -91,13 +90,13 @@
       }
       catch (IOException e)
       {
-         throw new BundleException("Invalid bundle location=" + url, e);
+         throw new IllegalArgumentException("Invalid bundle location=" + url, e);
       }
       
       return new BundleInfo(root, location);
    }
 
-   public static BundleInfo createBundleInfo(URL url) throws BundleException
+   public static BundleInfo createBundleInfo(URL url)
    {
       if (url == null)
          throw new IllegalArgumentException("URL cannot be null");
@@ -109,18 +108,18 @@
       }
       catch (IOException e)
       {
-         throw new BundleException("Invalid bundle location=" + url, e);
+         throw new IllegalArgumentException("Invalid bundle location=" + url, e);
       }
       
       return new BundleInfo(root, url.toExternalForm());
    }
    
-   public static BundleInfo createBundleInfo(VirtualFile root) throws BundleException
+   public static BundleInfo createBundleInfo(VirtualFile root)
    {
       return new BundleInfo(root, null);
    }
    
-   private BundleInfo(VirtualFile root, String location) throws BundleException
+   private BundleInfo(VirtualFile root, String location)
    {
       if (root == null)
          throw new IllegalArgumentException("VirtualFile cannot be null");
@@ -148,12 +147,12 @@
       }
       catch (Exception ex)
       {
-         throw new BundleException("Cannot get manifest from: " + root, ex);
+         throw new IllegalArgumentException("Cannot get manifest from: " + root, ex);
       }
       
       symbolicName = getManifestHeader(Constants.BUNDLE_SYMBOLICNAME);
       if (symbolicName == null)
-         throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + root);
+         throw new IllegalArgumentException("Cannot obtain Bundle-SymbolicName for: " + root);
 
       version = getManifestHeader(Constants.BUNDLE_VERSION);
       if (version == null)

Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/install-definition.xml	2009-10-21 07:28:16 UTC (rev 95267)
@@ -385,17 +385,15 @@
 
       <fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer"
         override="true">
+        <include name="jboss-osgi-deployment.jar" />
         <include name="jboss-osgi-runtime-felix.jar" />
         <include name="jboss-osgi-runtime-jbossas.jar" />
         <include name="org.apache.felix.framework.jar" />
       </fileset>
       <singlefile condition="isFelix" src="@{deploy.artifacts.dir}/resources/jbossas/jboss-beans-felix.xml" target="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer/META-INF/jboss-osgi-jboss-beans.xml"
         override="true" />
-      <fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer"
-        override="true">
-        <include name="jboss-osgi-runtime-jbossas.jar" />
-      </fileset>
       <fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
+        <include name="jboss-osgi-deployment.jar" />
         <include name="org.apache.felix.configadmin.jar" />
         <include name="org.apache.felix.metatype.jar" />
       </fileset>
@@ -408,6 +406,7 @@
 
       <fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer"
         override="true">
+        <include name="jboss-osgi-deployment.jar" />
         <include name="jboss-osgi-runtime-equinox.jar" />
         <include name="jboss-osgi-runtime-jbossas.jar" />
         <include name="org.apache.equinox.framework.jar" />
@@ -415,11 +414,8 @@
       </fileset>
       <singlefile condition="isEquinox" src="@{deploy.artifacts.dir}/resources/jbossas/jboss-beans-equinox.xml" target="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer/META-INF/jboss-osgi-jboss-beans.xml"
         override="true" />
-      <fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer"
-        override="true">
-        <include name="jboss-osgi-runtime-jbossas.jar" />
-      </fileset>
       <fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
+        <include name="jboss-osgi-deployment.jar" />
         <include name="org.apache.felix.configadmin.jar" />
         <include name="org.apache.felix.metatype.jar" />
         <include name="org.eclipse.osgi.services.jar" />
@@ -430,6 +426,7 @@
       <fileset condition="isJBossMC" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer"
         override="true">
         <include name="jboss-osgi-framework.jar" />
+        <include name="jboss-osgi-deployment.jar" />
       </fileset>
       <singlefile condition="isJBossMC" src="@{deploy.artifacts.dir}/resources/jbossas/jboss-beans-jbossmc.xml" target="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer/META-INF/jboss-osgi-jboss-beans.xml"
         override="true" />

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -28,7 +28,7 @@
 import org.jboss.osgi.deployment.common.Deployment;
 import org.jboss.osgi.deployment.internal.DeploymentImpl;
 import org.jboss.osgi.spi.util.BundleInfo;
-import org.osgi.framework.BundleException;
+import org.jboss.virtual.VirtualFile;
 
 /**
  * An abstract base implementation of the DeployerService.
@@ -38,9 +38,15 @@
  */
 public abstract class AbstractDeployerService implements DeployerService
 {
-   public Deployment createDeployment(URL url) throws BundleException
+   public Deployment createDeployment(URL url)
    {
       BundleInfo info = BundleInfo.createBundleInfo(url);
       return new DeploymentImpl(info);
    }
+   
+   public Deployment createDeployment(VirtualFile file)
+   {
+      BundleInfo info = BundleInfo.createBundleInfo(file);
+      return new DeploymentImpl(info);
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -29,6 +29,7 @@
 
 import org.jboss.osgi.deployment.common.Deployment;
 import org.jboss.osgi.spi.management.ObjectNameFactory;
+import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.BundleException;
 
 /**
@@ -47,8 +48,13 @@
    /** 
     * Create a deployment from the given location. 
     */
-   Deployment createDeployment(URL url) throws BundleException;
+   Deployment createDeployment(URL url);
    
+   /** 
+    * Create a deployment from the given file. 
+    */
+   Deployment createDeployment(VirtualFile file);
+   
    /**
     * Deploy an array of bundles
     */

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -63,8 +63,6 @@
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.kernel.Kernel;
 import org.jboss.logging.Logger;
-import org.jboss.osgi.deployment.common.Deployment;
-import org.jboss.osgi.deployment.internal.DeploymentImpl;
 import org.jboss.osgi.framework.filter.NoFilter;
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
@@ -75,7 +73,6 @@
 import org.jboss.osgi.framework.plugins.Plugin;
 import org.jboss.osgi.framework.plugins.ServicePlugin;
 import org.jboss.osgi.framework.resolver.BundleResolver;
-import org.jboss.osgi.spi.util.BundleInfo;
 import org.jboss.util.collection.ConcurrentSet;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VFSUtils;
@@ -475,11 +472,6 @@
          att.addAttachment(PROPERTY_AUTO_START, Boolean.FALSE);
          att.addAttachment(PROPERTY_BUNDLE_LOCATION, location);
 
-         // Add the deployment used by lifecycle interceptors
-         BundleInfo info = BundleInfo.createBundleInfo(root);
-         Deployment dep = new DeploymentImpl(info);
-         att.addAttachment(Deployment.class, dep);
-         
          deployerClient.deploy(deployment);
          try
          {

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/DeployerServiceImpl.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -35,6 +35,7 @@
 import org.jboss.osgi.framework.bundle.OSGiBundleManager;
 import org.jboss.osgi.framework.plugins.DeployerServicePlugin;
 import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
+import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 
@@ -74,11 +75,16 @@
       // do nothing
    }
 
-   public Deployment createDeployment(URL url) throws BundleException
+   public Deployment createDeployment(URL url)
    {
       return delegate.createDeployment(url);
    }
 
+   public Deployment createDeployment(VirtualFile file)
+   {
+      return delegate.createDeployment(file);
+   }
+
    public void deploy(Deployment[] bundleDeps) throws BundleException
    {
       delegate.deploy(bundleDeps);

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2009-10-21 07:26:16 UTC (rev 95266)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java	2009-10-21 07:28:16 UTC (rev 95267)
@@ -23,9 +23,10 @@
 
 //$Id$
 
-import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.logging.Logger;
 import org.jboss.osgi.deployment.common.Deployment;
+import org.jboss.osgi.deployment.deployer.DeployerService;
 import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptorService;
 import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
 import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
@@ -35,6 +36,7 @@
 import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
 
@@ -49,7 +51,7 @@
    // Provide logging
    final Logger log = Logger.getLogger(LifecycleInterceptorServiceImpl.class);
 
-   private LifecycleInterceptorService service;
+   private LifecycleInterceptorService delegate;
    private ServiceRegistration registration;
 
    public LifecycleInterceptorServiceImpl(OSGiBundleManager bundleManager)
@@ -59,24 +61,28 @@
 
    public void startService()
    {
-      BundleContext context = getSystemContext();
-      service = new AbstractLifecycleInterceptorService()
+      final BundleContext context = getSystemContext();
+      delegate = new AbstractLifecycleInterceptorService()
       {
          protected Deployment getDeployment(String name, Version version)
          {
             OSGiBundleState bundle = (OSGiBundleState)bundleManager.getBundle(name, version);
             if (bundle == null)
                throw new IllegalStateException("Cannot obtain bundle for: " + name + "-" + version);
-            
-            DeploymentUnit unit = bundle.getDeploymentUnit();
+
+            VFSDeploymentUnit unit = (VFSDeploymentUnit)bundle.getDeploymentUnit();
             Deployment dep = unit.getAttachment(Deployment.class);
             if (dep == null)
-               throw new IllegalStateException("Cannot obtain deployment for: " + bundle);
-            
+            {
+               ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
+               DeployerService service = (DeployerService)context.getService(sref);
+               dep = service.createDeployment(unit.getRoot());
+               unit.addAttachment(Deployment.class, dep);
+            }
             return dep;
          }
       };
-      registration = context.registerService(LifecycleInterceptorService.class.getName(), service, null);
+      registration = context.registerService(LifecycleInterceptorService.class.getName(), delegate, null);
    }
 
    public void stopService()
@@ -85,22 +91,25 @@
       {
          registration.unregister();
          registration = null;
-         service = null;
+         delegate = null;
       }
    }
 
    public void addInterceptor(LifecycleInterceptor interceptor)
    {
-      service.addInterceptor(interceptor);
+      if (delegate != null)
+         delegate.addInterceptor(interceptor);
    }
 
    public void removeInterceptor(LifecycleInterceptor interceptor)
    {
-      service.removeInterceptor(interceptor);
+      if (delegate != null)
+         delegate.removeInterceptor(interceptor);
    }
 
    public void handleStateChange(int state, Bundle bundle)
    {
-      service.handleStateChange(state, bundle);
+      if (delegate != null)
+         delegate.handleStateChange(state, bundle);
    }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list