You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2007/01/04 22:51:31 UTC
svn commit: r492766 - in /incubator/tuscany/java/sca/runtime/standalone:
launcher/src/main/java/org/apache/tuscany/launcher/
server.start/src/main/java/org/apache/tuscany/standalone/server/
standalone-api/src/main/java/org/apache/tuscany/runtime/standa...
Author: jboynes
Date: Thu Jan 4 13:51:30 2007
New Revision: 492766
URL: http://svn.apache.org/viewvc?view=rev&rev=492766
Log:
share method for creating a classloader from a directory
Modified:
incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java
incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java
Modified: incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java?view=diff&rev=492766&r1=492765&r2=492766
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java Thu Jan 4 13:51:30 2007
@@ -32,7 +32,6 @@
import org.osoa.sca.SCA;
import org.apache.tuscany.host.runtime.TuscanyRuntime;
-import org.apache.tuscany.host.util.LaunchHelper;
import org.apache.tuscany.runtime.standalone.DirectoryHelper;
import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfo;
import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfoImpl;
@@ -67,7 +66,7 @@
System.arraycopy(args, 1, appArgs, 0, appArgs.length);
ClassLoader hostClassLoader = ClassLoader.getSystemClassLoader();
- ClassLoader bootClassLoader = booter.getTuscanyClassLoader(bootDir);
+ ClassLoader bootClassLoader = DirectoryHelper.createClassLoader(hostClassLoader, bootDir);
ClassLoader applicationClassLoader = new URLClassLoader(new URL[]{applicationURL}, hostClassLoader);
URL systemScdl = booter.getSystemScdl(bootClassLoader);
@@ -124,11 +123,6 @@
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
}
- }
-
- protected ClassLoader getTuscanyClassLoader(File bootDir) {
- URL[] urls = LaunchHelper.scanDirectoryForJars(bootDir);
- return new URLClassLoader(urls, getClass().getClassLoader());
}
/**
Modified: incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java?view=diff&rev=492766&r1=492765&r2=492766
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java Thu Jan 4 13:51:30 2007
@@ -23,68 +23,70 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLClassLoader;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-
import javax.management.MBeanServer;
+import org.apache.tuscany.core.services.management.jmx.runtime.JmxRuntimeInfoImpl;
import org.apache.tuscany.host.RuntimeInfo;
import org.apache.tuscany.host.runtime.InitializationException;
import org.apache.tuscany.host.runtime.ShutdownException;
import org.apache.tuscany.host.runtime.TuscanyRuntime;
-import org.apache.tuscany.host.util.LaunchHelper;
+import org.apache.tuscany.runtime.standalone.DirectoryHelper;
import org.apache.tuscany.standalone.server.management.jmx.Agent;
import org.apache.tuscany.standalone.server.management.jmx.RmiAgent;
-import org.apache.tuscany.core.services.management.jmx.runtime.JmxRuntimeInfoImpl;
-import org.apache.tuscany.runtime.standalone.DirectoryHelper;
-
/**
- * This class provides the commandline interface for starting the
- * tuscany standalone server.
- *
- * <p>
- * The class boots the tuscany server and also starts a JMX server
- * and listens for shutdown command. The server itself is available
+ * This class provides the commandline interface for starting the
+ * tuscany standalone server.
+ * <p/>
+ * <p/>
+ * The class boots the tuscany server and also starts a JMX server
+ * and listens for shutdown command. The server itself is available
* by the object name <code>tuscany:type=server,name=tuscanyServer
- * </code>. It also allows a runtime to be booted given a bootpath.
- * The JMX domain in which the runtime is registered si definied in
+ * </code>. It also allows a runtime to be booted given a bootpath.
+ * The JMX domain in which the runtime is registered si definied in
* the file <code>$bootPath/etc/runtime.properties</code>. The properties
* defined are <code>jmx.domain</code> and <code>offline</code>.
* </p>
- *
- * <p>
- * The install directory can be specified using the system property
- * <code>tuscany.installDir</code>. If not specified it is asumed to
- * be the directory from where the JAR file containing the main class
- * is loaded.
+ * <p/>
+ * <p/>
+ * The install directory can be specified using the system property
+ * <code>tuscany.installDir</code>. If not specified it is asumed to
+ * be the directory from where the JAR file containing the main class
+ * is loaded.
* </p>
- *
- * <p>
+ * <p/>
+ * <p/>
* The administration port can be specified using the system property
- * <code>tuscany.adminPort</tuscany>.If not specified the default port
+ * <code>tuscany.adminPort</tuscany>.If not specified the default port
* that is used is <code>1099</code>
- *
- * @version $Rev$ $Date$
*
+ * @version $Rev$ $Date$
*/
public class TuscanyServer implements TuscanyServerMBean {
- /** Agent */
+ /**
+ * Agent
+ */
private final Agent agent;
- /** Install directory */
+ /**
+ * Install directory
+ */
private final File installDirectory;
- /** Base Url */
+ /**
+ * Base Url
+ */
private final URL baseUrl;
- /** Started runtimes. */
+ /**
+ * Started runtimes.
+ */
private final Map<String, TuscanyRuntime> bootedRuntimes = new ConcurrentHashMap<String, TuscanyRuntime>();
/**
- *
* @param args Commandline arguments.
*/
public static void main(String[] args) throws Exception {
@@ -93,8 +95,8 @@
/**
* Constructor initializes all the required classloaders.
- * @throws MalformedURLException
*
+ * @throws MalformedURLException
*/
private TuscanyServer() throws MalformedURLException {
installDirectory = DirectoryHelper.getInstallDirectory(TuscanyServer.class);
@@ -112,7 +114,7 @@
final RuntimeInfo runtimeInfo = new JmxRuntimeInfoImpl(baseUrl, installDirectory, online, mBeanServer, managementDomain);
final ClassLoader hostClassLoader = ClassLoader.getSystemClassLoader();
- final ClassLoader bootClassLoader = getTuscanyClassLoader(bootDirectory);
+ final ClassLoader bootClassLoader = DirectoryHelper.createClassLoader(hostClassLoader, bootDirectory);
final URL systemScdl = getSystemScdl(bootClassLoader);
if (systemScdl == null) {
@@ -122,7 +124,7 @@
final String className =
System.getProperty("tuscany.launcherClass",
"org.apache.tuscany.runtime.standalone.jmx.JmxRuntimeImpl");
- final TuscanyRuntime runtime = (TuscanyRuntime)Beans.instantiate(bootClassLoader, className);
+ final TuscanyRuntime runtime = (TuscanyRuntime) Beans.instantiate(bootClassLoader, className);
runtime.setMonitorFactory(runtime.createDefaultMonitorFactory());
runtime.setSystemScdl(systemScdl);
runtime.setHostClassLoader(hostClassLoader);
@@ -170,7 +172,6 @@
/**
* Starts the server.
- *
*/
public final void shutdown() {
@@ -184,17 +185,8 @@
}
/**
- * Gets the tuscany classloader.
- * @param bootDir Boot directory.
- * @return Tuscany classloader.
- */
- private ClassLoader getTuscanyClassLoader(File bootDir) {
- URL[] urls = LaunchHelper.scanDirectoryForJars(bootDir);
- return new URLClassLoader(urls, getClass().getClassLoader());
- }
-
- /**
* Gets the system SCDL.
+ *
* @param bootClassLoader Boot classloader.
* @return URL to the system SCDL.
*/
@@ -205,7 +197,6 @@
/**
* Starts the server and starts the JMX agent.
- *
*/
private void start() {
agent.start();
Modified: incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java?view=diff&rev=492766&r1=492765&r2=492766
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java Thu Jan 4 13:51:30 2007
@@ -19,8 +19,13 @@
package org.apache.tuscany.runtime.standalone;
import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.jar.JarFile;
/**
* Utility class for installation directory related operations.
@@ -110,4 +115,44 @@
}
+ /**
+ * Create a classloader from all the jar files or subdirectories in a directory.
+ * The classpath for the returned classloader will comprise all jar files and subdirectories
+ * of the supplied directory. Hidden files and those that do not contain a valid manifest will
+ * be silently ignored.
+ *
+ * @param parent the parent for the new classloader
+ * @param directory the directory to scan
+ * @return a classloader whose classpath includes all jar files and subdirectories of the supplied directory
+ */
+ public static ClassLoader createClassLoader(ClassLoader parent, File directory) {
+ File[] jars = directory.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ if (file.isHidden()) {
+ return false;
+ }
+ if (file.isDirectory()) {
+ return true;
+ }
+ try {
+ JarFile jar = new JarFile(file);
+ return jar.getManifest() != null;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+ });
+
+ URL[] urls = new URL[jars.length];
+ for (int i = 0; i < jars.length; i++) {
+ try {
+ urls[i] = jars[i].toURI().toURL();
+ } catch (MalformedURLException e) {
+ // toURI should have escaped the URL
+ throw new AssertionError();
+ }
+ }
+
+ return new URLClassLoader(urls, parent);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org