You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by sp...@apache.org on 2009/11/17 15:06:04 UTC

svn commit: r881318 - in /incubator/kato/trunk/org.apache.kato: kato.api.vm/src/main/java/javax/tools/diagnostics/vm/ kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/

Author: spoole
Date: Tue Nov 17 15:06:02 2009
New Revision: 881318

URL: http://svn.apache.org/viewvc?rev=881318&view=rev
Log:
added dump trigger configuration 

Added:
    incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/DumpInitiatorDelegate.java
    incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/IDumpTrigger.java
Modified:
    incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/Dump.java
    incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/ScenarioLauncher.java

Modified: incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/Dump.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/Dump.java?rev=881318&r1=881317&r2=881318&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/Dump.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/Dump.java Tue Nov 17 15:06:02 2009
@@ -10,6 +10,8 @@
  */
 public class Dump {
 
+	public static final String initiatorPropertyName="javax.tools.diagnositics.vm.dumpinitiator";
+	 
 	/**
 	 * <p>
 	 * Initiate a dump.  The location and type of dump produced is
@@ -21,7 +23,46 @@
 	
 	
 	public boolean execute() {
-		return true;
+		
+		DumpInitiatorDelegate delegate=loadDelegate();
+		return delegate.dump();
+	}
+	/**
+	 * @return
+	 */
+	private DumpInitiatorDelegate loadDelegate() {
+		
+		String delegateName=System.getProperty(initiatorPropertyName);
+		 
+		try {
+			if(delegateName==null) {
+				Class clazz=Class.forName(delegateName);
+				return (DumpInitiatorDelegate) clazz.newInstance();
+			}
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		} catch (InstantiationException e) {
+			
+			e.printStackTrace();
+		} catch (IllegalAccessException e) {
+			
+			e.printStackTrace();
+		}
+		
+		
+		return new DummyDelegate();
 	}
 	
+	private class DummyDelegate implements DumpInitiatorDelegate {
+
+		/* (non-Javadoc)
+		 * @see javax.tools.diagnostics.vm.DumpInitiatorDelegate#dump()
+		 */
+		@Override
+		public boolean dump() {
+		
+			return false;
+		}
+		
+	}
 }

Added: incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/DumpInitiatorDelegate.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/DumpInitiatorDelegate.java?rev=881318&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/DumpInitiatorDelegate.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.api.vm/src/main/java/javax/tools/diagnostics/vm/DumpInitiatorDelegate.java Tue Nov 17 15:06:02 2009
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package javax.tools.diagnostics.vm;
+
+/**
+ * Interface that describes the required capabilities of specific
+ * dump initiator.
+ * 
+ * Classes that implement this interface can be called by the
+ * Dump class to trigger a specific dump.
+ * 
+ * The default implementation used is determined by the JVM
+ * and is recorded in the javax.tools.diagnositics.vm.dumpinitiator property
+ * 
+ */
+public interface DumpInitiatorDelegate {
+
+	/**
+	 * Called to cause a dump to be initiated.
+	 * This method should only be called by the Dump class
+	 * 
+	 * @returns true if dump initiation suceeded 
+	 */
+	public boolean dump();
+}

Added: incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/IDumpTrigger.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/IDumpTrigger.java?rev=881318&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/IDumpTrigger.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/IDumpTrigger.java Tue Nov 17 15:06:02 2009
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package org.apache.kato.tck.harness.scenario;
+
+/**
+ * Dump Trigger
+ * 
+ *  Interface used by scenario launcher to trigger
+ *  dumps.  How the dump is triggered is at the
+ *  discretion of the implementor.
+ *  
+ */
+public interface IDumpTrigger {
+
+	/**
+	 * Called by the Scenario Launcher to create a Dump
+	 * This method is not expected to return.
+	 * If it does the Scenario Launcher will exit the JVM
+	 * immediately
+	 */
+	public void dump();
+	
+}

