To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 1f0fa0c5 authored by Rui Chen's avatar Rui Chen
Browse files

[Daytrader]Updated the java codes that trigger the trading of daytrader

parent 93f6b649
......@@ -8,17 +8,11 @@
*/
package org.dacapo.daytrader;
import java.io.InputStream;
import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.kernel.Jsr77Naming;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.KernelFactory;
import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.apache.geronimo.kernel.config.ConfigurationManager;
import org.apache.geronimo.kernel.log.GeronimoLogging;
import org.apache.geronimo.kernel.repository.Artifact;
import java.lang.ProcessBuilder;
import java.lang.Process;
import java.io.File;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.Collection;
......@@ -28,25 +22,20 @@ import java.util.Collection;
* @id $Id: DaCapoClientRunner.java 738 2009-12-24 00:19:36Z steveb-oss $
*/
public class DaCapoClientRunner {
private static Kernel kernel = null;
private static AbstractName bean = null;
private static String car = null;
private static String gero = null;
public static void initialize(String carName, String size, int numThreads, boolean useBeans) {
try {
GeronimoLogging.initialize(GeronimoLogging.ERROR);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
kernel = KernelFactory.newInstance().createKernel("DaCapoClient");
kernel.boot();
InputStream in = classLoader.getResourceAsStream("META-INF/config.ser");
ConfigurationUtil.loadBootstrapConfiguration(kernel, in, classLoader, true);
Artifact configuration = Artifact.create(carName);
ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
configurationManager.loadConfiguration(configuration);
configurationManager.startConfiguration(configuration);
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
bean = new Jsr77Naming().createRootName(configuration, configuration.toString(), "J2EEApplication");
String[] args = new String[] { "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "" };
kernel.invoke(bean, "main", new Object[] { args }, new String[] { String[].class.getName() });
car = carName;
gero = System.getProperty("org.apache.geronimo.home.dir");
ProcessBuilder pb = new ProcessBuilder("java", "-jar", "-Dkaraf.startLocalConsole=false",gero + "/bin/client.jar", car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "");
Process p = pb.start();
p.waitFor();
} catch (Exception e) {
System.err.print("Exception initializing client: " + e.toString());
e.printStackTrace();
......@@ -55,18 +44,22 @@ public class DaCapoClientRunner {
}
public static void runIteration(String size, int numThreads, boolean useBeans) {
String[] args = new String[] { "-t", numThreads + "", "-s", size, useBeans ? "-b" : "" };
try {
kernel.invoke(bean, "main", new Object[] { args }, new String[] { String[].class.getName() });
ProcessBuilder pb = new ProcessBuilder("java", "-jar", "-Dkaraf.startLocalConsole=false", gero + "/bin/client.jar", car, "-t", numThreads + "", "-s", size, useBeans ? "-b" : "");
Process p = pb.start();
p.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
while (stdInput.ready()) { //While there's something in the buffer
//read&print - replace with a buffered read (into an array) if the output doesn't contain CR/LF
System.out.println(stdInput.readLine());
}
} catch (Exception e) {
System.err.print("Exception running client iteration: " + e.toString());
e.printStackTrace();
}
}
public static void shutdown() {
bean = null;
kernel.shutdown();
kernel = null;
}
}
......@@ -10,12 +10,13 @@ package org.dacapo.daytrader;
import java.io.InputStream;
import java.util.Arrays;
import org.apache.geronimo.main.Bootstrapper;
import org.apache.geronimo.main.Main;
import org.apache.geronimo.cli.daemon.DaemonCLParser;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.KernelFactory;
import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.apache.geronimo.kernel.log.GeronimoLogging;
import org.apache.geronimo.kernel.util.Main;
import org.apache.geronimo.cli.shutdown.ShutdownCLParser;
import org.apache.geronimo.main.ScriptLaunchListener;
/**
* Dacapo benchmark harness for tradesoap.
......@@ -24,28 +25,31 @@ import org.apache.geronimo.kernel.util.Main;
* @id $Id: DaCapoServerRunner.java 738 2009-12-24 00:19:36Z steveb-oss $
*/
public class DaCapoServerRunner {
private static Kernel kernel = null;
private static Thread serverThread = null;
private static Bootstrapper boot = null;
public static void initialize() {
try {
GeronimoLogging.initialize(GeronimoLogging.ERROR);
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
kernel = KernelFactory.newInstance().createKernel("DaCapoServer");
kernel.boot();
InputStream in = classLoader.getResourceAsStream("META-INF/config.ser");
ConfigurationUtil.loadBootstrapConfiguration(kernel, in, classLoader, true);
boot = new Bootstrapper();
final DaemonCLParser parser = new DaemonCLParser(System.out);
final Main main = (Main) kernel.getGBean(Main.class);
parser.parse(new String[] { "--quiet" });
serverThread = new Thread(new Runnable() {
public void run() {
Thread.currentThread().setContextClassLoader(main.getClass().getClassLoader());
main.execute(parser);
}
});
serverThread.start();
parser.parse(new String[] { "--clean", "--quite" });
boot.setWaitForStop(true);
boot.setStartBundles(Arrays.asList("org.apache.geronimo.framework/j2ee-system//car"));
boot.setLog4jConfigFile("var/log/server-log4j.properties");
boot.setCleanStorage(((DaemonCLParser)parser).isCleanCache());
boot.setLaunchListener(new ScriptLaunchListener("server"));
boot.init();
boot.launch();
Main geronimoMain = boot.getMain();
ClassLoader newTCCL = geronimoMain.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(newTCCL);
geronimoMain.execute(parser);
} catch (Exception e) {
System.err.print("Exception initializing server: " + e.toString());
e.printStackTrace();
......@@ -53,16 +57,13 @@ public class DaCapoServerRunner {
}
}
public static void shutdown() {
while (serverThread.isAlive()) {
serverThread.interrupt();
try {
serverThread.join();
} catch (InterruptedException e) {
}
public static void shutdown(){
try {
boot.shutdown(0L);
} catch (Exception e) {
System.err.print("Exception initializing server: " + e.toString());
e.printStackTrace();
System.exit(-1);
}
serverThread = null;
kernel.shutdown();
kernel = null;
}
}
......@@ -22,24 +22,21 @@ import java.util.List;
*/
public class Launcher {
// Geronimo configuration
private final static String GVERSION = "2.1.4";
private final static String GVERSION = "3.0.1";
private final static String GTYPE = "minimal";
private final static String GDIRECTORY = "geronimo-jetty6-" + GTYPE + "-" + GVERSION;
private final static String GDIRECTORY = "geronimo-tomcat7-" + GTYPE + "-" + GVERSION;
// The daytrader-dacapo application
private final static String CAR_NAME = "org.apache.geronimo.daytrader/daytrader-dacapo/2.2-SNAPSHOT/car";
// These jars hold configuration information for the client and server
// geronimo environments.
private final static String[] CLIENT_BIN_JARS = { "client.jar" };
private final static String[] SERVER_BIN_JARS = { "server.jar" };
private final static String CAR_NAME = "org.apache.geronimo.daytrader.plugins/daytrader-dacapo/3.0-SNAPSHOT/car";
// This jar contains the code that knows how to create and communicate with
// geronimo environments
private final static String[] DACAPO_CLI_JAR = { "jar/daytrader.jar" };
// The following list is defined in the "Class-Path:" filed of MANIFEST.MF for the client and server jars
private final static String[] GERONIMO_LIB_JARS = { "geronimo-cli-"+GVERSION+".jar", "geronimo-kernel-"+GVERSION+".jar", "geronimo-transformer-"+GVERSION+".jar", "asm-3.1.jar", "asm-commons-3.1.jar", "commons-cli-1.0.jar", "commons-logging-1.0.4.jar", "cglib-nodep-2.1_3.jar", "log4j-1.2.14.jar", "xpp3-1.1.3.4.0.jar", "xstream-1.2.2.jar"};
private final static String[] GERONIMO_LIB_JARS = {"agent/transformer.jar", "endorsed/yoko-rmi-spec.jar"
, "endorsed/yoko-spec-corba.jar", "geronimo-main.jar", "geronimo-cli.jar", "commons-cli.jar"
, "geronimo-hook.jar", "geronimo-rmi-loader.jar", "karaf-jaas-boot.jar"};
private static int numThreads = -1;
private static String size;
......@@ -87,9 +84,14 @@ public class Launcher {
private static void setGeronimoProperties() {
File geronimo = new File(scratch, GDIRECTORY);
System.setProperty("org.apache.geronimo.base.dir", geronimo.getPath());
System.setProperty("org.apache.geronimo.home.dir", geronimo.getPath());
System.setProperty("org.apache.geronimo.server.dir", geronimo.getPath());
System.setProperty("karaf.home", geronimo.getPath());
System.setProperty("karaf.base", geronimo.getPath());
System.setProperty("java.util.logging.config.file", geronimo.getPath() + "/etc/java.util.logging.properties");
System.setProperty("java.ext.dirs", geronimo.getPath() + "/lib/ext:" + System.getProperty("java.home") + "/lib/ext");
System.setProperty("java.io.tmpdir", geronimo.getPath() + "/var/temp");
System.setProperty("karaf.startRemoteShell", "true");
}
public static void performIteration() {
......@@ -109,6 +111,17 @@ public class Launcher {
}
}
public static void shutdown(){
try {
Class<?> clazz = serverCLoader.loadClass("org.dacapo.daytrader.DaCapoServerRunner");
Method method = clazz.getMethod("shutdown", new Class[]{});
method.invoke(null, new Object[]{});
}catch (Exception e) {
System.err.println("Exception during iteration: " + e.toString());
e.printStackTrace();
}
}
/**
* Create the classloader from within which to start the Geronimo client
* and/or server kernels.
......@@ -119,8 +132,7 @@ public class Launcher {
*/
private static ClassLoader createGeronimoClassLoader(ClassLoader parent, boolean server) {
File geronimo = new File(scratch, GDIRECTORY).getAbsoluteFile();
ClassLoader binCL = new URLClassLoader(getGeronimoBinaryJars(geronimo, server), parent);
ClassLoader libCL = new URLClassLoader(getGeronimoLibraryJars(geronimo, server), binCL);
ClassLoader libCL = new URLClassLoader(getGeronimoLibraryJars(geronimo, server), parent);
return libCL;
}
......@@ -146,19 +158,6 @@ public class Launcher {
return jars.toArray(new URL[jars.size()]);
}
/**
* Get a list of jars (if any) which should be in the binary classpath for
* this benchmark.
*
* @param geronimo The base directory for the jars
* @return An array of URLs, one URL for each jar
*/
private static URL[] getGeronimoBinaryJars(File geronimo, boolean server) {
List<URL> jars = new ArrayList<URL>();
addJars(jars, new File(geronimo, "bin"), (server ? SERVER_BIN_JARS : CLIENT_BIN_JARS));
return jars.toArray(new URL[jars.size()]);
}
/**
* Compile a list of paths to jars from a base directory and relative paths.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment