[jboss-osgi-commits] JBoss-OSGI SVN: r89497 - in projects/jboss-osgi/trunk/bundles: hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal and 1 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu May 28 09:56:57 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-05-28 09:56:57 -0400 (Thu, 28 May 2009)
New Revision: 89497

Added:
   projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/BundleInfo.java
   projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java
   projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScannerService.java
   projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java
Removed:
   projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScanner.java
Modified:
   projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/MicrocontainerService.java
   projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/BundleInfoImpl.java
   projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerActivator.java
   projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java
   projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/ScannerThread.java
   projects/jboss-osgi/trunk/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
Log:
Deployment scanner uses DeploymentService

Added: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/BundleInfo.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/BundleInfo.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/BundleInfo.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.common.service;
+
+//$Id$
+
+import java.net.URL;
+
+
+/**
+ * An abstraction of a bundle in the scan folder
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public interface BundleInfo
+{
+   /**
+    * The state of the bundle
+    */
+   enum State
+   {
+      NEW, INSTALLED, ACTIVE, UNINSTALLED
+   }
+
+   /**
+    * Get the bundle location
+    */
+   URL getLocation();
+
+   /**
+    * Get the bundle state
+    */
+   BundleInfo.State getState();
+
+   /**
+    * Get the bundle symbolic name
+    */
+   String getSymbolicName();
+
+   /**
+    * Get the bundle version
+    */
+   String getVersion();
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/BundleInfo.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.common.service;
+
+//$Id$
+
+
+/**
+ * A Service that deploys bundles through the deployers that
+ * are registered with the {@link MicrocontainerService}
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public interface DeployerService
+{
+   /**
+    * Deploy an array of bundles
+    */
+   void deploy(BundleInfo[] bundles) throws Exception;
+
+   /**
+    * Undeploy an array of bundles
+    */
+   void undeploy(BundleInfo[] bundles) throws Exception;
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Deleted: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScanner.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScanner.java	2009-05-28 13:54:17 UTC (rev 89496)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScanner.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -1,108 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.common.service;
-
-//$Id$
-
-import java.net.URL;
-
-/**
- * The DeploymentScanner service 
- * 
- * @author thomas.diesler at jboss.com
- * @since 27-May-2009
- */
-public interface DeploymentScanner
-{
-   /**
-    * The property that names the scan location: org.jboss.osgi.hotdeploy.scandir
-    */
-   String PROPERTY_SCAN_LOCATION = "org.jboss.osgi.hotdeploy.scandir";
-   
-   /**
-    * The property to defines the scan interval: org.jboss.osgi.hotdeploy.interval
-    */
-   String PROPERTY_SCAN_INTERVAL = "org.jboss.osgi.hotdeploy.interval";
-   
-   /**
-    * Get the scan location URL.
-    *  
-    * This is can be specified by setting the {@link PROPERTY_SCAN_LOCATION} property. 
-    */
-   URL getScanLocation();
-   
-   /**
-    * The number of scans since the service started 
-    */
-   long getScanCount();
-   
-   /**
-    * The number of milliseconds between scans
-    * Defaults to 2000ms 
-    */
-   long getScanInterval();
-   
-   /**
-    * Run a directory scan
-    */
-   void scan();
-   
-   /**
-    * Returns the array of bundles currently known to the deployemtn scanner. 
-    */
-   BundleInfo[] getBundles();
-   
-   /**
-    * An abstraction of a bundle in the scan folder
-    * 
-    */
-   interface BundleInfo
-   {
-      /**
-       * The state of the bundle
-       */
-      enum State
-      {
-         NEW, INSTALLED, ACTIVE, UNINSTALLED
-      }
-
-      /**
-       * Get the bundle location
-       */
-      URL getLocation();
-
-      /**
-       * Get the bundle state
-       */
-      State getState();
-
-      /**
-       * Get the bundle symbolic name
-       */
-      String getSymbolicName();
-
-      /**
-       * Get the bundle version
-       */
-      String getVersion();
-   }
-}
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScannerService.java (from rev 89492, projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScanner.java)
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScannerService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeploymentScannerService.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.common.service;
+
+//$Id$
+
+import java.net.URL;
+
+
+/**
+ * A service that scans a directory location for new/removed bundles.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public interface DeploymentScannerService
+{
+   /**
+    * The property that names the scan location: org.jboss.osgi.hotdeploy.scandir
+    */
+   String PROPERTY_SCAN_LOCATION = "org.jboss.osgi.hotdeploy.scandir";
+   
+   /**
+    * The property to defines the scan interval: org.jboss.osgi.hotdeploy.interval
+    */
+   String PROPERTY_SCAN_INTERVAL = "org.jboss.osgi.hotdeploy.interval";
+   
+   /**
+    * Get the scan location URL.
+    *  
+    * This is can be specified by setting the {@link PROPERTY_SCAN_LOCATION} property. 
+    */
+   URL getScanLocation();
+   
+   /**
+    * The number of scans since the service started 
+    */
+   long getScanCount();
+   
+   /**
+    * The number of milliseconds between scans
+    * Defaults to 2000ms 
+    */
+   long getScanInterval();
+   
+   /**
+    * Run a directory scan
+    */
+   void scan();
+   
+   /**
+    * Returns the array of bundles currently known to the deployemtn scanner. 
+    */
+   BundleInfo[] getBundles();
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/MicrocontainerService.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/MicrocontainerService.java	2009-05-28 13:54:17 UTC (rev 89496)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/MicrocontainerService.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -23,7 +23,6 @@
 
 //$Id$
 
