[jboss-cvs] JBossAS SVN: r79155 - in projects/jboss-deployers/trunk: deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 6 11:17:46 EDT 2008
Author: adrian at jboss.org
Date: 2008-10-06 11:17:46 -0400 (Mon, 06 Oct 2008)
New Revision: 79155
Added:
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentMBean.java
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContextMBean.java
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContextMBean.java
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/DeployerTracking.java
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/TrackingMutableAttachments.java
projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContextMBean.java
Modified:
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerWrapper.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java
projects/jboss-deployers/trunk/deployers-structure-spi/pom.xml
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
projects/jboss-deployers/trunk/pom.xml
Log:
[JBDEPLOY-99] - JMX management
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerWrapper.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerWrapper.java 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerWrapper.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -30,6 +30,7 @@
import org.jboss.deployers.spi.deployer.DeploymentStage;
import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.DeployerTracking;
import org.jboss.logging.Logger;
import org.jboss.managed.api.ManagedObject;
@@ -70,7 +71,7 @@
this.log = Logger.getLogger(deployer.getClass());
this.classLoader = SecurityActions.getContextClassLoader();
}
-
+
/**
* Get the managedObjectCreator.
*
@@ -162,6 +163,7 @@
if (unit == null)
throw new IllegalArgumentException("Null unit");
+ DeployerTracking.push(deployer.toString());
ClassLoader previous = SecurityActions.setContextClassLoader(classLoader);
try
{
@@ -176,6 +178,7 @@
}
finally
{
+ DeployerTracking.pop();
SecurityActions.resetContextClassLoader(previous);
}
}
@@ -185,6 +188,7 @@
if (unit == null)
throw new IllegalArgumentException("Null unit");
+ DeployerTracking.push(deployer.toString());
ClassLoader previous = SecurityActions.setContextClassLoader(classLoader);
try
{
@@ -198,6 +202,7 @@
}
finally
{
+ DeployerTracking.pop();
SecurityActions.resetContextClassLoader(previous);
}
}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -34,6 +34,10 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerContextActions;
@@ -55,6 +59,7 @@
import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentMBean;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
import org.jboss.kernel.spi.dependency.KernelController;
@@ -69,7 +74,7 @@
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class DeployersImpl implements Deployers, ControllerContextActions, DeployersImplMBean
+public class DeployersImpl implements Deployers, ControllerContextActions, DeployersImplMBean, MBeanRegistration
{
/**
* The log
@@ -92,6 +97,12 @@
*/
private Controller controller;
+ /** The mbean server */
+ private MBeanServer server;
+
+ /** Whether to register deployments as mbeans */
+ private boolean registerMBeans = true;
+
/**
* The repository
*/
@@ -385,6 +396,26 @@
this.repository = repository;
}
+ /**
+ * Get whether to register mbeans
+ *
+ * @return true to register mbeans
+ */
+ public boolean isRegisterMBeans()
+ {
+ return registerMBeans;
+ }
+
+ /**
+ * Set whether to register mbeans
+ *
+ * @param registerMBeans true to register mbeans
+ */
+ public void setRegisterMBeans(boolean registerMBeans)
+ {
+ this.registerMBeans = registerMBeans;
+ }
+
public void start()
{
// Bootstrap the repository
@@ -457,6 +488,97 @@
return deploymentTimes.listTimes(details);
}
+ public String listDeployers(String stageName)
+ {
+ StringBuilder result = new StringBuilder();
+ result.append("<table><tr><th>Stage/Deployer</th><th>top</th><th>component</th><th>parent last</th><th>input<th>output</th></tr>");
+ if (stageName == null || stageName.trim().length() == 0)
+ {
+ for (String stage : stages.keySet())
+ internalListDeployers(stage, null, result);
+ }
+ else
+ {
+ internalListDeployers(stageName, null, result);
+ }
+ result.append("</table>");
+ return result.toString();
+ }
+
+ public String listDeployersByAttachment(String attachment)
+ {
+ if (attachment == null || attachment.trim().length() == 0)
+ return "No attachment specified";
+
+ StringBuilder result = new StringBuilder();
+ result.append("<table><tr><th>Stage/Deployer</th><th>top</th><th>component</th><th>parent last</th><th>input<th>output</th></tr>");
+ for (String stage : stages.keySet())
+ internalListDeployers(stage, attachment, result);
+ result.append("</table>");
+ return result.toString();
+ }
+
+ /**
+ * List the deployers for a stage
+ *
+ * @param stageName the stage
+ * @param attachment the attachment
+ * @param builder the builder
+ */
+ protected void internalListDeployers(String stageName, String attachment, StringBuilder builder)
+ {
+ List<Deployer> deployers = getDeployersList(stageName);
+ if (deployers.isEmpty())
+ return;
+
+ builder.append("<tr>").append("<td>").append(stageName).append("</td>").append("</tr>");
+ for (Deployer deployer : deployers)
+ {
+ int row = 0;
+ Set<String> deployerInputs = deployer.getInputs();
+ List<String> inputs = new ArrayList<String>();
+ for (String input : deployerInputs)
+ {
+ if (attachment == null || attachment.equals(input))
+ inputs.add(input);
+ }
+ Set<String> deployerOutputs = deployer.getOutputs();
+ List<String> outputs = new ArrayList<String>();
+ for (String output : deployerOutputs)
+ {
+ if (attachment == null || attachment.equals(output))
+ outputs.add(output);
+ }
+ if (attachment != null && inputs.isEmpty() && outputs.isEmpty())
+ continue;
+ while (row < 1 || row < outputs.size() || row < outputs.size())
+ {
+ builder.append("<tr>");
+ if (row == 0)
+ {
+ builder.append("<td>`--").append(deployer).append("</td>");
+ builder.append(deployer.isTopLevelOnly() ? "<td>X</td>" : "<td/>");
+ builder.append(deployer.isWantComponents() ? "<td>X</td>" : "<td/>");
+ builder.append(deployer.isParentFirst() == false ? "<td>X</td>" : "<td/>");
+ }
+ else
+ {
+ builder.append("<td/><td/><td/><td/>");
+ }
+ if (row < inputs.size())
+ builder.append("<td>").append(inputs.get(row)).append("</td>");
+ else
+ builder.append("<td/>");
+ if (row < outputs.size())
+ builder.append("<td>").append(outputs.get(row)).append("</td>");
+ else
+ builder.append("<td/>");
+ builder.append("</tr>");
+ ++row;
+ }
+ }
+ }
+
public DeploymentStage getDeploymentStage(DeploymentContext context) throws DeploymentException
{
DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
@@ -568,6 +690,7 @@
setState(context, DeploymentState.UNDEPLOYED, null);
// This is now in the abstract classloader deployer.undeploy,
// but left here in case somebody isn't using that.
+ unregisterMBean(context);
removeClassLoader(context);
cleanup(context);
log.debug("Fully Undeployed " + context.getName());
@@ -600,6 +723,7 @@
context.getTransientAttachments().addAttachment(ScopeBuilder.class, scopeBuilder);
if (repository != null)
context.getTransientAttachments().addAttachment(MutableMetaDataRepository.class, repository);
+ registerMBean(context);
}
catch (Throwable t)
{
@@ -608,6 +732,7 @@
context.setProblem(t);
// Set the children to not deployed
setState(context, DeploymentState.UNDEPLOYED, DeploymentState.DEPLOYING);
+ unregisterMBean(context);
}
}
@@ -1432,4 +1557,64 @@
cleanup(component);
}
}
+
+ /**
+ * Register a deployment context's mbean
+ *
+ * @param context the context
+ */
+ protected void registerMBean(DeploymentContext context)
+ {
+ if (server != null && isRegisterMBeans() && context instanceof DeploymentMBean)
+ {
+ try
+ {
+ DeploymentMBean depMBean = (DeploymentMBean) context;
+ server.registerMBean(context, depMBean.getObjectName());
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to register deployment mbean " + context.getName(), e);
+ }
+ }
+ }
+
+ /**
+ * Unregister a deployment context's mbean
+ *
+ * @param context the context
+ */
+ protected void unregisterMBean(DeploymentContext context)
+ {
+ if (server != null && isRegisterMBeans() && context instanceof DeploymentMBean )
+ {
+ try
+ {
+ DeploymentMBean depMBean = (DeploymentMBean) context;
+ server.unregisterMBean(depMBean.getObjectName());
+ }
+ catch (Exception e)
+ {
+ log.trace("Unable to unregister deployment mbean " + context.getName(), e);
+ }
+ }
+ }
+
+ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
+ {
+ this.server = server;
+ return name;
+ }
+
+ public void postRegister(Boolean registrationDone)
+ {
+ }
+
+ public void preDeregister() throws Exception
+ {
+ }
+
+ public void postDeregister()
+ {
+ }
}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -36,4 +36,20 @@
* @return the deployer times
*/
String listDeployerTimes(boolean details);
+
+ /**
+ * List the deployers for each stage in order
+ *
+ * @param stageName the stage name or null for all stages
+ * @return an html formatted table
+ */
+ String listDeployers(String stageName);
+
+ /**
+ * List the deployers for a given attachment
+ *
+ * @param attachment the attachment name
+ * @return an html formatted table
+ */
+ String listDeployersByAttachment(String attachment);
}
Modified: projects/jboss-deployers/trunk/deployers-structure-spi/pom.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/pom.xml 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/pom.xml 2008-10-06 15:17:46 UTC (rev 79155)
@@ -104,6 +104,16 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>org.jboss.integration</groupId>
+ <artifactId>jboss-classloading-spi</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-log4j</artifactId>
<scope>test</scope>
Added: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentMBean.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentMBean.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentMBean.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -0,0 +1,200 @@
+/*
+* 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.Comparator;
+import java.util.List;
+import java.util.Set;
+
+import javax.management.ObjectName;
+
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.deployers.spi.DeploymentState;
+import org.jboss.metadata.spi.scope.ScopeKey;
+
+/**
+ * DeploymentMBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface DeploymentMBean
+{
+ /**
+ * Get the deployment name
+ *
+ * @return the name
+ */
+ String getName();
+
+ /**
+ * Get the object name
+ *
+ * @return the object name
+ */
+ ObjectName getObjectName();
+
+ /**
+ * Get the controller context names.
+ *
+ * @return the names
+ */
+ Set<Object> getControllerContextNames();
+
+ /**
+ * Get the simple vfs name of the deployment unit. This is the simple
+ * name of the virtual file .
+ *
+ * vfs path ------------------- relative path
+ * deploy/some.ear "some.ear"
+ * deploy/some.ear/x.ejb "x.ejb"
+ * deploy/some.ear/y.sar "y.sar"
+ * deploy/some.ear/y.sar/z.rar "z.rar"
+ * @return the deployment unit simple path
+ */
+ String getSimpleName();
+
+ /**
+ * Get the path of this deployment relative to the top of the deployment
+ *
+ * vfs path ------------------- relative path
+ * deploy/some.ear ""
+ * deploy/some.ear/x.ejb "/x.ejb"
+ * deploy/some.ear/y.sar "/y.sar"
+ * deploy/some.ear/y.sar/z.rar "/y.sar/z.rar"
+ *
+ * @return the top-level deployment relative path
+ */
+ String getRelativePath();
+
+ /**
+ * Get the relative order
+ *
+ * @return the relative order
+ */
+ int getRelativeOrder();
+
+ /**
+ * Get the comparator.
+ *
+ * @return the comparator.
+ */
+ Comparator<DeploymentContext> getComparator();
+
+ /**
+ * Get the scope
+ *
+ * @return the scope
+ */
+ ScopeKey getScope();
+
+ /**
+ * Get the mutable scope
+ *
+ * @return the mutable scope
+ */
+ ScopeKey getMutableScope();
+
+ /**
+ * Set the mutable scope
+ *
+ * @param key the mutable scope key
+ */
+ void setMutableScope(ScopeKey key);
+
+ /**
+ * Get the deployment state
+ *
+ * @return the state
+ */
+ DeploymentState getState();
+
+ /**
+ * Gets the classloader for this deployment unit
+ *
+ * @return the classloader
+ */
+ ObjectName getClassLoaderName();
+
+ /**
+ * Whether this is a top level deployment
+ *
+ * @return true when top level
+ */
+ boolean isTopLevel();
+
+ /**
+ * Get the top level deployment
+ *
+ * @return the top level deployment
+ */
+ ObjectName getTopLevelName();
+
+ /**
+ * The parent
+ *
+ * @return the parent
+ */
+ ObjectName getParentName();
+
+ /**
+ * The children
+ *
+ * @return the children
+ */
+ List<ObjectName> getChildNames();
+
+ /**
+ * Whether this is a component
+ *
+ * @return true when a component
+ */
+ boolean isComponent();
+
+ /**
+ * The components
+ *
+ * @return the components
+ */
+ List<ObjectName> getComponentNames();
+
+ /**
+ * Get the dependency info
+ *
+ * @return the dependency
+ */
+ DependencyInfo getDependencyInfo();
+
+ /**
+ * Whether the deployment was processed
+ *
+ * @return true when processed
+ */
+ boolean isDeployed();
+
+ /**
+ * Get the problem for this context
+ *
+ * @return the problem
+ */
+ Throwable getProblem();
+}
Modified: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -27,23 +27,33 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.HashSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.classloading.spi.RealClassLoader;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.DeploymentState;
+import org.jboss.deployers.spi.attachments.Attachments;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.deployers.spi.attachments.helpers.ManagedObjectsWithTransientAttachmentsImpl;
import org.jboss.deployers.structure.spi.ClassLoaderFactory;
import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
+import org.jboss.deployers.structure.spi.DeploymentMBean;
import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
@@ -64,7 +74,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
-public class AbstractDeploymentContext extends ManagedObjectsWithTransientAttachmentsImpl implements DeploymentContext
+public class AbstractDeploymentContext extends ManagedObjectsWithTransientAttachmentsImpl implements DeploymentContext, AbstractDeploymentContextMBean, MBeanRegistration
{
/** The serialVersionUID */
private static final long serialVersionUID = 7368360479461613969L;
@@ -74,7 +84,13 @@
/** The name */
private String name;
+
+ /** The ObjectName */
+ private ObjectName objectName;
+ /** The MBeanServer */
+ private MBeanServer server;
+
/** The controller context names - should be serializable */
private Set<Object> controllerContextNames;
@@ -132,6 +148,12 @@
/** The mutable scope */
private ScopeKey mutableScope;
+ /** The transient managed objects */
+ private transient TrackingMutableAttachments transientManagedObjects;
+
+ /** The transient attachements */
+ private transient TrackingMutableAttachments transientAttachments;
+
/**
* Get the scope builder for a deployment context
*
@@ -294,7 +316,7 @@
{
if (deploymentContext == null)
throw new IllegalArgumentException("Null deployment context");
-
+
ScopeBuilder builder = deploymentContext.getTransientAttachments().getAttachment(ScopeBuilder.class);
if (builder == null)
builder = DefaultScopeBuilder.INSTANCE;
@@ -306,6 +328,8 @@
*/
public AbstractDeploymentContext()
{
+ transientManagedObjects = new TrackingMutableAttachments(super.getTransientManagedObjects());
+ transientAttachments = new TrackingMutableAttachments(super.getTransientAttachments());
}
/**
@@ -330,6 +354,7 @@
*/
public AbstractDeploymentContext(String name, String simpleName, String relativePath)
{
+ this();
if (name == null)
throw new IllegalArgumentException("Null name");
if (relativePath == null)
@@ -346,6 +371,30 @@
return name;
}
+ public ObjectName getObjectName()
+ {
+ if (objectName == null)
+ {
+ String type = "Deployment";
+ if (getParent() != null)
+ type = "SubDeployment";
+ if (isComponent())
+ type = "Component";
+ String name = getName();
+ name = name.replace("\"", """);
+ String temp = "jboss.deployment:id=\"" + name + "\",type=" + type;
+ try
+ {
+ objectName = new ObjectName(temp);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new RuntimeException("Error creating object name: " + temp, e);
+ }
+ }
+ return objectName;
+ }
+
public Set<Object> getControllerContextNames()
{
return controllerContextNames != null ? Collections.unmodifiableSet(controllerContextNames) : null;
@@ -482,6 +531,15 @@
{
return classLoader;
}
+
+ public ObjectName getClassLoaderName()
+ {
+ ClassLoader classLoader = getClassLoader();
+ if (classLoader == null || classLoader instanceof RealClassLoader == false)
+ return null;
+
+ return ((RealClassLoader) classLoader).getObjectName();
+ }
public void setClassLoader(ClassLoader classLoader)
{
@@ -558,11 +616,27 @@
}
return result;
}
-
+
+ public ObjectName getTopLevelName()
+ {
+ DeploymentContext top = getTopLevel();
+ if (top == null || top instanceof DeploymentMBean == false)
+ return null;
+ return ((DeploymentMBean) top).getObjectName();
+ }
+
public DeploymentContext getParent()
{
return parent;
}
+
+ public ObjectName getParentName()
+ {
+ DeploymentContext parent = getParent();
+ if (parent == null || parent instanceof DeploymentMBean == false)
+ return null;
+ return ((DeploymentMBean) parent).getObjectName();
+ }
public void setParent(DeploymentContext parent)
{
@@ -579,6 +653,18 @@
return new ArrayList<DeploymentContext>(children);
}
+ public List<ObjectName> getChildNames()
+ {
+ List<DeploymentContext> children = getChildren();
+ List<ObjectName> result = new ArrayList<ObjectName>();
+ for (DeploymentContext child : children)
+ {
+ if (child instanceof DeploymentMBean)
+ result.add(((DeploymentMBean) child).getObjectName());
+ }
+ return result;
+ }
+
public void addChild(DeploymentContext child)
{
if (child == null)
@@ -586,6 +672,8 @@
if (children == null)
children = new TreeSet<DeploymentContext>(comparator);
children.add(child);
+ if (server != null)
+ registerMBeans(child, true);
}
public boolean removeChild(DeploymentContext child)
@@ -594,6 +682,8 @@
throw new IllegalArgumentException("Null child");
if (children == null)
return false;
+ if (server != null)
+ unregisterMBeans(child, true);
return children.remove(child);
}
@@ -607,12 +697,26 @@
return Collections.unmodifiableList(components);
}
+ public List<ObjectName> getComponentNames()
+ {
+ List<DeploymentContext> components = getComponents();
+ List<ObjectName> result = new ArrayList<ObjectName>();
+ for (DeploymentContext component : components)
+ {
+ if (component instanceof DeploymentMBean)
+ result.add(((DeploymentMBean) component).getObjectName());
+ }
+ return result;
+ }
+
public void addComponent(DeploymentContext component)
{
if (component == null)
throw new IllegalArgumentException("Null component");
deployed();
components.add(component);
+ if (server != null)
+ registerMBeans(component, true);
log.debug("Added component " + component.getName() + " to " + getName());
}
@@ -621,6 +725,8 @@
if (component == null)
throw new IllegalArgumentException("Null component");
+ if (server != null)
+ unregisterMBeans(component, true);
List<DeploymentContext> componentComponents = component.getComponents();
if (componentComponents.isEmpty() == false)
log.warn("Removing component " + name + " which still has components " + componentComponents);
@@ -660,6 +766,80 @@
}
}
+ public MutableAttachments getTransientAttachments()
+ {
+ return transientAttachments;
+ }
+
+ public MutableAttachments getTransientManagedObjects()
+ {
+ return transientManagedObjects;
+ }
+
+ public String listAttachments(boolean detail)
+ {
+ Set<String> processed = new HashSet<String>();
+ StringBuilder result = new StringBuilder();
+ result.append("<table>");
+ result.append("<tr><th>Attachment</th><th>Created</th><th>Referenced</th>");
+ if (detail)
+ result.append("<th>Contents</th>");
+
+ result.append("<tr><td>Predetermined</td></tr>");
+ listAttachments(result, getPredeterminedManagedObjects(), detail, processed);
+ result.append("<tr><td>Managed Objects</td></tr>");
+ listAttachments(result, getTransientManagedObjects(), detail, processed);
+ result.append("<tr><td>Transient</td></tr>");
+ listAttachments(result, getTransientAttachments(), detail, processed);
+ result.append("</table>");
+ return result.toString();
+ }
+
+ protected static void listAttachments(StringBuilder builder, Attachments attachments, boolean detail, Set<String> processed)
+ {
+ TrackingMutableAttachments tracking = null;
+ if (attachments instanceof TrackingMutableAttachments)
+ tracking = (TrackingMutableAttachments) attachments;
+
+ for (Map.Entry<String, Object> attachment : attachments.getAttachments().entrySet())
+ {
+ String name = attachment.getKey();
+ List<String> referenced = Collections.emptyList();
+ if (tracking != null)
+ {
+ Set<String> deployers = tracking.getReferenced(name);
+ if (deployers != null)
+ referenced = new ArrayList<String>(tracking.getReferenced(name));
+ }
+ int row = 0;
+ while (row < 1 || row < referenced.size())
+ {
+ builder.append("<tr>");
+ if (row == 0)
+ {
+ builder.append("<td>`--").append(name).append("</td>");
+ if (tracking != null)
+ builder.append("<td>").append(tracking.getCreated(name)).append("</td>");
+ else
+ builder.append("<td/>");
+ }
+ else
+ {
+ builder.append("<td/><td/>");
+ }
+ if (tracking != null && row < referenced.size())
+ builder.append("<td>").append(referenced.get(row)).append("</td>");
+ else
+ builder.append("<td/>");
+ if (row == 0 && detail)
+ builder.append("<td>").append(attachment.getValue()).append("</td>");
+ builder.append("</tr>");
+ ++row;
+ }
+ builder.append("</tr>");
+ }
+ }
+
public void visit(DeploymentContextVisitor visitor) throws DeploymentException
{
if (visitor == null)
@@ -771,7 +951,84 @@
{
cleanupRepository(this);
}
+
+ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
+ {
+ this.server = server;
+ return name;
+ }
+
+ public void postRegister(Boolean registrationDone)
+ {
+ if (registrationDone)
+ registerMBeans(this, false);
+ }
+ public void preDeregister() throws Exception
+ {
+ unregisterMBeans(this, false);
+ }
+
+ public void postDeregister()
+ {
+ }
+
+ /**
+ * Register mbeans
+ *
+ * @param context the context
+ * @param registerContext whether to register the context or just its children and components
+ */
+ protected void registerMBeans(DeploymentContext context, boolean registerContext)
+ {
+ if (registerContext && context instanceof DeploymentMBean)
+ {
+ try
+ {
+ DeploymentMBean depMBean = (DeploymentMBean) context;
+ server.registerMBean(context, depMBean.getObjectName());
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to register deployment mbean " + context.getName(), e);
+ }
+ }
+ List<DeploymentContext> children = context.getChildren();
+ for (DeploymentContext child : children)
+ registerMBeans(child, true);
+ List<DeploymentContext> components = context.getComponents();
+ for (DeploymentContext component : components)
+ registerMBeans(component, false);
+ }
+
+ /**
+ * Unregister mbeans
+ *
+ * @param context the context
+ * @param unregisterContext whether to unregister the context or just its children and components
+ */
+ protected void unregisterMBeans(DeploymentContext context, boolean unregisterContext)
+ {
+ if (unregisterContext && context instanceof DeploymentMBean)
+ {
+ try
+ {
+ DeploymentMBean depMBean = (DeploymentMBean) context;
+ server.unregisterMBean(depMBean.getObjectName());
+ }
+ catch (Exception e)
+ {
+ log.trace("Unable to unregister deployment mbean " + context.getName(), e);
+ }
+ }
+ List<DeploymentContext> children = context.getChildren();
+ for (DeploymentContext child : children)
+ unregisterMBeans(child, true);
+ List<DeploymentContext> components = context.getComponents();
+ for (DeploymentContext component : components)
+ unregisterMBeans(component, false);
+ }
+
@Override
public String toString()
{
Added: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContextMBean.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContextMBean.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContextMBean.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -0,0 +1,41 @@
+/*
+* 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.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentMBean;
+
+/**
+ * AbstractDeploymentContextMBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface AbstractDeploymentContextMBean extends DeploymentMBean
+{
+ /**
+ * List the attachments as an html table
+ *
+ * @param detail whether to show the attachment
+ * @return the html formatted string
+ */
+ String listAttachments(boolean detail);
+}
Modified: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -21,13 +21,21 @@
*/
package org.jboss.deployers.structure.spi.helpers;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.concurrent.CopyOnWriteArrayList;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.classloading.spi.RealClassLoader;
import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.DeploymentException;
@@ -38,6 +46,7 @@
import org.jboss.deployers.structure.spi.ClassLoaderFactory;
import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
+import org.jboss.deployers.structure.spi.DeploymentMBean;
import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
@@ -53,7 +62,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision: 59630 $
*/
-public class ComponentDeploymentContext implements DeploymentContext
+public class ComponentDeploymentContext implements DeploymentContext, ComponentDeploymentContextMBean, MBeanRegistration
{
/** The serialVersionUID */
private static final long serialVersionUID = -5105972679660633071L;
@@ -64,6 +73,12 @@
/** The name */
private String name;
+ /** The object name */
+ private ObjectName objectName;
+
+ /** The server */
+ private MBeanServer server;
+
/** The controller context names - should be serializable */
private Set<Object> controllerContextNames;
@@ -77,10 +92,10 @@
private List<DeploymentContext> components = new CopyOnWriteArrayList<DeploymentContext>();
/** The attachments */
- private transient MutableAttachments transientAttachments = AttachmentsFactory.createMutableAttachments();
+ private transient MutableAttachments transientAttachments = new TrackingMutableAttachments(AttachmentsFactory.createMutableAttachments());
/** The managed objects */
- private transient MutableAttachments transientManagedObjects = AttachmentsFactory.createMutableAttachments();
+ private transient MutableAttachments transientManagedObjects = new TrackingMutableAttachments(AttachmentsFactory.createMutableAttachments());
/** The scope */
private ScopeKey scope;
@@ -117,6 +132,25 @@
return name;
}
+ public ObjectName getObjectName()
+ {
+ if (objectName == null)
+ {
+ String name = getName();
+ name = name.replace("\"", """);
+ String temp = "jboss.deployment:id=\"" + name + "\",type=Component";
+ try
+ {
+ objectName = new ObjectName(temp);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new RuntimeException("Error creating object name: " + temp, e);
+ }
+ }
+ return objectName;
+ }
+
public Set<Object> getControllerContextNames()
{
return controllerContextNames != null ? Collections.unmodifiableSet(controllerContextNames) : null;
@@ -242,6 +276,15 @@
{
return parent.getClassLoader();
}
+
+ public ObjectName getClassLoaderName()
+ {
+ ClassLoader classLoader = getClassLoader();
+ if (classLoader == null || classLoader instanceof RealClassLoader == false)
+ return null;
+
+ return ((RealClassLoader) classLoader).getObjectName();
+ }
public void setClassLoader(ClassLoader classLoader)
{
@@ -270,11 +313,27 @@
{
return parent.getTopLevel();
}
+
+ public ObjectName getTopLevelName()
+ {
+ DeploymentContext top = getTopLevel();
+ if (top == null || top instanceof DeploymentMBean == false)
+ return null;
+ return ((DeploymentMBean) top).getObjectName();
+ }
public DeploymentContext getParent()
{
return parent;
}
+
+ public ObjectName getParentName()
+ {
+ DeploymentContext parent = getParent();
+ if (parent == null || parent instanceof DeploymentMBean == false)
+ return null;
+ return ((DeploymentMBean) parent).getObjectName();
+ }
public void setParent(DeploymentContext parent)
{
@@ -285,6 +344,11 @@
{
return Collections.emptyList();
}
+
+ public List<ObjectName> getChildNames()
+ {
+ return Collections.emptyList();
+ }
public void addChild(DeploymentContext child)
{
@@ -316,11 +380,25 @@
return Collections.unmodifiableList(components);
}
+ public List<ObjectName> getComponentNames()
+ {
+ List<DeploymentContext> components = getComponents();
+ List<ObjectName> result = new ArrayList<ObjectName>();
+ for (DeploymentContext component : components)
+ {
+ if (component instanceof DeploymentMBean)
+ result.add(((DeploymentMBean) component).getObjectName());
+ }
+ return result;
+ }
+
public void addComponent(DeploymentContext component)
{
if (component == null)
throw new IllegalArgumentException("Null component");
components.add(component);
+ if (server != null)
+ registerMBeans(component, true);
}
public boolean removeComponent(DeploymentContext component)
@@ -328,6 +406,8 @@
if (component == null)
throw new IllegalArgumentException("Null component");
boolean result = components.remove(component);
+ if (server != null)
+ unregisterMBeans(component, true);
component.cleanup();
return result;
}
@@ -336,7 +416,7 @@
{
return parent.getResourceClassLoader();
}
-
+
public DeploymentResourceLoader getResourceLoader()
{
return parent.getResourceLoader();
@@ -347,6 +427,70 @@
return parent.getDependencyInfo();
}
+ public String listAttachments(boolean detail)
+ {
+ Set<String> processed = new HashSet<String>();
+ StringBuilder result = new StringBuilder();
+ result.append("<table>");
+ result.append("<tr><th>Attachment</th><th>Created</th><th>Referenced</th>");
+ if (detail)
+ result.append("<th>Contents</th>");
+
+ result.append("<tr><td>Predetermined</td></tr>");
+ listAttachments(result, getPredeterminedManagedObjects(), detail, processed);
+ result.append("<tr><td>Managed Objects</td></tr>");
+ listAttachments(result, getTransientManagedObjects(), detail, processed);
+ result.append("<tr><td>Transient</td></tr>");
+ listAttachments(result, getTransientAttachments(), detail, processed);
+ result.append("</table>");
+ return result.toString();
+ }
+
+ protected static void listAttachments(StringBuilder builder, Attachments attachments, boolean detail, Set<String> processed)
+ {
+ TrackingMutableAttachments tracking = null;
+ if (attachments instanceof TrackingMutableAttachments)
+ tracking = (TrackingMutableAttachments) attachments;
+
+ for (Map.Entry<String, Object> attachment : attachments.getAttachments().entrySet())
+ {
+ String name = attachment.getKey();
+ List<String> referenced = Collections.emptyList();
+ if (tracking != null)
+ {
+ Set<String> deployers = tracking.getReferenced(name);
+ if (deployers != null)
+ referenced = new ArrayList<String>(tracking.getReferenced(name));
+ }
+ int row = 0;
+ while (row < 1 || row < referenced.size())
+ {
+ builder.append("<tr>");
+ if (row == 0)
+ {
+ builder.append("<td>`--").append(name).append("</td>");
+ if (tracking != null)
+ builder.append("<td>").append(tracking.getCreated(name)).append("</td>");
+ else
+ builder.append("<td/>");
+ }
+ else
+ {
+ builder.append("<td/><td/>");
+ }
+ if (tracking != null && row < referenced.size())
+ builder.append("<td>").append(referenced.get(row)).append("</td>");
+ else
+ builder.append("<td/>");
+ if (row == 0 && detail)
+ builder.append("<td>").append(attachment.getValue()).append("</td>");
+ builder.append("</tr>");
+ ++row;
+ }
+ builder.append("</tr>");
+ }
+ }
+
public void visit(DeploymentContextVisitor visitor) throws DeploymentException
{
if (visitor == null)
@@ -479,6 +623,77 @@
AbstractDeploymentContext.cleanupRepository(this);
}
+ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
+ {
+ this.server = server;
+ return name;
+ }
+
+ public void postRegister(Boolean registrationDone)
+ {
+ if (registrationDone)
+ registerMBeans(this, false);
+ }
+
+ public void preDeregister() throws Exception
+ {
+ unregisterMBeans(this, false);
+ }
+
+ public void postDeregister()
+ {
+ }
+
+ /**
+ * Register mbeans
+ *
+ * @param context the context
+ * @param registerContext whether to register the context or just its children and components
+ */
+ protected void registerMBeans(DeploymentContext context, boolean registerContext)
+ {
+ if (registerContext && context instanceof DeploymentMBean)
+ {
+ try
+ {
+ DeploymentMBean depMBean = (DeploymentMBean) context;
+ server.registerMBean(context, depMBean.getObjectName());
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to register deployment mbean " + context.getName(), e);
+ }
+ }
+ List<DeploymentContext> components = context.getComponents();
+ for (DeploymentContext component : components)
+ registerMBeans(component, false);
+ }
+
+ /**
+ * Unregister mbeans
+ *
+ * @param context the context
+ * @param unregisterContext whether to unregister the context or just its children and components
+ */
+ protected void unregisterMBeans(DeploymentContext context, boolean unregisterContext)
+ {
+ if (unregisterContext && context instanceof DeploymentMBean)
+ {
+ try
+ {
+ DeploymentMBean depMBean = (DeploymentMBean) context;
+ server.unregisterMBean(depMBean.getObjectName());
+ }
+ catch (Exception e)
+ {
+ log.trace("Unable to unregister deployment mbean " + context.getName(), e);
+ }
+ }
+ List<DeploymentContext> components = context.getComponents();
+ for (DeploymentContext component : components)
+ unregisterMBeans(component, false);
+ }
+
public String toString()
{
StringBuilder buffer = new StringBuilder();
Added: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContextMBean.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContextMBean.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContextMBean.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -0,0 +1,41 @@
+/*
+* 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.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentMBean;
+
+/**
+ * ComponentDeploymentContextMBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ComponentDeploymentContextMBean extends DeploymentMBean
+{
+ /**
+ * List the attachments as an html table
+ *
+ * @param detail whether to show the attachment
+ * @return the html formatted string
+ */
+ String listAttachments(boolean detail);
+}
Added: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/DeployerTracking.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/DeployerTracking.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/DeployerTracking.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -0,0 +1,64 @@
+/*
+* 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.helpers;
+
+import java.util.Stack;
+
+/**
+ * DeployerTracking.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerTracking
+{
+ /** The thread local stack containg the current deployer */
+ private static ThreadLocal<Stack<String>> currentDeployer = new ThreadLocal<Stack<String>>()
+ {
+ protected Stack<String> initialValue()
+ {
+ return new Stack<String>();
+ }
+ };
+
+ /**
+ * Get the current deployer
+ *
+ * @return the name of the current deployer
+ */
+ public static String getCurrentDeployer()
+ {
+ if (currentDeployer.get().isEmpty())
+ return "UNKNOWN";
+ return currentDeployer.get().peek();
+ }
+
+ public static void push(String deployer)
+ {
+ currentDeployer.get().push(deployer);
+ }
+
+ public static void pop()
+ {
+ currentDeployer.get().pop();
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/TrackingMutableAttachments.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/TrackingMutableAttachments.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/TrackingMutableAttachments.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -0,0 +1,254 @@
+/*
+* 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.helpers;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+
+/**
+ * TrackingMutableAttachments.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TrackingMutableAttachments implements MutableAttachments
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The delegate */
+ private MutableAttachments delegate;
+
+ /** The attachment creator */
+ private Map<String, String> createdDeployer = new ConcurrentHashMap<String, String>();
+
+ /** The attachment referencer */
+ private Map<String, Set<String>> referencedDeployer = new ConcurrentHashMap<String, Set<String>>();
+
+ /**
+ * Create a new TrackingMutableAttachments.
+ *
+ * @param delegate the delegate
+ */
+ public TrackingMutableAttachments(MutableAttachments delegate)
+ {
+ if (delegate == null)
+ throw new IllegalArgumentException("Null delegate");
+ this.delegate = delegate;
+ }
+
+ /**
+ * Get the deployer that created an attachment
+ *
+ * @param name the attachment name
+ * @return the name or null if was predetermined
+ */
+ public String getCreated(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ return createdDeployer.get(name);
+ }
+
+ /**
+ * Get the deployers that referenced an attachment
+ *
+ * @param name the attachment name
+ * @return the name or null if nothing referenced it
+ */
+ public Set<String> getReferenced(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ Set<String> result = referencedDeployer.get(name);
+ if (result == null)
+ return null;
+ return Collections.unmodifiableSet(result);
+ }
+
+ /**
+ * An attachment is being created
+ *
+ * @param name the name
+ */
+ void created(String name)
+ {
+ createdDeployer.put(name, DeployerTracking.getCurrentDeployer());
+ }
+
+ /**
+ * An attachment is being referenced
+ *
+ * @param name the name
+ */
+ void referenced(String name)
+ {
+ Set<String> deployers = referencedDeployer.get(name);
+ if (deployers == null)
+ {
+ deployers = new CopyOnWriteArraySet<String>();
+ referencedDeployer.put(name, deployers);
+ }
+ deployers.add(DeployerTracking.getCurrentDeployer());
+ }
+
+ public <T> T addAttachment(Class<T> type, T attachment)
+ {
+ T result = delegate.addAttachment(type, attachment);
+ if (result == null)
+ created(type.getName());
+ else
+ referenced(type.getName());
+ return result;
+ }
+
+ public Object addAttachment(String name, Object attachment)
+ {
+ Object result = delegate.addAttachment(name, attachment);
+ if (result == null)
+ created(name);
+ else
+ referenced(name);
+ return result;
+ }
+
+ public <T> T addAttachment(String name, T attachment, Class<T> expectedType)
+ {
+ T result = delegate.addAttachment(name, attachment, expectedType);
+ if (result == null)
+ created(name);
+ else
+ referenced(name);
+ return result;
+ }
+
+ public void clear()
+ {
+ createdDeployer.clear();
+ referencedDeployer.clear();
+ delegate.clear();
+ }
+
+ public void clearChangeCount()
+ {
+ delegate.clearChangeCount();
+ }
+
+ public <T> T getAttachment(Class<T> type)
+ {
+ T result = delegate.getAttachment(type);
+ if (result != null)
+ referenced(type.getName());
+ return result;
+ }
+
+ public <T> T getAttachment(String name, Class<T> expectedType)
+ {
+ T result = delegate.getAttachment(name, expectedType);
+ if (result != null)
+ referenced(name);
+ return result;
+ }
+
+ public Object getAttachment(String name)
+ {
+ Object result = delegate.getAttachment(name);
+ if (result != null)
+ referenced(name);
+ return result;
+ }
+
+ public Map<String, Object> getAttachments()
+ {
+ return delegate.getAttachments();
+ }
+
+ public int getChangeCount()
+ {
+ return delegate.getChangeCount();
+ }
+
+ public boolean hasAttachments()
+ {
+ return delegate.hasAttachments();
+ }
+
+ public boolean isAttachmentPresent(Class<?> type)
+ {
+ boolean result = delegate.isAttachmentPresent(type);
+ if (result)
+ referenced(type.getName());
+ return result;
+ }
+
+ public boolean isAttachmentPresent(String name, Class<?> expectedType)
+ {
+ boolean result = delegate.isAttachmentPresent(name, expectedType);
+ if (result)
+ referenced(name);
+ return result;
+ }
+
+ public boolean isAttachmentPresent(String name)
+ {
+ boolean result = delegate.isAttachmentPresent(name);
+ if (result)
+ referenced(name);
+ return result;
+ }
+
+ public <T> T removeAttachment(Class<T> type)
+ {
+ T result = delegate.removeAttachment(type);
+ if (result != null)
+ referenced(type.getName());
+ return result;
+ }
+
+ public <T> T removeAttachment(String name, Class<T> expectedType)
+ {
+ T result = delegate.removeAttachment(name, expectedType);
+ if (result != null)
+ referenced(name);
+ return result;
+ }
+
+ public Object removeAttachment(String name)
+ {
+ Object result = delegate.removeAttachment(name);
+ if (result != null)
+ referenced(name);
+ return result;
+ }
+
+ public void setAttachments(Map<String, Object> map)
+ {
+ delegate.setAttachments(map);
+ createdDeployer.clear();
+ referencedDeployer.clear();
+ }
+}
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -44,7 +44,7 @@
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class AbstractVFSDeploymentContext extends AbstractDeploymentContext implements VFSDeploymentContext
+public class AbstractVFSDeploymentContext extends AbstractDeploymentContext implements VFSDeploymentContext, AbstractVFSDeploymentContextMBean
{
/** The serialVersionUID */
private static final long serialVersionUID = 4474515937180482776L;
Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContextMBean.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContextMBean.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContextMBean.java 2008-10-06 15:17:46 UTC (rev 79155)
@@ -0,0 +1,57 @@
+/*
+* 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.vfs.plugins.structure;
+
+import java.util.List;
+
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContextMBean;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * AbstractVFSDeploymentContextMBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface AbstractVFSDeploymentContextMBean extends AbstractDeploymentContextMBean
+{
+ /**
+ * Get the root file
+ *
+ * @return the root
+ */
+ VirtualFile getRoot();
+
+ /**
+ * Get the meta data locations
+ *
+ * @return the meta data locations
+ */
+ List<VirtualFile> getMetaDataLocations();
+
+ /**
+ * Get the class path
+ *
+ * @return the class path
+ */
+ List<VirtualFile> getClassPath();
+}
Modified: projects/jboss-deployers/trunk/pom.xml
===================================================================
--- projects/jboss-deployers/trunk/pom.xml 2008-10-06 14:23:27 UTC (rev 79154)
+++ projects/jboss-deployers/trunk/pom.xml 2008-10-06 15:17:46 UTC (rev 79155)
@@ -25,6 +25,7 @@
<version.jboss.mdr>2.0.0.CR1</version.jboss.mdr>
<version.jboss.microcontainer>2.0.0.CR1</version.jboss.microcontainer>
<version.jboss.classloader>2.0.0.CR2</version.jboss.classloader>
+ <version.jboss.classloading.spi>5.0.0.CR2</version.jboss.classloading.spi>
<version.jboss.common.core>2.2.8.GA</version.jboss.common.core>
<version.jboss.logging.spi>2.0.5.GA</version.jboss.logging.spi>
<version.jboss.logging.log4j>2.0.5.GA</version.jboss.logging.log4j>
@@ -271,6 +272,11 @@
<version>${version.jboss.classloader}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.integration</groupId>
+ <artifactId>jboss-classloading-spi</artifactId>
+ <version>${version.jboss.classloading.spi}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.man</groupId>
<artifactId>jboss-managed</artifactId>
<version>${version.jboss.man}</version>
More information about the jboss-cvs-commits
mailing list