[jboss-cvs] JBossAS SVN: r104936 - in projects/jboss-deployers/branches/Branch_2_0: deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 18 11:41:22 EDT 2010
Author: alesj
Date: 2010-05-18 11:41:20 -0400 (Tue, 18 May 2010)
New Revision: 104936
Added:
projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java
projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/test/BeansDeploymentRegistryUnitTestCase.java
Modified:
projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java
Log:
Port deployment registry.
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java 2010-05-18 15:18:36 UTC (rev 104935)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java 2010-05-18 15:41:20 UTC (rev 104936)
@@ -21,8 +21,10 @@
*/
package org.jboss.deployers.spi.deployer.helpers;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentRegistry;
import org.jboss.deployers.structure.spi.DeploymentUnit;
/**
@@ -37,6 +39,9 @@
/** Use unit name for controller context name */
private boolean useUnitName;
+ /** The controller context to deployment unit mapping */
+ private DeploymentRegistry registry;
+
/**
* Create a new AbstractRealDeployer.
*/
@@ -123,6 +128,30 @@
}
/**
+ * Put context to deployment mapping.
+ *
+ * @param context the context
+ * @param unit the deployment
+ * @return previous mapping value
+ */
+ protected DeploymentUnit putContext(ControllerContext context, DeploymentUnit unit)
+ {
+ return (registry != null) ? registry.putContext(context, unit) : null;
+ }
+
+ /**
+ * Remove context to deployment mapping.
+ *
+ * @param context the context
+ * @param unit the deployment
+ * @return is previous mapping value same as unit param
+ */
+ protected DeploymentUnit removeContext(ControllerContext context, DeploymentUnit unit)
+ {
+ return (registry != null) ? registry.removeContext(context, unit) : null;
+ }
+
+ /**
* Should we use unit name for controller context name.
*
* @return true if usage is allowed
@@ -141,4 +170,14 @@
{
this.useUnitName = useUnitName;
}
+
+ /**
+ * Set the context to deployment mapping.
+ *
+ * @param registry the registry
+ */
+ public void setDeploymentRegistry(DeploymentRegistry registry)
+ {
+ this.registry = registry;
+ }
}
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java (from rev 104929, projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentUnit.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java 2010-05-18 15:41:20 UTC (rev 104936)
@@ -0,0 +1,68 @@
+/*
+ * 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.deployers.structure.spi;
+
+import java.util.Set;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * This registry keeps a track of deployment's context.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface DeploymentRegistry
+{
+ /**
+ * Put context to deployment mapping.
+ *
+ * @param context the context
+ * @param unit the deployment
+ * @return previous mapping value
+ */
+ DeploymentUnit putContext(ControllerContext context, DeploymentUnit unit);
+
+ /**
+ * Remove context to deployment mapping.
+ *
+ * @param context the context
+ * @param unit the deployment
+ * @return previous mapping value
+ */
+ DeploymentUnit removeContext(ControllerContext context, DeploymentUnit unit);
+
+ /**
+ * Get owner deployment for context.
+ *
+ * @param context the context
+ * @return owning deployment unit
+ */
+ DeploymentUnit getDeployment(ControllerContext context);
+
+ /**
+ * Get contexts owned by deployment unit.
+ *
+ * @param unit the deployment unit
+ * @return set of contexts
+ */
+ Set<ControllerContext> getContexts(DeploymentUnit unit);
+}
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java (from rev 104932, projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java 2010-05-18 15:41:20 UTC (rev 104936)
@@ -0,0 +1,121 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.deployers.structure.spi.helpers;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.deployers.structure.spi.DeploymentRegistry;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Simple deployment registry
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractDeploymentRegistry implements DeploymentRegistry
+{
+ /** The read/write lock */
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+ /** The context 2 deployment mapping */
+ private final Map<ControllerContext, DeploymentUnit> contextMapping = new ConcurrentHashMap<ControllerContext, DeploymentUnit>();
+
+ /** The deployment 2 context mapping */
+ private final Map<DeploymentUnit, Set<ControllerContext>> deploymentMapping = new HashMap<DeploymentUnit, Set<ControllerContext>>();
+
+ private void check(ControllerContext context, DeploymentUnit unit)
+ {
+ if (context == null || unit == null)
+ throw new IllegalArgumentException("Null context or unit: context=" + context + ", unit=" + unit);
+ }
+
+ public DeploymentUnit putContext(ControllerContext context, DeploymentUnit unit)
+ {
+ check(context, unit);
+ lock.writeLock().lock();
+ try
+ {
+ Set<ControllerContext> contexts = deploymentMapping.get(unit);
+ if (contexts == null)
+ {
+ contexts = new HashSet<ControllerContext>();
+ deploymentMapping.put(unit, contexts);
+ }
+ contexts.add(context);
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
+ return contextMapping.put(context, unit);
+ }
+
+ public DeploymentUnit removeContext(ControllerContext context, DeploymentUnit unit)
+ {
+ check(context, unit);
+ lock.writeLock().lock();
+ try
+ {
+ Set<ControllerContext> contexts = deploymentMapping.get(unit);
+ if (contexts != null)
+ {
+ contexts.remove(context);
+
+ if (contexts.isEmpty())
+ deploymentMapping.remove(unit);
+ }
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
+ return contextMapping.remove(context);
+ }
+
+ public DeploymentUnit getDeployment(ControllerContext context)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+
+ return contextMapping.get(context);
+ }
+
+ public Set<ControllerContext> getContexts(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null deployment unit");
+
+ lock.readLock().lock();
+ try
+ {
+ Set<ControllerContext> contexts = deploymentMapping.get(unit);
+ return (contexts != null) ? new HashSet<ControllerContext>(contexts) : Collections.<ControllerContext>emptySet();
+ }
+ finally
+ {
+ lock.readLock().unlock();
+ }
+ }
+}
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java 2010-05-18 15:18:36 UTC (rev 104935)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java 2010-05-18 15:41:20 UTC (rev 104936)
@@ -29,6 +29,7 @@
import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
import org.jboss.beans.metadata.spi.ValueMetaData;
import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ScopeInfo;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
@@ -116,12 +117,16 @@
ScopeInfo scopeInfo = context.getScopeInfo();
scopeInfo.setScope(unit.getScope());
scopeInfo.setMutableScope(unit.getMutableScope());
+
try
{
+ // move this before install, so FromDeployment can access it
+ putContext(context, unit.getParent()); // we're a component, use parent
controller.install(context);
}
catch (Throwable t)
{
+ removeContext(context, unit.getParent());
throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment.getName(), t);
}
}
@@ -152,8 +157,9 @@
@Override
public void undeploy(DeploymentUnit unit, BeanMetaData deployment)
{
- controller.uninstall(deployment.getName());
-
+ ControllerContext context = controller.uninstall(deployment.getName());
+ removeContext(context, unit.getParent());
+
// Remove any classloader metadata we added (not necessary if we clone above)
ClassLoaderMetaData classLoader = deployment.getClassLoader();
if (classLoader instanceof DeploymentClassLoaderMetaData)
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java 2010-05-18 15:18:36 UTC (rev 104935)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java 2010-05-18 15:41:20 UTC (rev 104936)
@@ -21,20 +21,11 @@
*/
package org.jboss.test.deployers.vfs.deployer.bean;
+import org.jboss.test.deployers.vfs.deployer.bean.test.*;
+
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
-import org.jboss.test.deployers.vfs.deployer.bean.test.AliasDeployerUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.AnnotatedBeansUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.BeanDeployerClassLoaderUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.BeanDeployerUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.BeanManagedDeploymentUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.BeanMetaDataFactoryDeployerUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.BeanScanningUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.BuilderBeansUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.KernelDeployerUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.KernelScopeUnitTestCase;
-import org.jboss.test.deployers.vfs.deployer.bean.test.AutowireAnnotationBeansTestCase;
/**
* BeanDeployerTestSuite.
@@ -65,6 +56,7 @@
suite.addTest(AnnotatedBeansUnitTestCase.suite());
suite.addTest(BuilderBeansUnitTestCase.suite());
suite.addTest(AutowireAnnotationBeansTestCase.suite());
+ suite.addTest(BeansDeploymentRegistryUnitTestCase.suite());
return suite;
}
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/test/BeansDeploymentRegistryUnitTestCase.java (from rev 104929, projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/test/BeanScanningUnitTestCase.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/test/BeansDeploymentRegistryUnitTestCase.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/deployer/bean/test/BeansDeploymentRegistryUnitTestCase.java 2010-05-18 15:41:20 UTC (rev 104936)
@@ -0,0 +1,168 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.test.deployers.vfs.deployer.bean.test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.structure.spi.DeploymentRegistry;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentRegistry;
+import org.jboss.deployers.vfs.deployer.kernel.BeanDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.KernelDeploymentDeployer;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.kernel.Kernel;
+import org.jboss.test.deployers.support.TCCLClassLoaderDeployer;
+import org.jboss.test.deployers.vfs.deployer.AbstractDeployerUnitTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * BeansDeploymentRegistryUnitTestCase.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BeansDeploymentRegistryUnitTestCase extends AbstractDeployerUnitTest
+{
+ private DeploymentRegistry registry;
+
+ public static Test suite()
+ {
+ return new TestSuite(BeansDeploymentRegistryUnitTestCase.class);
+ }
+
+ public BeansDeploymentRegistryUnitTestCase(String name) throws Throwable
+ {
+ super(name);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ registry = null;
+ super.tearDown();
+ }
+
+ protected void addDeployers(Kernel kernel)
+ {
+ registry = new AbstractDeploymentRegistry();
+
+ BeanDeployer beanDeployer = new BeanDeployer();
+ KernelDeploymentDeployer kernelDeploymentDeployer = new KernelDeploymentDeployer();
+ TCCLClassLoaderDeployer tcclDeployer = new TCCLClassLoaderDeployer();
+ addDeployer(main, beanDeployer);
+ addDeployer(main, kernelDeploymentDeployer);
+ addDeployer(main, tcclDeployer);
+
+ BeanMetaDataDeployer deployer = new BeanMetaDataDeployer(kernel.getController());
+ deployer.setDeploymentRegistry(registry);
+ addDeployer(main, deployer);
+ }
+
+ public void testSuccessfulDeployment() throws Throwable
+ {
+ ControllerContext c1 = null;
+ ControllerContext c2 = null;
+ DeploymentUnit unit = null;
+
+ VFSDeployment deployment = createDeployment("/bean/multiple", "test.jar");
+ assertDeploy(deployment);
+ try
+ {
+ c1 = controller.getInstalledContext("Test1");
+ c2 = controller.getInstalledContext("Test2");
+ unit = assertDeploymentUnit(main, deployment.getName());
+
+ Set<ControllerContext> contexts = new HashSet<ControllerContext>();
+ contexts.add(c1);
+ contexts.add(c2);
+
+ assertEquals(contexts, registry.getContexts(unit));
+ assertSame(unit, registry.getDeployment(c1));
+ assertSame(unit, registry.getDeployment(c2));
+ }
+ finally
+ {
+ assertUndeploy(deployment);
+
+ assertEmpty(registry.getContexts(unit));
+ assertNull(registry.getDeployment(c1));
+ assertNull(registry.getDeployment(c2));
+ }
+ }
+
+ public void testFailedDeployment() throws Throwable
+ {
+ ControllerContext c1 = null;
+ ControllerContext c2 = null;
+ DeploymentUnit unit = null;
+
+ VFSDeployment deployment = createDeployment("/bean/multiple", "test.jar");
+ assertDeploy(deployment);
+ try
+ {
+ c1 = controller.getInstalledContext("Test1");
+ c2 = controller.getInstalledContext("Test2");
+ unit = assertDeploymentUnit(main, deployment.getName());
+
+ Set<ControllerContext> contexts = new HashSet<ControllerContext>();
+ contexts.add(c1);
+ contexts.add(c2);
+
+ assertEquals(contexts, registry.getContexts(unit));
+ assertSame(unit, registry.getDeployment(c1));
+ assertSame(unit, registry.getDeployment(c2));
+
+ Deployment failed = createSimpleDeployment("failed");
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("Foo", Object.class.getName());
+ builder.addAlias("Test1");
+ ((MutableAttachments)failed.getPredeterminedManagedObjects()).addAttachment(BeanMetaData.class, builder.getBeanMetaData());
+
+ try
+ {
+ DeploymentUnit du = addDeployment(main, failed);
+ ControllerContext foo = controller.getInstalledContext("Foo");
+ assertNull(foo);
+ assertEmpty(registry.getContexts(du));
+ }
+ finally
+ {
+ assertUndeploy(failed);
+ }
+ }
+ finally
+ {
+ assertUndeploy(deployment);
+
+ assertEmpty(registry.getContexts(unit));
+ assertNull(registry.getDeployment(c1));
+ assertNull(registry.getDeployment(c2));
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list