Modified: incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/ScenarioLauncher.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/ScenarioLauncher.java?rev=881318&r1=881317&r2=881318&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/ScenarioLauncher.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.harness/src/main/java/org/apache/kato/tck/harness/scenario/ScenarioLauncher.java Tue Nov 17 15:06:02 2009
@@ -14,12 +14,6 @@
 
 package org.apache.kato.tck.harness.scenario;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -31,16 +25,36 @@
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
-import org.apache.kato.tck.api.ICheckpoint;
 import org.apache.kato.tck.api.TCKException;
 
 /**
  * 
  */
 public class ScenarioLauncher {
+	/**
+	 * 
+	 */
+	private static final String CLASS = "class";
+	
+	/**
+	 * 
+	 */
+	private static final String MODE2 = "mode";
+
+	/**
+	 * 
+	 */
+	private static final String CONFIGDIR = "configdir";
+
+	/**
+	 * 
+	 */
+	private static final String DUMPTRIGGER = "dumptrigger";
+
 	private static ScenarioLauncher defaultLauncher = new ScenarioLauncher();
 	
 	private IScenerioSetupHandler handler=null;
+	private IDumpTrigger trigger=null;
 	
 	
 	private ScenarioLauncher() {
@@ -58,25 +72,25 @@
 		options.addOption(scenario);
 
 		Option clazz = OptionBuilder.withArgName("classname").hasArg()
-				.withDescription("classname to run").create("class");
+				.withDescription("classname to run").create(CLASS);
 		options.addOption(clazz);
 
 		Option mode = OptionBuilder.withArgName("modetype").hasArg()
-				.withDescription("run mode: report or execute").create("mode");
+				.withDescription("run mode: report or execute").create(MODE2);
 		mode.setRequired(true);
 		options.addOption(mode);
 		
 		Option home = OptionBuilder.withArgName("file").hasArg()
-		.withDescription("directory to store configuration (defaults to '.tck' in user home)").create("configdir");
+		.withDescription("directory to store configuration (defaults to '.tck' in user home)").create(CONFIGDIR);
 		options.addOption(home);
 		
+		Option dumpclass=OptionBuilder.withArgName("dumpclassname").hasArg()
+		.withDescription("Dump trigger class name (defaults to jvm level specific dump trigger)").create(DUMPTRIGGER);
+		options.addOption(dumpclass);
 		
-
 		return options;
+		
 	}
-	/**
-	 * @return
-	 */
 	public static ScenarioLauncher getDefaultLauncher() {
 		return defaultLauncher;
 	}
@@ -115,6 +129,7 @@
 		}
 		
 		System.out.println(l.getHandler().getStatus());
+		l.dump();
 		
 		System.exit(0);
 
@@ -125,6 +140,14 @@
 
 	
 
+	
+	/**
+	 * 
+	 */
+	private void dump() {
+		trigger.dump();
+		
+	}
 	/**
 	 * @return
 	 */
@@ -226,7 +249,7 @@
 		try {
 			// parse the command line arguments
 			CommandLine line = parser.parse(options, args);
-			if (line.hasOption("class") == false
+			if (line.hasOption(CLASS) == false
 					&& line.hasOption("scenario") == false) {
 				error("at least one of -scenario or -class must be specified");
 				return false;
@@ -252,7 +275,7 @@
 						}
 						classestoload.add(clazz);
 
-					} else if (opt.equals("class")) {
+					} else if (opt.equals(CLASS)) {
 						String value = parm.getValue();
 						Class clazz = loadScenarioClass(value);
 						if (clazz == null) {
@@ -266,15 +289,18 @@
 				
 				
 				
-				String mode = line.getOptionValue("mode");
+				String mode = line.getOptionValue(MODE2);
 				if (mode.equals("run")) {
 					handler=new ScenerioSetupHandler();
+					
+					
+					
 				}
 				else if(mode.equals("config")) {
 					ConfigurationExtractor x=new ConfigurationExtractor();
 					
-					if(line.hasOption("configdir")) {
-						String configdir=line.getOptionValue("configdir");
+					if(line.hasOption(CONFIGDIR)) {
+						String configdir=line.getOptionValue(CONFIGDIR);
 						x.setConfigDirectory(configdir);
 					}
 					
@@ -285,6 +311,10 @@
 					return false;
 				}
 				
+				// 	do we have the dump trigger class?
+				
+				if(instantiateTriggerClass(line.getOptionValue(DUMPTRIGGER))==false) return false;
+				
 				handler.open();
 				
 				// instantiate objects which will call back 
@@ -304,5 +334,64 @@
 		}	
 
 	}
+	/**
+	 * Instantiates the trigger class named
+	 * If the provided trigger class name is null then
+	 * the default trigger class for the JVM level is used
+	 * 
+	 * @param triggerName
+	 * @return true if trigger instantiated
+	 */
+	private boolean instantiateTriggerClass(String triggerName) {
+		triggerName=getTriggerClassName(triggerName);
+		if(triggerName==null) {
+			error("cannot locate trigger class called "+triggerName);
+			return false;
+		}
+		trigger=loadTriggerClass(triggerName);
+		if(trigger==null) {
+			error("cannot instantiate trigger class called "+triggerName);
+			return false;
+		}
+		return true;
+	}
+	/**
+	 * @param optionValue
+	 * @return
+	 */
+	private String getTriggerClassName(String dumpClassName) {
+
+		if(dumpClassName!=null && dumpClassName.trim().equals("")==false) return dumpClassName;
+		
+		// what JVM level?
+		String version=System.getProperty("java.version");
+		if(version.contains("1.4")) return "org.apache.kato.tck.scenario142.DumpTrigger142";
+		if(version.contains("1.5")) return "org.apache.kato.tck.scenario150.DumpTrigger150";
+		
+		return "org.apache.kato.tck.scenario160.DumpTrigger160";
+		
+	}
+	/**
+	 * @param optionValue
+	 * @return
+	 */
+	private IDumpTrigger loadTriggerClass(String className) {
+		
+		Class c=loadScenarioClass(className);
+		if(c==null) return null;
+		
+		try {
+			return (IDumpTrigger) c.newInstance();
+		} catch (InstantiationException e) {
+			
+			e.printStackTrace();
+		} catch (IllegalAccessException e) {
+			
+			e.printStackTrace();
+		}
+		
+		return null;
+	
+	}
 	
 }