[jboss-cvs] JBossAS SVN: r77551 - in trunk/ejb3/src/main/org/jboss/ejb3: deployers and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 27 17:23:38 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-08-27 17:23:38 -0400 (Wed, 27 Aug 2008)
New Revision: 77551
Added:
trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyItem.java
trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyValueMetaData.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/client/ClientEJBHandler.java
trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
Log:
JBAS-5892, delay the loading of the JBossClientMetaData until the client container class loader is in place
Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientEJBHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientEJBHandler.java 2008-08-27 21:10:45 UTC (rev 77550)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientEJBHandler.java 2008-08-27 21:23:38 UTC (rev 77551)
@@ -26,26 +26,19 @@
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
-import java.util.Set;
import javax.ejb.EJB;
-import org.jboss.ejb3.clientmodule.EJBRemoteHandler;
import org.jboss.injection.AbstractHandler;
-import org.jboss.injection.EJBInjectionHandler;
import org.jboss.injection.InjectionContainer;
-import org.jboss.injection.InjectionUtil;
import org.jboss.injection.Injector;
-import org.jboss.injection.JndiPropertyInjector;
-import org.jboss.injection.lang.reflect.BeanProperty;
-import org.jboss.injection.lang.reflect.BeanPropertyFactory;
+
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.AbstractEJBReferenceMetaData;
import org.jboss.metadata.javaee.spec.AnnotatedEJBReferenceMetaData;
import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
import org.jboss.metadata.javaee.spec.EJBReferenceMetaData;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
-import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
/**
* @author Scott.Stark at jboss.org
Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java 2008-08-27 21:10:45 UTC (rev 77550)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java 2008-08-27 21:23:38 UTC (rev 77551)
@@ -51,6 +51,7 @@
import org.jboss.client.AppClientLauncher;
import org.jboss.dependency.spi.ControllerMode;
import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployment.dependency.JndiDependencyMetaData;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
@@ -81,7 +82,7 @@
private static final Logger log = Logger.getLogger(ClientLauncher.class);
private static final String VERSION = "$Revision$";
private static Throwable exception;
- /** The kernel */
+ /** The kernel for the client container */
private static Kernel kernel;
/** The deployer */
@@ -93,33 +94,23 @@
/** Additional classpath elements to client container classpath */
private static List<String> extraClassPath = new ArrayList<String>();
-
+ /**
+ * Access the client main class as loaded by the MC/client container. This
+ * class should be used to ensure that any static variable set in the class
+ * as a by-product of invoking the client main(String[]) method are seen.
+ * @return client main class object
+ */
public static Class<?> getTheMainClass()
{
return theMainClass;
}
/**
- * Convenience method for launching a client container.
+ * Convenience method to load the XML descriptor for the given applicationClientName.
+ * This does a lookup against the server for the xml metadata the client
+ * deployer bound.
*
- * @param xml
- * @param mainClassName
- * @param applicationClientName
- * @param args
- * @throws Exception
- */
- public static void launch(JBossClientMetaData xml, String mainClassName, String applicationClientName, String args[])
- throws Throwable
- {
- List<String> cp = Collections.emptyList();
- launch(xml, cp, mainClassName, applicationClientName, args, null);
- }
-
-
- /**
- * Convenience method to load the XML descriptor.
- *
- * @return
+ * @return the JBossClientMetaData
* @throws IOException
* @throws JBossXBException
*/
@@ -139,26 +130,46 @@
}
/**
+ * Calls {@link #launch(String, String, String[], Properties)}
+ */
+ public void launch(String clientClass, String clientName, String[] args)
+ throws Throwable
+ {
+ launch(clientClass, clientName, args, null);
+ }
+
+ /**
+ * Convenience method for launching a client container.
+ *
+ * @param xml
+ * @param mainClassName
+ * @param applicationClientName
+ * @param args
+ * @throws Exception
+ */
+ public static void launch(JBossClientMetaData xml, String mainClassName, String applicationClientName, String args[])
+ throws Throwable
+ {
+ List<String> cp = Collections.emptyList();
+ launch(xml, cp, mainClassName, applicationClientName, args, null);
+ }
+ /**
* The AppClientLauncher method for launching a client container.
*
* @param mainClassName - the class whose main(String[]) will be invoked
* @param clientName - the client name that maps to the server side JNDI ENC
* @param args - the args to pass to main method
+ * @param jndiEnv - jndi properties to pass to set as System properties
* @throws Throwable
*/
- public void launch(String mainClassName, String clientName, String args[])
- throws Throwable
- {
- launch(mainClassName, clientName, args, null);
- }
- public void launch(String mainClassName, String clientName, String args[],
+ public static void launch(String mainClassName, String clientName, String args[],
Properties jndiEnv)
throws Throwable
{
// Set the RMIClassLoaderSpi implementation to JBossRMIClassLoader
System.setProperty("java.rmi.server.RMIClassLoaderSpi", JBossRMIClassLoader.class.getName());
-
- JBossClientMetaData xml = loadXML(clientName);
+ // This is loaded lazily via a jndi dependency
+ JBossClientMetaData xml = null;
List<String> cp = loadClassPath(clientName);
launch(xml, cp, mainClassName, clientName, args, jndiEnv);
}
@@ -233,14 +244,17 @@
factory.setRoots(roots);
beanFactories.add(factory);
// ClientContainer(xml, mainClass, applicationClientName, jndiEnv);
- builder.addConstructorParameter(JBossClientMetaData.class.getName(), xml);
+ String classLoaderName = factory.getContextName();
+ if(classLoaderName == null)
+ classLoaderName = factory.getName() + ":" + factory.getVersion();
+ String metaDataJndiName = applicationClientName + "/metaData";
+ ValueMetaData xmlMD = new JndiDependencyValueMetaData(metaDataJndiName, jndiEnv, classLoaderName);
+ builder.addConstructorParameter(JBossClientMetaData.class.getName(), xmlMD);
+ //builder.addConstructorParameter(JBossClientMetaData.class.getName(), xml);
builder.addConstructorParameter(Class.class.getName(), mainClassName);
builder.addConstructorParameter(String.class.getName(), applicationClientName);
builder.addConstructorParameter(Properties.class.getName(), jndiEnv);
// Use vfs class loader as the ClientContainer class loader
- String classLoaderName = factory.getContextName();
- if(classLoaderName == null)
- classLoaderName = factory.getName() + ":" + factory.getVersion();
ValueMetaData classLoader = builder.createInject(classLoaderName);
builder.setClassLoader(classLoader);
BeanMetaData clientContainerMD = builder.getBeanMetaData();
@@ -252,6 +266,7 @@
if(beans.size() > 0)
deployment.setBeans(beans);
deploy(deployment);
+ validate();
KernelController controller = kernel.getController();
// ClientContainer
Added: trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyItem.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyItem.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyItem.java 2008-08-27 21:23:38 UTC (rev 77551)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.client;
+
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.logging.Logger;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class JndiDependencyItem extends AbstractDependencyItem
+ implements DependencyItem
+{
+private static final Logger log = Logger.getLogger(JndiDependencyItem.class);
+
+ /** The demand jndi name */
+ private String jndiName;
+ private Properties env;
+ private String classLoaderName;
+
+ JndiDependencyItem(String jndiName, Properties env, String classLoaderName)
+ {
+ this.jndiName = jndiName;
+ this.env = env;
+ this.classLoaderName = classLoaderName;
+ }
+
+ @Override
+ public boolean resolve(Controller controller)
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ ControllerContext cc = controller.getContext(classLoaderName, ControllerState.INSTALLED);
+ ClassLoader loader = (ClassLoader) cc.getTarget();
+ if(loader != null)
+ Thread.currentThread().setContextClassLoader(loader);
+ Properties jndiEnv = env;
+ if(jndiEnv == null)
+ jndiEnv = System.getProperties();
+ InitialContext ctx = new InitialContext(jndiEnv);
+ Object depends = ctx.lookup(jndiName);
+ super.setIDependOn(depends);
+ log.info("Resolved("+jndiName+")"+depends);
+ setResolved(true);
+ return isResolved();
+ }
+ catch(NameNotFoundException e)
+ {
+ log.debug("Jndi lookup failed", e);
+ }
+ catch(Throwable ignored)
+ {
+ log.debug("Unexpected error", ignored);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ setResolved(false);
+ return isResolved();
+ }
+
+ @Override
+ public void toString(JBossStringBuilder buffer)
+ {
+ super.toString(buffer);
+ buffer.append(" depend=").append(jndiName);
+ }
+
+ @Override
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ buffer.append(getName()).append(" depend ").append(jndiName);
+ }
+
+ @Override
+ public String toHumanReadableString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("JndiDepends: '");
+ builder.append(jndiName);
+ builder.append("'");
+ return builder.toString();
+ }
+}
Added: trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyValueMetaData.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyValueMetaData.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/JndiDependencyValueMetaData.java 2008-08-27 21:23:38 UTC (rev 77551)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.client;
+
+import java.util.Properties;
+
+import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class JndiDependencyValueMetaData extends AbstractDependencyValueMetaData
+{
+ private static final long serialVersionUID = 1;
+
+ /** The demand jndi name */
+ private String jndiName;
+ private Properties env;
+ private String classLoaderName;
+ private JndiDependencyItem depends;
+
+ public JndiDependencyValueMetaData(String jndiName, Properties env, String classLoaderName)
+ {
+ this.jndiName = jndiName;
+ this.env = env;
+ this.classLoaderName = classLoaderName;
+ }
+
+ @Override
+ public void initialVisit(MetaDataVisitor visitor)
+ {
+ depends = new JndiDependencyItem(jndiName, env, classLoaderName);
+ visitor.addDependency(depends);
+ visitor.initialVisit(this);
+ }
+
+ @Override
+ public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
+ {
+ return depends.getIDependOn();
+ }
+
+}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java 2008-08-27 21:10:45 UTC (rev 77550)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java 2008-08-27 21:23:38 UTC (rev 77551)
@@ -45,6 +45,7 @@
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.metadata.client.jboss.JBossClientMetaData;
+import org.jboss.metadata.ear.jboss.JBossAppMetaData;
import org.jboss.naming.Util;
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
@@ -84,6 +85,11 @@
this.linkDeploymentJndiName = linkDeploymentJndiName;
}
+ /**
+ * Deploy a client application
+ * @param unit - the application jar unit
+ * @param metaData - the metadata for the application
+ */
@Override
public void deploy(VFSDeploymentUnit unit, JBossClientMetaData metaData) throws DeploymentException
{
@@ -115,6 +121,23 @@
String uri = vf.toURI().toString();
cpURIs.add(uri);
}
+ // Also need to include the ear lib dir entries
+ VFSDeploymentUnit earUnit = unit.getParent();
+ List<VirtualFile> earClassPath = earUnit.getClassPath();
+ JBossAppMetaData earMD = earUnit.getAttachment(JBossAppMetaData.class);
+ String libDir = earMD.getLibraryDirectory();
+ if(libDir == null)
+ libDir = "lib";
+ String libDirPrefix = libDir + "/";
+ for(VirtualFile vf : earClassPath)
+ {
+ if(vf.getPathName().startsWith(libDirPrefix))
+ {
+ String uri = vf.toURI().toString();
+ cpURIs.add(uri);
+ }
+ }
+
encCtx.bind("classPathEntries", cpURIs);
// java:comp/UserTransaction -> UserTransaction
Util.createLinkRef(encCtx, "UserTransaction", "UserTransaction");
More information about the jboss-cvs-commits
mailing list