[jboss-cvs] JBossAS SVN: r72206 - trunk/ejb3/src/main/org/jboss/ejb3/deployers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 15 05:58:44 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-04-15 05:58:44 -0400 (Tue, 15 Apr 2008)
New Revision: 72206
Added:
trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASKernel.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java
Log:
EJBTHREE-1278, update to override KernelAbstraction
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java 2008-04-15 09:44:29 UTC (rev 72205)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java 2008-04-15 09:58:44 UTC (rev 72206)
@@ -117,7 +117,9 @@
//di.deployedObject = container.getObjectName();
unit.addAttachment(ClientENCInjectionContainer.class, container);
- getKernelAbstraction().install(container.getObjectName().getCanonicalName(), container.getDependencyPolicy(), container);
+ JBoss5DeploymentUnit ejb3Unit = new JBoss5DeploymentUnit(unit);
+ getKernelAbstraction().install(container.getObjectName().getCanonicalName(),
+ container.getDependencyPolicy(), ejb3Unit, container);
}
catch(Exception e)
{
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java 2008-04-15 09:44:29 UTC (rev 72205)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java 2008-04-15 09:58:44 UTC (rev 72206)
@@ -49,7 +49,7 @@
{
super(ejb3Unit, deploymentScope, metaData, persistenceUnitsMetaData);
this.jbossUnit = jbossUnit;
- kernelAbstraction = new MCKernelAbstraction(kernel, mbeanServer);
+ kernelAbstraction = new JBossASKernel(kernel);
// todo maybe mbeanServer should be injected?
this.mbeanServer = mbeanServer;
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java 2008-04-15 09:44:29 UTC (rev 72205)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentScope.java 2008-04-15 09:58:44 UTC (rev 72206)
@@ -25,39 +25,67 @@
import java.util.concurrent.ConcurrentHashMap;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployment.spi.DeploymentEndpointResolver;
+import org.jboss.deployment.spi.EndpointInfo;
+import org.jboss.deployment.spi.EndpointType;
import org.jboss.ejb3.DeploymentScope;
+import org.jboss.ejb3.EJBContainer;
import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.logging.Logger;
/**
* Abstraction for an EAR/WAR or anything that scopes EJB deployments
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @author adrian at jboss.org
+ * @author Scott.Stark at jboss.org
* @version $Revision: 55144 $
*/
public class JBoss5DeploymentScope implements DeploymentScope
{
+ public static final String ATTACHMENT_KEY = "org.jboss.ejb3.deployers.JBoss5DeploymentScope.deployments";
+ private static final Logger log = Logger.getLogger(JBoss5DeploymentScope.class);
+ /** The Map<String,Ejb3Deployment> of the deployment vfs path name to deployment */
private ConcurrentHashMap<String, Ejb3Deployment> deployments;
+ /** The deployment endpoint resolver implementation */
+ private DeploymentEndpointResolver endpointResolver;
+ /** The parent deployment short name */
private String shortName;
+ /** The deployment short name minus any .suffix */
private String baseName;
+ @SuppressWarnings("unchecked")
public JBoss5DeploymentScope(VFSDeploymentUnit parent)
{
this.shortName = parent.getSimpleName();
this.baseName = shortName;
-
+
int idx = shortName.lastIndexOf('.');
if( idx > 0 )
baseName = shortName.substring(0, idx);
-
- deployments = (ConcurrentHashMap<String, Ejb3Deployment>)parent.getAttachment("EJB_DEPLOYMENTS");
+
+ // Create the deployment map attachment if it does not exist
+ deployments = (ConcurrentHashMap<String, Ejb3Deployment>)parent.getAttachment(ATTACHMENT_KEY);
if (deployments == null)
{
deployments = new ConcurrentHashMap<String, Ejb3Deployment>();
- parent.addAttachment("EJB_DEPLOYMENTS", deployments);
+ parent.addAttachment(ATTACHMENT_KEY, deployments);
}
+ // Look for the endpoint resolver
+ endpointResolver = parent.getAttachment(DeploymentEndpointResolver.class);
+ if(endpointResolver == null)
+ throw new IllegalStateException("No DeploymentEndpointResolver found in deployment: "+parent);
}
+ public DeploymentEndpointResolver getEndpointResolver()
+ {
+ return endpointResolver;
+ }
+ public void setEndpointResolver(DeploymentEndpointResolver endpointResolver)
+ {
+ this.endpointResolver = endpointResolver;
+ }
+
public Collection<Ejb3Deployment> getEjbDeployments()
{
return deployments.values();
@@ -65,12 +93,18 @@
public void register(Ejb3Deployment deployment)
{
- deployments.put(deployment.getDeploymentUnit().getShortName(), deployment);
+ String pathName = deployment.getDeploymentUnit().getRootFile().getPathName();
+ if(pathName.startsWith(shortName))
+ pathName = pathName.substring(shortName.length()+1);
+ deployments.put(pathName, deployment);
}
public void unregister(Ejb3Deployment deployment)
{
- deployments.remove(deployment.getDeploymentUnit().getShortName());
+ String pathName = deployment.getDeploymentUnit().getRootFile().getPathName();
+ if(pathName.startsWith(shortName))
+ pathName = pathName.substring(shortName.length()+1);
+ deployments.remove(pathName);
}
public Ejb3Deployment findRelativeDeployment(String relativeName)
@@ -82,6 +116,46 @@
return deployments.get(relativeName);
}
+ @SuppressWarnings("unchecked")
+ public EJBContainer getEjbContainer(Class businessIntf, String vfsContext)
+ {
+ EJBContainer container = null;
+ // Get the deployment endpoint
+ EndpointInfo endpoint = endpointResolver.getEndpointInfo(businessIntf, EndpointType.EJB, vfsContext);
+ if(endpoint != null)
+ {
+ log.debug("Found endpoint for interface: "+businessIntf+", endpoint: "+endpoint);
+ Ejb3Deployment deployment = deployments.get(endpoint.getPathName());
+ container = deployment.getEjbContainerForEjbName(endpoint.getName());
+ }
+ else
+ {
+ log.debug("Failed to find endpoint for interface: "+businessIntf);
+ }
+ return container;
+ }
+
+ @SuppressWarnings("unchecked")
+ public EJBContainer getEjbContainer(String ejbLink, Class businessIntf, String vfsContext)
+ {
+ EJBContainer container = null;
+ // First try the ejbLink
+ EndpointInfo endpoint = endpointResolver.getEndpointInfo(ejbLink, EndpointType.EJB, vfsContext);
+ if(endpoint != null)
+ {
+ log.debug("Found endpoint for ejbLink: "+ejbLink+", endpoint: "+endpoint);
+ Ejb3Deployment deployment = deployments.get(endpoint.getPathName());
+ container = deployment.getEjbContainerForEjbName(endpoint.getName());
+ }
+ else
+ {
+ log.debug("Failed to find endpoint for ejbLink: "+ejbLink);
+ // Try the business interface
+ container = getEjbContainer(businessIntf, vfsContext);
+ }
+ return container;
+ }
+
public String getName()
{
return shortName;
@@ -96,5 +170,4 @@
{
return baseName;
}
-
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java 2008-04-15 09:44:29 UTC (rev 72205)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java 2008-04-15 09:58:44 UTC (rev 72206)
@@ -66,11 +66,29 @@
this.interceptorInfoRepository = new InterceptorInfoRepository(classLoader);
}
+ public Object addAttachment(String name, Object attachment)
+ {
+ return unit.addAttachment(name, attachment);
+ }
+ public Object getAttachment(String name)
+ {
+ return unit.getAttachment(name);
+ }
+ public Object removeAttachment(String name)
+ {
+ return unit.removeAttachment(name);
+ }
+
public VirtualFile getRootFile()
{
return unit.getFile("");
}
+ public String getRelativePath()
+ {
+ return unit.getRelativePath();
+ }
+
public URL getRelativeURL(String jar)
{
try
Added: trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASKernel.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASKernel.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/JBossASKernel.java 2008-04-15 09:58:44 UTC (rev 72206)
@@ -0,0 +1,290 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.ejb3.deployers;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.RuntimeMBeanException;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDemandMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.beans.metadata.spi.DemandMetaData;
+import org.jboss.beans.metadata.spi.SupplyMetaData;
+import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.DeploymentUnit;
+import org.jboss.ejb3.KernelAbstraction;
+import org.jboss.ejb3.MCDependencyPolicy;
+import org.jboss.ejb3.embedded.resource.RARDeployment;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+import org.jboss.logging.Logger;
+
+/**
+ * The JBossAS implementation of the ejb3 KernelAbstraction integration api
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class JBossASKernel
+ implements KernelAbstraction
+{
+ private static Logger log = Logger.getLogger(JBossASKernel.class);
+ private MBeanServer mbeanServer;
+ private Kernel kernel;
+
+ public JBossASKernel(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+
+ public MBeanServer getMbeanServer()
+ {
+ return mbeanServer;
+ }
+ public void setMbeanServer(MBeanServer mbeanServer)
+ {
+ this.mbeanServer = mbeanServer;
+ }
+
+ public void install(String name, DependencyPolicy dependencies,
+ DeploymentUnit unit, Object service)
+ {
+ // Look for the kernel deployment
+ KernelDeployment deployment = (KernelDeployment) unit.getAttachment(KernelDeployment.class.getName());
+ if(deployment == null)
+ {
+ AbstractKernelDeployment akd = new AbstractKernelDeployment();
+ akd.setBeanFactories(new ArrayList<BeanMetaDataFactory>());
+ deployment = akd;
+ deployment.setName(unit.getShortName());
+ unit.addAttachment(KernelDeployment.class.getName(), deployment);
+ }
+
+ // Create the metadata for the bean to install
+ AbstractBeanMetaData bean = new AbstractBeanMetaData(name, service.getClass().getName());
+ bean.setConstructor(new AlreadyInstantiated(service));
+ MCDependencyPolicy policy = (MCDependencyPolicy) dependencies;
+ bean.setDepends(policy.getDependencies());
+ bean.setDemands(policy.getDemands());
+ bean.setSupplies(policy.getSupplies());
+ log.info("installing bean: " + name);
+ log.info(" with dependencies:");
+ for (Object obj : policy.getDependencies())
+ {
+ Object msgObject = obj;
+ if (obj instanceof AbstractDemandMetaData)
+ {
+ msgObject = ((AbstractDemandMetaData)obj).getDemand();
+ }
+ log.info("\t" + msgObject);
+ }
+ log.info(" and demands:");
+ for(DemandMetaData dmd : policy.getDemands())
+ {
+ log.info("\t" + dmd.getDemand());
+ }
+ log.info(" and supplies:");
+ for(SupplyMetaData smd : policy.getSupplies())
+ {
+ log.info("\t" + smd.getSupply());
+ }
+ // Just add the mc bean metadata to the unit
+ deployment.getBeanFactories().add(bean);
+ }
+
+ public void installMBean(ObjectName on, DependencyPolicy dependencies,
+ Object service)
+ {
+ if(mbeanServer == null)
+ throw new RuntimeException("No MBeanServer has been injected");
+
+ try
+ {
+ mbeanServer.registerMBean(service, on);
+ install(on.getCanonicalName(), dependencies, null, service);
+
+ // EJBTHREE-606: emulate the ServiceController calls
+ MBeanInfo info = mbeanServer.getMBeanInfo(on); // redundant call for speed
+ invokeOptionalMethod(on, info, "create");
+ invokeOptionalMethod(on, info, "start");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void uninstall(String name)
+ {
+
+
+ }
+
+ public Object getAttribute(ObjectName objectName, String attribute) throws Exception
+ {
+ String name = objectName.getCanonicalName();
+ KernelRegistryEntry entry = kernel.getRegistry().getEntry(name);
+ if (entry != null)
+ {
+ Object target = entry.getTarget();
+ Field field = target.getClass().getField(attribute);
+ return field.get(target);
+ }
+ return null;
+ }
+
+ public Set getMBeans(ObjectName query) throws Exception
+ {
+ Object target = kernel.getRegistry().getEntry(query);
+ Set set = new HashSet();
+ set.add(target);
+ return set;
+ }
+
+ public void uninstallMBean(ObjectName on)
+ {
+ try
+ {
+ // EJBTHREE-606: emulate the ServiceController calls
+ MBeanInfo info = mbeanServer.getMBeanInfo(on); // redundant call for speed
+ try
+ {
+ invokeOptionalMethod(on, info, "stop");
+ }
+ catch(Exception e)
+ {
+ log.warn("stop on " + on + " failed", e);
+ }
+ try
+ {
+ invokeOptionalMethod(on, info, "destroy");
+ }
+ catch(Exception e)
+ {
+ log.warn("destroy on " + on + " failed", e);
+ }
+
+ mbeanServer.unregisterMBean(on);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Object invoke(ObjectName objectName, String operationName, Object[] params, String[] signature) throws Exception
+ {
+ String name = objectName.getCanonicalName();
+ KernelRegistryEntry entry = kernel.getRegistry().getEntry(name);
+ if (entry != null)
+ {
+ Object target = entry.getTarget();
+ if (target instanceof RARDeployment)
+ {
+ RARDeployment deployment = (RARDeployment)target;
+ return deployment.invoke(operationName, params, signature);
+ }
+ else
+ {
+ Class[] types = new Class[signature.length];
+ for (int i = 0; i < signature.length; ++i)
+ {
+ types[i] = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
+ }
+ Method method = target.getClass().getMethod(operationName, types);
+ return method.invoke(target, params);
+ }
+ }
+ return null;
+ }
+
+ private boolean hasOperation(MBeanInfo info, String operationName)
+ {
+ for(MBeanOperationInfo operationInfo : info.getOperations())
+ {
+ if(operationInfo.getName().equals(operationName) == false)
+ continue;
+
+ // void return type
+ if(operationInfo.getReturnType().equals("void") == false)
+ continue;
+
+ // no parameters
+ if(operationInfo.getSignature().length != 0)
+ continue;
+
+ return true;
+ }
+
+ return false;
+ }
+ private void invokeOptionalMethod(ObjectName on, MBeanInfo info, String operationName)
+ throws InstanceNotFoundException, MBeanException, ReflectionException
+ {
+ Object params[] = { };
+ String signature[] = { };
+ if(hasOperation(info, operationName))
+ mbeanServer.invoke(on, operationName, params, signature);
+ }
+
+ public static class AlreadyInstantiated extends AbstractConstructorMetaData
+ {
+ private static final long serialVersionUID = 1L;
+
+ private Object bean;
+
+ public class Factory
+ {
+
+ public Object create()
+ {
+ return bean;
+ }
+ }
+
+ public AlreadyInstantiated(Object bean)
+ {
+ this.bean = bean;
+ this.setFactory(new AbstractValueMetaData(new Factory()));
+ this.setFactoryClass(Factory.class.getName());
+ this.setFactoryMethod("create");
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list