-import java.net.URL;
 import java.util.List;
 
 /**
@@ -64,14 +63,4 @@
     * @return null if there is no bean registered under this name
     */
    Object getRegisteredBean(String beanName);
-
-   /*
-    * * Deploy MC beans from URL
-    */
-   void deploy(URL url) throws Exception;
-
-   /*
-    * * Undeploy MC beans from URL
-    */
-   void undeploy(URL url) throws Exception;
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/BundleInfoImpl.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/BundleInfoImpl.java	2009-05-28 13:54:17 UTC (rev 89496)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/BundleInfoImpl.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -26,11 +26,10 @@
 import java.net.URL;
 import java.util.Dictionary;
 
-import org.jboss.osgi.common.service.DeploymentScanner.BundleInfo;
+import org.jboss.osgi.common.service.BundleInfo;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 
-
 /**
  * An abstraction of a bundle in the scan folder
  * 

Modified: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerActivator.java	2009-05-28 13:54:17 UTC (rev 89496)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerActivator.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -23,12 +23,12 @@
 
 //$Id$
 
-import org.jboss.osgi.common.service.DeploymentScanner;
+import org.jboss.osgi.common.service.DeploymentScannerService;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
 /**
- * The {@link DeploymentScanner} service activator
+ * The {@link DeploymentScannerService} service activator
  * 
  * @author thomas.diesler at jboss.com
  * @since 27-May-2009
@@ -40,7 +40,7 @@
    public void start(BundleContext context)
    {
       service = new DeploymentScannerImpl(context);
-      context.registerService(DeploymentScanner.class.getName(), service, null);
+      context.registerService(DeploymentScannerService.class.getName(), service, null);
       
       service.start();
    }

Modified: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java	2009-05-28 13:54:17 UTC (rev 89496)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -37,12 +37,15 @@
 import java.util.jar.Manifest;
 
 import org.jboss.osgi.common.log.LogServiceTracker;
-import org.jboss.osgi.common.service.DeploymentScanner;
-import org.jboss.osgi.common.service.DeploymentScanner.BundleInfo.State;
+import org.jboss.osgi.common.service.BundleInfo;
+import org.jboss.osgi.common.service.DeployerService;
+import org.jboss.osgi.common.service.DeploymentScannerService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * The DeploymentScanner service
@@ -50,7 +53,7 @@
  * @author thomas.diesler at jboss.com
  * @since 27-May-2009
  */
-public class DeploymentScannerImpl implements DeploymentScanner
+public class DeploymentScannerImpl implements DeploymentScannerService
 {
    private LogServiceTracker log;
    private BundleContext context;
@@ -60,6 +63,7 @@
    private long scanCount;
 
    private ScannerThread scannerThread;
+   private DeployerService deployerService;
    private List<BundleInfo> lastScan = new ArrayList<BundleInfo>();
 
    public DeploymentScannerImpl(BundleContext context)
@@ -67,6 +71,25 @@
       this.log = new LogServiceTracker(context);
       this.context = context;
 
+      // Init and track the DeployerService
+      deployerService = new SimpleDeployerService(context);
+      ServiceTracker tracker = new ServiceTracker(context, DeployerService.class.getName(), null)
+      {
+         @Override
+         public Object addingService(ServiceReference reference)
+         {
+            deployerService = (DeployerService)super.addingService(reference);
+            return deployerService;
+         }
+
+         @Override
+         public void removedService(ServiceReference reference, Object service)
+         {
+            deployerService = new SimpleDeployerService(context);
+         }
+      };
+      tracker.open();
+      
       initScanner(context);
    }
 
