[jboss-cvs] JBossAS SVN: r84802 - in projects/jboss-osgi/trunk/runtime/deployer/src/main: java/org/jboss/osgi/deployer/helpers and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 26 08:41:29 EST 2009


Author: alesj
Date: 2009-02-26 08:41:29 -0500 (Thu, 26 Feb 2009)
New Revision: 84802

Added:
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/VDFBundleListener.java
Modified:
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java
   projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
Log:
Add BundleListener.

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-02-26 13:12:41 UTC (rev 84801)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-02-26 13:41:29 UTC (rev 84802)
@@ -38,7 +38,7 @@
    public BundleStartStopDeployer()
    {
       super(Bundle.class);
-      setStage(DeploymentStages.POST_CLASSLOADER);
+      setStage(DeploymentStages.PRE_REAL);
    }
 
    public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java	2009-02-26 13:12:41 UTC (rev 84801)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java	2009-02-26 13:41:29 UTC (rev 84802)
@@ -30,6 +30,7 @@
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.deployer.helpers.VDFBundleListener;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -46,17 +47,23 @@
    private BundleContext bundleContext;
    private List<URI> skipBundles;
 
-   public OSGiDeployer()
+   private VDFBundleListener listener;
+
+   public OSGiDeployer(VDFBundleListener listener)
    {
       super(OSGiMetaData.class);
+      if (listener == null)
+         throw new IllegalArgumentException("Null listener");
+
       addOutput(Bundle.class);
       setStage(DeploymentStages.POST_PARSE);
+      this.listener = listener;
    }
 
    public void setBundleContext(BundleContext bundleContext)
    {
       this.bundleContext = bundleContext;
-   }
+   }                                                   
 
    public void setSkipBundles(List<URI> skipBundles)
    {
@@ -67,8 +74,18 @@
    {
       if (bundleContext == null)
          throw new IllegalArgumentException("No system bundle context.");
+
+      bundleContext.addBundleListener(listener);
    }
 
+   public void stop()
+   {
+      if (bundleContext == null)
+         return;
+
+      bundleContext.removeBundleListener(listener);
+   }
+
    public void deploy(DeploymentUnit unit, OSGiMetaData metadata) throws DeploymentException
    {
       log.info("Install Bundle: " + metadata.getSymbolicName());
@@ -83,6 +100,7 @@
          {
             Bundle bundle = bundleContext.installBundle(bundleUri.toString());
             unit.addAttachment(Bundle.class, bundle);
+            listener.addDeployment(unit);
          }
       }
       catch (BundleException ex)
@@ -98,6 +116,7 @@
       if (bundle != null)
       {
          log.info("Uninstall Bundle: " + bundle.getSymbolicName());
+         listener.removeDeployment(unit);
          try
          {
             bundle.uninstall();

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java	2009-02-26 13:12:41 UTC (rev 84801)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java	2009-02-26 13:41:29 UTC (rev 84802)
@@ -49,7 +49,13 @@
    @Override
    public boolean resolve(Controller controller)
    {
-      setResolved(bundle.getState() == Bundle.RESOLVED);
+      setResolved((bundle.getState() & Bundle.RESOLVED) == Bundle.RESOLVED);
       return isResolved();
    }
+
+   @Override
+   protected void toHumanReadableString(StringBuilder builder)
+   {
+      builder.append("Bundle(state): ").append(bundle).append("(").append(bundle.getState()).append(")");
+   }
 }
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/VDFBundleListener.java (from rev 84799, projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/BundleClassLoader.java)
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/VDFBundleListener.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/VDFBundleListener.java	2009-02-26 13:41:29 UTC (rev 84802)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deployer.helpers;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+
+/**
+ * MC's VDF based BundleListener.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class VDFBundleListener implements BundleListener
+{
+   private static Logger log = Logger.getLogger(VDFBundleListener.class);
+   private static Map<Integer, DeploymentStage> stages = new HashMap<Integer, DeploymentStage>();
+   private Map<Long, String> deployments = new ConcurrentHashMap<Long, String>();
+
+   private final DeployerClient main;
+
+   static
+   {
+      stages.put(BundleEvent.INSTALLED, DeploymentStages.NOT_INSTALLED);
+      stages.put(BundleEvent.RESOLVED, DeploymentStages.CLASSLOADER);
+      stages.put(BundleEvent.LAZY_ACTIVATION, DeploymentStages.INSTALLED); // TODO
+      stages.put(BundleEvent.STARTING, DeploymentStages.POST_CLASSLOADER);
+      stages.put(BundleEvent.STARTED, DeploymentStages.PRE_REAL);
+      stages.put(BundleEvent.STOPPING, DeploymentStages.PRE_REAL);
+      stages.put(BundleEvent.STOPPED, DeploymentStages.POST_CLASSLOADER);
+      stages.put(BundleEvent.UPDATED, DeploymentStages.NOT_INSTALLED); // TODO
+      stages.put(BundleEvent.UNRESOLVED, DeploymentStages.DESCRIBE);
+      stages.put(BundleEvent.UNINSTALLED, DeploymentStages.NOT_INSTALLED);
+   }
+
+   public VDFBundleListener(DeployerClient main)
+   {
+      if (main == null)
+         throw new IllegalArgumentException("Null deployer client");
+
+      this.main = main;
+   }
+
+   public void bundleChanged(BundleEvent event)
+   {
+      Bundle bundle = event.getBundle();
+      long id = bundle.getBundleId();
+      String deploymentName = deployments.get(id);
+      if (deploymentName != null)
+      {
+         try
+         {
+            int type = event.getType();
+            DeploymentStage stage = stages.get(type);
+            main.change(deploymentName, stage);
+         }
+         catch (Throwable t)
+         {
+            log.error("Exception changing context state: " + t);
+         }
+      }
+   }
+
+   public void addDeployment(DeploymentUnit unit)
+   {
+      Bundle bundle = unit.getAttachment(Bundle.class);
+      if (bundle != null)
+      {
+         deployments.put(bundle.getBundleId(), unit.getName());
+      }
+   }
+
+   public void removeDeployment(DeploymentUnit unit)
+   {
+      Bundle bundle = unit.getAttachment(Bundle.class);
+      if (bundle != null)
+      {
+         deployments.remove(bundle.getBundleId());
+      }
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml	2009-02-26 13:12:41 UTC (rev 84801)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml	2009-02-26 13:41:29 UTC (rev 84802)
@@ -65,8 +65,18 @@
   <!-- The OSGi Meta Data Deployer -->
   <bean name="jboss.osgi:service=MetaDataDeployer" class="org.jboss.osgi.deployer.OSGiMetaDataDeployer" />
 
+  <!-- VDFBundleListener -->
+  <bean name="VDFBundleListener" class="org.jboss.osgi.deployer.helpers.VDFBundleListener">
+    <constructor>
+      <parameter><inject/></parameter>
+    </constructor>
+  </bean>
+
   <!-- The OSGi Deployer -->
   <bean name="jboss.osgi:service=Deployer" class="org.jboss.osgi.deployer.OSGiDeployer">
+    <constructor>
+      <parameter><inject bean="VDFBundleListener"/></parameter>
+    </constructor>
     <property name="bundleContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
     <property name="skipBundles"><inject bean="jboss.osgi:service=Framework" property="autoInstall" /></property>
   </bean>




More information about the jboss-cvs-commits mailing list