You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/03/22 21:40:09 UTC

svn commit: r387935 - in /jakarta/jmeter/branches/rel-2-1: src/components/org/apache/jmeter/visualizers/ xdocs/

Author: sebb
Date: Wed Mar 22 12:40:07 2006
New Revision: 387935

URL: http://svn.apache.org/viewcvs?rev=387935&view=rev
Log:
Add BeanShell Listener

Added:
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListener.java
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerBeanInfo.java
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerResources.properties
Modified:
    jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml

Added: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListener.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListener.java?rev=387935&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListener.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListener.java Wed Mar 22 12:40:07 2006
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * 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.jmeter.visualizers;
+
+import java.io.Serializable;
+
+import org.apache.jmeter.gui.UnsharedComponent;
+import org.apache.jmeter.samplers.SampleEvent;
+import org.apache.jmeter.samplers.SampleListener;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.testbeans.TestBean;
+import org.apache.jmeter.testelement.AbstractTestElement;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.BeanShellInterpreter;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.jorphan.util.JMeterException;
+import org.apache.log.Logger;
+
+public class BeanShellListener extends AbstractTestElement 
+    implements SampleListener, Visualizer, Serializable, TestBean, UnsharedComponent  {
+	
+    private static final Logger log = LoggingManager.getLoggerForClass();
+    
+    private static final long serialVersionUID = 2;
+
+    transient private BeanShellInterpreter bshInterpreter = null;
+
+    // can be specified in jmeter.properties
+    private static final String INIT_FILE = "beanshell.listener.init"; //$NON-NLS-1$
+
+
+    private String script = "";
+    
+    public BeanShellListener()  throws ClassNotFoundException {
+        bshInterpreter = new BeanShellInterpreter(JMeterUtils.getProperty(INIT_FILE),log);
+    }
+
+
+	public String getScript() {
+		return script;
+	}
+
+
+	public void setScript(String script) {
+		this.script = script;
+	}
+
+
+	public void sampleOccurred(SampleEvent se) {
+        JMeterContext jmctx = JMeterContextService.getContext();
+        JMeterVariables vars = jmctx.getVariables();
+        SampleResult samp=se.getResult();
+        try {
+            // Add variables for access to context and variables
+            bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
+            bshInterpreter.set("vars", vars);//$NON-NLS-1$
+            bshInterpreter.set("sampleEvent", se);//$NON-NLS-1$
+            bshInterpreter.set("sampleResult", samp);//$NON-NLS-1$
+            bshInterpreter.eval(script);
+        } catch (JMeterException e) {
+            log.warn("Problem in BeanShell script "+e);
+        }
+		
+	}
+
+
+	public void sampleStarted(SampleEvent e) {
+	}
+
+	public void sampleStopped(SampleEvent e) {
+	}
+
+	public void add(SampleResult sample) {
+	}
+
+	public boolean isStats() {// Required by Visualiser
+		return false;
+	}
+
+//	public Object clone() {
+//        BeanShellListener o = (BeanShellListener) super.clone();
+//        o.script = script;
+//		return o;
+//	}
+    
+}

Added: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerBeanInfo.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerBeanInfo.java?rev=387935&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerBeanInfo.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerBeanInfo.java Wed Mar 22 12:40:07 2006
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * 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.jmeter.visualizers;
+
+import java.beans.PropertyDescriptor;
+
+import org.apache.jmeter.testbeans.BeanInfoSupport;
+
+public class BeanShellListenerBeanInfo extends BeanInfoSupport {
+
+	/**
+	 * @param beanClass
+	 */
+	public BeanShellListenerBeanInfo() {
+		super(BeanShellListener.class);
+
+        createPropertyGroup("scripting", new String[] { "script" });
+
+		PropertyDescriptor p = property("script");
+		p.setValue(NOT_UNDEFINED, Boolean.TRUE);
+		p.setValue(DEFAULT, "");
+	}
+
+}

Added: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerResources.properties
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerResources.properties?rev=387935&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerResources.properties (added)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/visualizers/BeanShellListenerResources.properties Wed Mar 22 12:40:07 2006
@@ -0,0 +1,4 @@
+displayName=BeanShell Listener
+scripting.displayName=BeanShell (variables: jmctx vars sampleEvent sampleResult)
+script.displayName=Script
+script.shortDescription=Beanshell script
\ No newline at end of file

Modified: jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml?rev=387935&r1=387934&r2=387935&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml Wed Mar 22 12:40:07 2006
@@ -51,7 +51,7 @@
 <li>Regular Expression Extractor sets group count</li>
 <li>Can now save entire screen as an image, not just the right-hand pane</li>
 <li>Bug 38901 - Add optional SOAPAction header to SOAP Sampler</li>
-<li>New BeanShell test elements: Timer, PreProcessor, PostProcessor</li>
+<li>New BeanShell test elements: Timer, PreProcessor, PostProcessor, Listener</li>
 </ul>
 
 <h4>Bug fixes:</h4>



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org