[jboss-cvs] JBossAS SVN: r92992 - in projects/demos/microcontainer/trunk/igloo/src/main: resources/META-INF and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Aug 29 19:36:27 EDT 2009


Author: alesj
Date: 2009-08-29 19:36:27 -0400 (Sat, 29 Aug 2009)
New Revision: 92992

Added:
   projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResetDeployer.java
   projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolver.java
Modified:
   projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolveDeployer.java
   projects/demos/microcontainer/trunk/igloo/src/main/resources/META-INF/igloo-beans.xml
Log:
Bundle resolver.

Copied: projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResetDeployer.java (from rev 92957, projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolveDeployer.java)
===================================================================
--- projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResetDeployer.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResetDeployer.java	2009-08-29 23:36:27 UTC (rev 92992)
@@ -0,0 +1,56 @@
+/*
+ * 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.demos.bootstrap.igloo.deployers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+
+/**
+ * Simple bundle reset deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleResetDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
+{
+   private BundleResolver resolver;
+
+   public BundleResetDeployer(BundleResolver resolver)
+   {
+      super(OSGiMetaData.class);
+
+      if (resolver == null)
+         throw new IllegalArgumentException("Null resolver");
+
+      this.resolver = resolver;
+
+      setStage(new DeploymentStage("Reset"));
+      setTopLevelOnly(true);
+   }
+
+   public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
+   {
+      resolver.reset(unit);
+   }
+}
\ No newline at end of file

Modified: projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolveDeployer.java
===================================================================
--- projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolveDeployer.java	2009-08-29 20:09:23 UTC (rev 92991)
+++ projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolveDeployer.java	2009-08-29 23:36:27 UTC (rev 92992)
@@ -21,13 +21,7 @@
  */
 package org.jboss.demos.bootstrap.igloo.deployers;
 
-import java.util.Set;
-
 import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.spi.DependencyInfo;
