jboynes 2003/08/23 15:14:20
Modified: modules/core/src/conf client.mlet
modules/core/src/java/org/apache/geronimo/client
Launcher.java
Added: modules/core/src/java/org/apache/geronimo/client
AppClientContainer.java
AppClientContainerMBean.java
MainInvokerInterceptor.java
Removed: modules/core/src/java/org/apache/geronimo/client
AppClient.java AppClientMBean.java
Log:
Convert AppClient to a real Container
Set up interceptor stack to set up environment on run
Revision Changes Path
1.2 +6 -0 incubator-geronimo/modules/core/src/conf/client.mlet
Index: client.mlet
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/conf/client.mlet,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- client.mlet 16 Aug 2003 19:03:08 -0000 1.1
+++ client.mlet 23 Aug 2003 22:14:20 -0000 1.2
@@ -5,6 +5,12 @@
<ARG type="boolean" value="true" />
</MLET>
+<MLET CODE="org.apache.geronimo.deployment.dependency.DependencyService"
+ NAME="geronimo.boot:role=DependencyService"
+ ARCHIVE=""
+ >
+</MLET>
+
<MLET CODE="org.apache.geronimo.deployment.DeploymentController"
NAME="geronimo.deployment:role=DeploymentController"
ARCHIVE=""
1.2 +64 -10
incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/Launcher.java
Index: Launcher.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/Launcher.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Launcher.java 16 Aug 2003 19:03:09 -0000 1.1
+++ Launcher.java 23 Aug 2003 22:14:20 -0000 1.2
@@ -56,10 +56,17 @@
package org.apache.geronimo.client;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import javax.management.Attribute;
+import javax.management.AttributeList;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
@@ -77,6 +84,7 @@
import org.apache.geronimo.deployment.DeploymentException;
import org.apache.geronimo.jmx.JMXKernel;
import org.apache.geronimo.jmx.JMXUtil;
+import org.apache.geronimo.proxy.ProxyInvocation;
/**
* Launcher for J2EE Application Clients.
@@ -168,7 +176,7 @@
// throw new DeploymentException(e);
// }
- AppClient clientMBean = new AppClient(clientURL);
+ AppClientContainer clientMBean = new AppClientContainer();
clientName = JMXUtil.getObjectName("geronimo.client:url=" +
ObjectName.quote(clientURL.toString()));
try {
mbServer.registerMBean(clientMBean, clientName);
@@ -183,6 +191,44 @@
} catch (NotCompliantMBeanException e) {
throw new DeploymentException(e);
}
+
+ String mainClassName;
+ try {
+ Manifest manifest;
+ if (clientURL.toString().endsWith("/")) {
+ // unpacked
+ URL manifestURL = new URL(clientURL, "META-INF/MANIFEST.MF");
+ InputStream is = manifestURL.openStream();
+ manifest = new Manifest(is);
+ is.close();
+ } else {
+ URL jarURL = new URL("jar:" + clientURL + "!/");
+ JarURLConnection jarConn = (JarURLConnection)
jarURL.openConnection();
+ manifest = jarConn.getManifest();
+ }
+ Attributes attrs = manifest.getMainAttributes();
+ mainClassName = (String) attrs.get(Attributes.Name.MAIN_CLASS);
+ if (mainClassName == null) {
+ throw new DeploymentException("No Main-Class defined in
manifest for " + clientURL);
+ }
+ } catch (IOException e) {
+ throw new DeploymentException("Unable to get Main-Class from
manifest for " + clientURL, e);
+ }
+
+ try {
+ AttributeList attrs = new AttributeList(2);
+ attrs.add(new Attribute("MainClassName", mainClassName));
+ attrs.add(new Attribute("ClientURL", clientURL));
+ mbServer.setAttributes(clientName, attrs);
+ } catch (Exception e) {
+ throw new DeploymentException(e);
+ }
+
+ try {
+ mbServer.invoke(clientName, "start", null, null);
+ } catch (Exception e) {
+ throw new DeploymentException(e);
+ }
}
private void undeploy() {
@@ -190,14 +236,20 @@
if (controllerName != null) {
MBeanServer mbServer = kernel.getMBeanServer();
try {
- mbServer.invoke(controllerName, "undeploy", new
Object[]{clientURL}, DEPLOY_ARG_TYPES);
- } catch (InstanceNotFoundException e) {
- log.error("Error undeploying client", e);
- } catch (MBeanException e) {
- log.error("Error undeploying client", e);
- } catch (ReflectionException e) {
- log.error("Error undeploying client", e);
+ mbServer.invoke(clientName, "stop", null, null);
+ } catch (Exception e) {
+ log.error("Error stopping client", e);
}
+
+// try {
+// mbServer.invoke(controllerName, "undeploy", new
Object[]{clientURL}, DEPLOY_ARG_TYPES);
+// } catch (InstanceNotFoundException e) {
+// log.error("Error undeploying client", e);
+// } catch (MBeanException e) {
+// log.error("Error undeploying client", e);
+// } catch (ReflectionException e) {
+// log.error("Error undeploying client", e);
+// }
}
kernel.release();
}
@@ -205,7 +257,9 @@
public void run() {
try {
- mbServer.invoke(clientName, "runMain", new Object[]{appArgs},
new String[]{appArgs.getClass().getName()});
+ ProxyInvocation invocation = new ProxyInvocation();
+ ProxyInvocation.putArguments(invocation, new Object[] { appArgs
});
+ mbServer.invoke(clientName, "invoke", new Object[]{invocation},
new String[]{"org.apache.geronimo.common.Invocation"});
} catch (InstanceNotFoundException e) {
IllegalStateException ex = new IllegalStateException("Unable to
invoke app client");
ex.initCause(e);
1.1
incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/AppClientContainer.java
Index: AppClientContainer.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.client;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.geronimo.common.AbstractRPCContainer;
import org.apache.geronimo.deployment.DeploymentException;
import org.apache.geronimo.naming.java.ComponentContextInterceptor;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/08/23 22:14:20 $
*/
public class AppClientContainer extends AbstractRPCContainer implements
AppClientContainerMBean {
private static final Class[] MAIN_ARGS = {String[].class};
private String mainClassName;
private URL clientURL;
public AppClientContainer() throws DeploymentException {
}
public void setMainClassName(String className) {
mainClassName = className;
}
public String getMainClassName() {
return mainClassName;
}
public URL getClientURL() {
return clientURL;
}
public void setClientURL(URL clientURL) {
this.clientURL = clientURL;
}
protected void doStart() throws Exception {
ClassLoader clientCL = new URLClassLoader(new URL[] { clientURL },
Thread.currentThread().getContextClassLoader());
Method mainMethod;
try {
Class mainClass = clientCL.loadClass(mainClassName);
mainMethod = mainClass.getMethod("main", MAIN_ARGS);
} catch (ClassNotFoundException e) {
throw new DeploymentException("Unable to load Main-Class " +
mainClassName, e);
} catch (NoSuchMethodException e) {
throw new DeploymentException("Main-Class " + mainClassName + "
does not have a main method", e);
}
addInterceptor(new ComponentContextInterceptor(null));
addInterceptor(new MainInvokerInterceptor(mainMethod));
}
protected void doStop() throws Exception {
clearInterceptors();
}
}
1.1
incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/AppClientContainerMBean.java
Index: AppClientContainerMBean.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.client;
import java.net.URL;
import org.apache.geronimo.common.RPCContainer;
import org.apache.geronimo.management.StateManageable;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2003/08/23 22:14:20 $
*/
public interface AppClientContainerMBean extends RPCContainer,StateManageable
{
void setMainClassName(String className);
String getMainClassName();
URL getClientURL();
void setClientURL(URL clientURL);
}
1.1
incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/MainInvokerInterceptor.java
Index: MainInvokerInterceptor.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.client;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import org.apache.geronimo.common.AbstractInterceptor;
import org.apache.geronimo.common.InvocationResult;
import org.apache.geronimo.common.Invocation;
import org.apache.geronimo.common.SimpleInvocationResult;
import org.apache.geronimo.proxy.ProxyInvocation;
/**
* Basic invoker for the main method of an Application Client
*
* @version $Revision: 1.1 $ $Date: 2003/08/23 22:14:20 $
*/
public class MainInvokerInterceptor extends AbstractInterceptor {
private final Method mainMethod;
public MainInvokerInterceptor(Method mainMethod) {
this.mainMethod = mainMethod;
}
public InvocationResult invoke(Invocation invocation) throws Exception {
assert (mainMethod.equals(ProxyInvocation.getMethod(invocation)));
Object[] args = ProxyInvocation.getArguments(invocation);
try {
mainMethod.invoke(null, args);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
return new SimpleInvocationResult(cause);
}
return new SimpleInvocationResult(null);
}
}