@@ -110,25 +133,16 @@
             diff.add(info);
       }
 
-      for (BundleInfo info : diff)
+      // Undeploy the bundles through the DeployerService
+      try
       {
-         Bundle bundle = getInstalledBundle(info.getSymbolicName());
-         if (bundle != null)
-         {
-            if (info.getState() == State.INSTALLED || info.getState() == State.ACTIVE)
-            {
-               try
-               {
-                  log.log(LogService.LOG_DEBUG, "Uninstall: " + info.getSymbolicName());
-                  bundle.uninstall();
-               }
-               catch (BundleException ex)
-               {
-                  log.log(LogService.LOG_ERROR, "Cannot uninstall bundle", ex);
-               }
-            }
-         }
+         BundleInfo[] infoArr = diff.toArray(new BundleInfo[diff.size()]); 
+         deployerService.undeploy(infoArr);
       }
+      catch (Exception ex)
+      {
+         log.log(LogService.LOG_ERROR, "Cannot undeploy bundles", ex);
+      }
    }
 
    private void processNewDeployments(List<BundleInfo> currScan)
@@ -142,65 +156,26 @@
             diff.add(info);
       }
 
-      // Install the NEW bundles
-      List<Bundle> bundles = new ArrayList<Bundle>();
-      for (BundleInfo info : diff)
+      // Deploy the bundles through the DeployerService
+      try
       {
-         if (info.getState() == BundleInfo.State.NEW)
-         {
-            try
-            {
-               log.log(LogService.LOG_DEBUG, "Install: " + info.getSymbolicName());
-               Bundle bundle = context.installBundle(info.getLocation().toExternalForm());
-               bundles.add(bundle);
-            }
-            catch (BundleException ex)
-            {
-               log.log(LogService.LOG_ERROR, "Cannot install bundle: " + info.getSymbolicName(), ex);
-            }
-         }
+         BundleInfo[] infoArr = diff.toArray(new BundleInfo[diff.size()]); 
+         deployerService.deploy(infoArr);
       }
-
-      // Start the installed bundles
-      for (Bundle bundle : bundles)
+      catch (Exception ex)
       {
-         try
-         {
-            log.log(LogService.LOG_DEBUG, "Start: " + bundle.getSymbolicName());
-            bundle.start();
-         }
-         catch (BundleException ex)
-         {
-            log.log(LogService.LOG_ERROR, "Cannot start bundle: " + bundle.getSymbolicName(), ex);
-         }
+         log.log(LogService.LOG_ERROR, "Cannot deploy bundles", ex);
       }
    }
 
-   private Bundle getInstalledBundle(String symbolicName)
-   {
-      Bundle bundle = null;
-
-      for (Bundle aux : context.getBundles())
-      {
-         if (aux.getSymbolicName().equals(symbolicName))
-         {
-            bundle = aux;
-            break;
-         }
-      }
-
-      return bundle;
-   }
-
    public BundleInfo[] getBundles()
    {
-      List<BundleInfoImpl> bundles = new ArrayList<BundleInfoImpl>();
+      List<BundleInfo> bundles = new ArrayList<BundleInfo>();
       for (File file : scanLocation.listFiles())
       {
-         String symbolicName = getSymbolicName(file);
-         Bundle bundle = getInstalledBundle(symbolicName);
-         BundleInfoImpl bundleInfo = new BundleInfoImpl(toURL(file), symbolicName, bundle);
-         bundles.add(bundleInfo);
+         BundleInfo info = getBundleInfo(file);
+         Bundle bundle = SimpleDeployerService.getInstalledBundle(context, info);
+         bundles.add(new BundleInfoImpl(toURL(file), info.getSymbolicName(), bundle));
       }
       BundleInfo[] arr = new BundleInfoImpl[bundles.size()];
       return bundles.toArray(arr);
@@ -256,18 +231,19 @@
       scanLocation = scanFile;
    }
 
