[jboss-cvs] JBossAS SVN: r97077 - in projects/jboss-deployers/trunk: deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 27 07:14:18 EST 2009
Author: alesj
Date: 2009-11-27 07:14:17 -0500 (Fri, 27 Nov 2009)
New Revision: 97077
Added:
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java
Modified:
projects/jboss-deployers/trunk/deployers-jmx/src/main/java/org/jboss/system/deployers/ServiceDeployer.java
projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
Log:
[JBDEPLOY-65]; context to deployment registry.
Modified: projects/jboss-deployers/trunk/deployers-jmx/src/main/java/org/jboss/system/deployers/ServiceDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-jmx/src/main/java/org/jboss/system/deployers/ServiceDeployer.java 2009-11-27 12:08:58 UTC (rev 97076)
+++ projects/jboss-deployers/trunk/deployers-jmx/src/main/java/org/jboss/system/deployers/ServiceDeployer.java 2009-11-27 12:14:17 UTC (rev 97077)
@@ -24,9 +24,12 @@
import javax.management.ObjectName;
import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.kernel.Kernel;
import org.jboss.mx.util.ObjectNameFactory;
import org.jboss.system.ServiceContext;
import org.jboss.system.ServiceController;
@@ -112,6 +115,10 @@
remove(name);
throw t;
}
+
+ ControllerContext serviceContext = getControllerContext(name);
+ if (serviceContext != null)
+ putContext(serviceContext, unit);
}
catch (Throwable t)
{
@@ -120,6 +127,20 @@
}
/**
+ * Get service's controller context.
+ *
+ * @param name the service's object name
+ * @return the context
+ */
+ protected ControllerContext getControllerContext(ObjectName name)
+ {
+ Kernel kernel = controller.getKernel();
+ Controller controller = kernel.getController();
+ String canonicalName = name.getCanonicalName(); // too impl detail?
+ return controller.getContext(canonicalName, null);
+ }
+
+ /**
* Find first RealClassLoader instance
* and return its ObjectName.
* If none is found return defaultClassloader.
@@ -144,6 +165,11 @@
public void undeploy(DeploymentUnit unit, ServiceMetaData deployment)
{
ObjectName name = deployment.getObjectName();
+
+ ControllerContext serviceContext = getControllerContext(name);
+ if (serviceContext != null)
+ removeContext(serviceContext, unit);
+
ServiceContext context = controller.getServiceContext(name);
if (context != null)
{
Modified: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java 2009-11-27 12:08:58 UTC (rev 97076)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java 2009-11-27 12:14:17 UTC (rev 97077)
@@ -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;
+ }
}
Added: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentRegistry.java 2009-11-27 12:14:17 UTC (rev 97077)
@@ -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/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java (from rev 96678, projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentRegistry.java 2009-11-27 12:14:17 UTC (rev 97077)
@@ -0,0 +1,119 @@
+/*
+* 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.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+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)
+ {
+ return contextMapping.get(context);
+ }
+
+ public Set<ControllerContext> getContexts(DeploymentUnit 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();
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java 2009-11-27 12:08:58 UTC (rev 97076)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java 2009-11-27 12:14:17 UTC (rev 97077)
@@ -36,6 +36,7 @@
import org.jboss.beans.metadata.spi.ValueMetaData;
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ScopeInfo;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -177,6 +178,7 @@
try
{
controller.install(context);
+ putContext(context, unit);
}
catch (Throwable t)
{
@@ -223,7 +225,8 @@
BeanMetaDataDeployerPlugin plugin = deployedWithPlugin.remove(deployment.getName());
if (plugin == null || plugin.uninstallContext(controller, unit, deployment) == false)
{
- controller.uninstall(deployment.getName());
+ ControllerContext context = controller.uninstall(deployment.getName());
+ removeContext(context, unit);
}
// Remove any classloader metadata we added (not necessary if we clone above)
More information about the jboss-cvs-commits
mailing list