-import org.jboss.dependency.spi.DependencyItem;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
@@ -41,11 +35,17 @@
  */
 public class BundleResolveDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
 {
-   static final ControllerState CLASSLOADER_STATE = new ControllerState(DeploymentStages.CLASSLOADER.getName());
+   private BundleResolver resolver;
 
-   public BundleResolveDeployer()
+   public BundleResolveDeployer(BundleResolver resolver)
    {
       super(OSGiMetaData.class);
+
+      if (resolver == null)
+         throw new IllegalArgumentException("Null resolver");
+
+      this.resolver = resolver;
+
       addInput(Module.class);
       setStage(DeploymentStages.DESCRIBE);
       setTopLevelOnly(true);
@@ -53,13 +53,6 @@
 
    public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
    {
-      ControllerContext context = unit.getAttachment(ControllerContext.class);
-      if (context != null)
-      {
-         DependencyInfo info = context.getDependencyInfo();
-         Set<DependencyItem> items = info.getUnresolvedDependencies(CLASSLOADER_STATE);
-         if (items == null || items.isEmpty())
-            unit.setRequiredStage(DeploymentStages.CLASSLOADER);
-      }
+      resolver.resolve(unit);
    }
 }
\ No newline at end of file

Copied: projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolver.java (from rev 92957, projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolveDeployer.java)
===================================================================
--- projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolver.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/igloo/src/main/java/org/jboss/demos/bootstrap/igloo/deployers/BundleResolver.java	2009-08-29 23:36:27 UTC (rev 92992)
@@ -0,0 +1,121 @@
+/*
+ * 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.demos.bootstrap.igloo.deployers;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Simple bundle resolve helper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleResolver
+{
+   static final ControllerState DESCRIBED_STATE = new ControllerState(DeploymentStages.DESCRIBE.getName());
+   static final ControllerState CLASSLOADER_STATE = new ControllerState(DeploymentStages.CLASSLOADER.getName());
+
+   private Set<DeploymentUnit> units = new CopyOnWriteArraySet<DeploymentUnit>();
+
+   public BundleResolver(Controller controller)
+   {
+      controller.addState(new ControllerState("Reset"), null);
+   }
+
+   void resolve(DeploymentUnit unit)
+   {
+      run(unit, new Action()
+      {
+         public void resolved(DeploymentUnit unit)
+         {
+            unit.setRequiredStage(DeploymentStages.CLASSLOADER);
+            for (DeploymentUnit unresolved : units)
+            {
+               unresolved.setRequiredStage(DeploymentStages.CLASSLOADER); // try moving
+               ControllerContext context = unresolved.getAttachment(ControllerContext.class);
+               if (context != null)
+                  context.setRequiredState(CLASSLOADER_STATE);
+            }
+         }
+
+         public void unresolved(DeploymentUnit unit)
+         {
+            units.add(unit);
+         }
+      });
+   }
+
+   void reset(DeploymentUnit unit)
+   {
+      units.remove(unit); // remove, as we're clearly resolved
+
+      Set<DeploymentUnit> copy = new HashSet<DeploymentUnit>(units);
+      for (DeploymentUnit unresolved : copy)
+      {
+         run(unresolved, new Action()
+         {
+            public void resolved(DeploymentUnit unit)
+            {
+               units.remove(unit);
+            }
+
+            public void unresolved(DeploymentUnit unit)
+            {
+               unit.setRequiredStage(DeploymentStages.DESCRIBE); // move back
+               ControllerContext context = unit.getAttachment(ControllerContext.class);
+               if (context != null)
+                  context.setRequiredState(DESCRIBED_STATE);
+            }
+         });
+      }
+   }
+
+   protected void run(DeploymentUnit unit, Action action)
+   {
+      ControllerContext context = unit.getAttachment(ControllerContext.class);
+      if (context != null)
+      {
+         DependencyInfo info = context.getDependencyInfo();
+         Set<DependencyItem> unresolvedDependencies = info.getUnresolvedDependencies(CLASSLOADER_STATE);
+         if (unresolvedDependencies == null || unresolvedDependencies.isEmpty())
+            action.resolved(unit);
+         else
+            action.unresolved(unit);
+      }
+   }
+
+   private interface Action
+   {
+      void resolved(DeploymentUnit unit);
+
+      void unresolved(DeploymentUnit unit);
+   }
+}
\ No newline at end of file

Modified: projects/demos/microcontainer/trunk/igloo/src/main/resources/META-INF/igloo-beans.xml
===================================================================
--- projects/demos/microcontainer/trunk/igloo/src/main/resources/META-INF/igloo-beans.xml	2009-08-29 20:09:23 UTC (rev 92991)
+++ projects/demos/microcontainer/trunk/igloo/src/main/resources/META-INF/igloo-beans.xml	2009-08-29 23:36:27 UTC (rev 92992)
@@ -58,7 +58,15 @@
   <bean name="OSGiBundleClassLoadingDeployer" class="org.jboss.osgi.plugins.facade.classloading.OSGiBundleClassLoadingDeployer"/>
   <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.plugins.deployers.bundle.OSGiBundleActivatorDeployer" />
 
-  <bean name="OSGiBundleResolveDeployer" class="org.jboss.demos.bootstrap.igloo.deployers.BundleResolveDeployer" />  
+  <bean name="BundleResolver" class="org.jboss.demos.bootstrap.igloo.deployers.BundleResolver">
+    <constructor><parameter><inject bean="jboss.kernel:service=KernelController" /></parameter></constructor>
+  </bean>
+  <bean name="OSGiBundleResolveDeployer" class="org.jboss.demos.bootstrap.igloo.deployers.BundleResolveDeployer">
+    <constructor><parameter><inject bean="BundleResolver" /></parameter></constructor>
+  </bean>
+  <bean name="OSGiBundleResetDeployer" class="org.jboss.demos.bootstrap.igloo.deployers.BundleResetDeployer">
+    <constructor><parameter><inject bean="BundleResolver" /></parameter></constructor>
+  </bean>
   <bean name="OSGiBundleStartStopDeployer" class="org.jboss.demos.bootstrap.igloo.deployers.BundleStartStopDeployer" />
 
 </deployment>




More information about the jboss-cvs-commits mailing list