-   private String getSymbolicName(File file)
+   private BundleInfo getBundleInfo(File file)
    {
       try
       {
          JarFile jarFile = new JarFile(file);
          Manifest manifest = jarFile.getManifest();
          Attributes attribs = manifest.getMainAttributes();
-         String symbolicName = attribs.getValue(BUNDLE_SYMBOLICNAME);
+         
+         String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
          if (symbolicName == null)
-            throw new IllegalStateException("Cannot obtain '" + BUNDLE_SYMBOLICNAME + "' from: " + file);
+            throw new IllegalStateException("Cannot obtain '" + Constants.BUNDLE_SYMBOLICNAME + "' from: " + file);
 
-         return symbolicName;
+         return new BundleInfoImpl(toURL(file), symbolicName, null);
       }
       catch (IOException ex)
       {

Modified: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/ScannerThread.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/ScannerThread.java	2009-05-28 13:54:17 UTC (rev 89496)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/ScannerThread.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -24,7 +24,7 @@
 //$Id$
 
 import org.jboss.osgi.common.log.LogServiceTracker;
-import org.jboss.osgi.common.service.DeploymentScanner;
+import org.jboss.osgi.common.service.DeploymentScannerService;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
 
@@ -38,10 +38,10 @@
 {
    private LogService log;
    
-   private DeploymentScanner scanner;
+   private DeploymentScannerService scanner;
    private boolean active = true;
 
-   public ScannerThread(BundleContext context, DeploymentScanner scanner)
+   public ScannerThread(BundleContext context, DeploymentScannerService scanner)
    {
       this.log = new LogServiceTracker(context);
       this.scanner = scanner;

Added: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.service.hotdeploy.internal;
+
+//$Id$
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.common.service.BundleInfo;
+import org.jboss.osgi.common.service.DeployerService;
+import org.jboss.osgi.common.service.BundleInfo.State;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.service.log.LogService;
+
+/**
+ * A {@link DeployerService} that installs/uninstalls the 
+ * bundles directly on the OSGi framework without going 
+ * through the MC registered deployers.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class SimpleDeployerService implements DeployerService
+{
+   private LogServiceTracker log;
+   private BundleContext context;
+
+   public SimpleDeployerService(BundleContext context)
+   {
+      this.log = new LogServiceTracker(context);
+      this.context = context;
+   }
+
+   public void deploy(BundleInfo[] bundleInfos) throws BundleException
+   {
+      // Install the NEW bundles
+      List<Bundle> bundles = new ArrayList<Bundle>();
+      for (BundleInfo info : bundleInfos)
+      {
+         if (info.getState() == BundleInfo.State.NEW)
+         {
+            try
+            {
+               log.log(LogService.LOG_DEBUG, "Install: " + info.getSymbolicName());
+               Bundle bundle = context.installBundle(info.getLocation().toExternalForm());
+               bundles.add(bundle);
+            }
+            catch (BundleException ex)
+            {
+               log.log(LogService.LOG_ERROR, "Cannot install bundle: " + info.getSymbolicName(), ex);
+            }
+         }
+      }
+
+      // Start the installed bundles
+      for (Bundle bundle : bundles)
+      {
+         try
+         {
+            log.log(LogService.LOG_DEBUG, "Start: " + bundle.getSymbolicName());
+            bundle.start();
+         }
+         catch (BundleException ex)
+         {
+            log.log(LogService.LOG_ERROR, "Cannot start bundle: " + bundle.getSymbolicName(), ex);
+         }
+      }
+   }
+
+   public void undeploy(BundleInfo[] bundleInfos) throws BundleException
+   {
+      for (BundleInfo info : bundleInfos)
+      {
+         Bundle bundle = getInstalledBundle(context, info);
+         if (bundle != null)
+         {
+            if (info.getState() == State.INSTALLED || info.getState() == State.ACTIVE)
+            {
+               try
+               {
+                  log.log(LogService.LOG_DEBUG, "Uninstall: " + info.getSymbolicName());
+                  bundle.uninstall();
+               }
+               catch (BundleException ex)
+               {
+                  log.log(LogService.LOG_ERROR, "Cannot uninstall bundle", ex);
+               }
+            }
+         }
+      }
+   }
+
+   public static Bundle getInstalledBundle(BundleContext context, BundleInfo bundleInfo)
+   {
+      Bundle bundle = null;
+
+      for (Bundle aux : context.getBundles())
+      {
+         String symbolicName = aux.getSymbolicName();
+         if (symbolicName.equals(bundleInfo.getSymbolicName()))
+         {
+            bundle = aux;
+            break;
+         }
+      }
+
+      return bundle;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java	2009-05-28 13:54:17 UTC (rev 89496)
+++ projects/jboss-osgi/trunk/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java	2009-05-28 13:56:57 UTC (rev 89497)
@@ -41,6 +41,7 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerContextActions;
 import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.client.spi.main.MainDeployer;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
@@ -49,8 +50,11 @@
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.common.service.BundleInfo;
+import org.jboss.osgi.common.service.DeployerService;
 import org.jboss.osgi.common.service.MicrocontainerService;
 import org.jboss.osgi.microcontainer.MicrocontainerServiceMBean;
+import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.BundleContext;
@@ -64,7 +68,7 @@
  * @author thomas.diesler at jboss.com
  * @since 23-Jan-2009
  */
-public class MicrocontainerServiceImpl implements MicrocontainerService, MicrocontainerServiceMBean
+public class MicrocontainerServiceImpl implements DeployerService, MicrocontainerService, MicrocontainerServiceMBean
 {
    private BundleContext context;
    private EmbeddedBeansDeployer deployer;
@@ -108,25 +112,34 @@
       return context != null ? context.getTarget() : null;
    }
 
-   public void deploy(URL url) throws Exception
+   public void deploy(BundleInfo[] bundles) throws Exception
    {
       ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
       try
       {
          Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
 
+         List<Deployment> deployments = new ArrayList<Deployment>();
          MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
-         VirtualFile file = VFS.createNewRoot(url);
-         VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
-         mainDeployer.addDeployment(deployment);
-         String deploymentName = deployment.getName();
+         for (BundleInfo bundle : bundles)
+         {
+            VirtualFile file = VFS.createNewRoot(bundle.getLocation());
+            VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
+            mainDeployer.addDeployment(deployment);
+            deployments.add(deployment);
+            contextMap.put(bundle.getLocation(), deployment.getName());
+         }
+
+         // Process the deployments
          mainDeployer.process();
-         contextMap.put(url, deploymentName);
-         mainDeployer.checkComplete(deployment);
+
+         // Check for completeness
+         Deployment[] depArr = deployments.toArray(new Deployment[deployments.size()]);
+         mainDeployer.checkComplete(depArr);
       }
       catch (IOException ex)
       {
-         DeploymentException.rethrowAsDeploymentException("Cannot deploy: " + url, ex);
+         DeploymentException.rethrowAsDeploymentException("Cannot deploy bundles: ", ex);
       }
       finally
       {
@@ -134,24 +147,39 @@
       }
    }
 
-   public void undeploy(URL url) throws Exception
+   public void undeploy(BundleInfo[] bundles) throws Exception
    {
-      String deploymentName = contextMap.remove(url);
-      if (deploymentName != null)
+      MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
+      for (BundleInfo bundle : bundles)
       {
-         MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
-         mainDeployer.removeDeployment(deploymentName);
-         mainDeployer.process();
+         String deploymentName = contextMap.remove(bundle.getLocation());
+         if (deploymentName != null)
+         {
+            mainDeployer.removeDeployment(deploymentName);
+         }
+         else
+         {
+            log.log(LogService.LOG_WARNING, "Package not deployed: " + bundle.getLocation());
+         }
       }
-      else
-      {
-         log.log(LogService.LOG_WARNING, "Package not deployed: " + url);
-      }
+      mainDeployer.process();
    }
 
+   public void deploy(URL url) throws Exception
+   {
+      BundleInfo info = new LocationOnlyBundleInfo(url);
+      deploy(new BundleInfo[] { info });
+   }
+
+   public void undeploy(URL url) throws Exception
+   {
+      BundleInfo info = new LocationOnlyBundleInfo(url);
+      undeploy(new BundleInfo[] { info });
+   }
+
    void start()
    {
-      final MicrocontainerService mcService = this;
+      final MicrocontainerService mcServiceImpl = this;
 
       final Kernel kernel = getKernel();
       final KernelController controller = kernel.getController();
@@ -177,8 +205,12 @@
 
             // Register the MicrocontainerService
             log.log(LogService.LOG_DEBUG, "Register MicrocontainerService");
-            context.registerService(MicrocontainerService.class.getName(), mcService, null);
+            context.registerService(MicrocontainerService.class.getName(), mcServiceImpl, null);
 
+            // Register the DeployerService
+            log.log(LogService.LOG_DEBUG, "Register DeployerService");
+            context.registerService(DeployerService.class.getName(), mcServiceImpl, null);
+
             // Register the MicrocontainerServiceMBean
             registerMicrocontainerServiceMBean(mbeanServer);
 
@@ -253,4 +285,34 @@
          super(name, actions, null, target);
       }
    }
+
+   static class LocationOnlyBundleInfo implements BundleInfo
+   {
+      private URL location;
+
+      public LocationOnlyBundleInfo(URL location)
+      {
+         this.location = location;
+      }
+
+      public URL getLocation()
+      {
+         return location;
+      }
+
+      public State getState()
+      {
+         throw new NotImplementedException();
+      }
+
+      public String getSymbolicName()
+      {
+         throw new NotImplementedException();
+      }
+
+      public String getVersion()
+      {
+         throw new NotImplementedException();
+      }
+   }
 }
\ No newline at end of file




More information about the jboss-osgi-commits mailing list