jakarta-jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/threads JMeterThread.java
Date Thu, 04 Aug 2005 21:15:22 GMT
sebb        2005/08/04 14:15:21

  Modified:    src/core/org/apache/jmeter/testelement
                        AbstractTestElement.java TestElement.java
               src/core/org/apache/jmeter/threads JMeterThread.java
  Added:       src/core/org/apache/jmeter/testelement ThreadListener.java
  Log:
  Implement ThreadListener interface
  (more efficient than scanning all elements)
  
  Revision  Changes    Path
  1.45      +0 -16     jakarta-jmeter/src/core/org/apache/jmeter/testelement/AbstractTestElement.java
  
  Index: AbstractTestElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testelement/AbstractTestElement.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- AbstractTestElement.java	12 Jul 2005 20:50:28 -0000	1.44
  +++ AbstractTestElement.java	4 Aug 2005 21:15:21 -0000	1.45
  @@ -385,22 +385,6 @@
   		this.threadName = inthreadName;
   	}
   
  -	/*
  -	 * (non-Javadoc)
  -	 * 
  -	 * @see org.apache.jmeter.testelement.TestElement#threadFinished()
  -	 */
  -	public void threadFinished() {
  -	}
  -
  -	/*
  -	 * (non-Javadoc)
  -	 * 
  -	 * @see org.apache.jmeter.testelement.TestElement#threadStarted()
  -	 */
  -	public void threadStarted() {
  -	}
  -
   	/**
   	 * 
   	 */
  
  
  
  1.16      +2 -12     jakarta-jmeter/src/core/org/apache/jmeter/testelement/TestElement.java
  
  Index: TestElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testelement/TestElement.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestElement.java	12 Jul 2005 20:50:28 -0000	1.15
  +++ TestElement.java	4 Aug 2005 21:15:21 -0000	1.16
  @@ -157,16 +157,6 @@
   	public void setThreadName(String threadName);
   
   	/**
  -	 * Called at the start of each thread. TODO - should it hava a parameter?
  -	 */
  -	public void threadStarted();
  -
  -	/**
  -	 * Called at the end of each thread. TODO - should it hava a parameter?
  -	 */
  -	public void threadFinished();
  -
  -	/**
   	 * Called by Remove to determine if it is safe to remove the element. The
   	 * element can either clean itself up, and return true, or the element can
   	 * return false.
  
  
  
  1.3       +33 -24    jakarta-jmeter/src/core/org/apache/jmeter/testelement/ThreadListener.java
  
  
  
  
  1.61      +29 -41    jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java
  
  Index: JMeterThread.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- JMeterThread.java	12 Jul 2005 20:50:42 -0000	1.60
  +++ JMeterThread.java	4 Aug 2005 21:15:21 -0000	1.61
  @@ -36,9 +36,9 @@
   import org.apache.jmeter.testbeans.TestBeanHelper;
   import org.apache.jmeter.testelement.TestElement;
   import org.apache.jmeter.testelement.TestListener;
  +import org.apache.jmeter.testelement.ThreadListener;
   import org.apache.jmeter.timers.Timer;
   import org.apache.jorphan.collections.HashTree;
  -import org.apache.jorphan.collections.HashTreeTraverser;
   import org.apache.jorphan.collections.SearchByClass;
   import org.apache.jorphan.logging.LoggingManager;
   import org.apache.jorphan.util.JMeterStopTestException;
  @@ -74,9 +74,11 @@
   
   	private transient JMeterVariables threadVars;
   
  -	private Collection testListeners;
  +	private transient Collection testListeners;   // Elements that implement TestListener
   
  -	private transient ListenerNotifier notifier;
  +    private transient Collection threadListeners; // Elements that implement ThreadListener
  +
  +    private transient ListenerNotifier notifier;
   
   	private int threadNum = 0;
   
  @@ -110,10 +112,16 @@
   		testTree = test;
   		compiler = new TestCompiler(testTree, threadVars);
   		controller = (Controller) testTree.getArray()[0];
  +        
   		SearchByClass threadListenerSearcher = new SearchByClass(TestListener.class);
   		test.traverse(threadListenerSearcher);
   		testListeners = threadListenerSearcher.getSearchResults();
  -		notifier = note;
  +        
  +        SearchByClass testListenerSearcher = new SearchByClass(ThreadListener.class);
  +        test.traverse(testListenerSearcher);
  +        threadListeners = testListenerSearcher.getSearchResults();
  +		
  +        notifier = note;
   		running = true;
   	}
   
  @@ -337,49 +345,29 @@
   		threadStarted();
   	}
   
  -	/**
  -	 * 
  -	 */
  +    private void processThreadListeners(boolean begin) {
  +        Iterator it = threadListeners.iterator();
  +        while (it.hasNext()){
  +            ThreadListener tl=(ThreadListener) it.next();
  +            if (begin) {
  +                tl.threadStarted();
  +            } else {
  +                tl.threadFinished();
  +            }
  +        }
  +        
  +    }
  +    
   	private void threadStarted() {
  -		Traverser startup = new Traverser(true);
  -		testTree.traverse(startup);
  +        processThreadListeners(true);
   	}
   
  -	/**
  -	 * 
  -	 */
   	private void threadFinished() {
  -		Traverser shut = new Traverser(false);
  -		testTree.traverse(shut);
  +        processThreadListeners(false);
   		JMeterContextService.decrNumberOfThreads();
   		threadGroup.decrNumberOfThreads();
   	}
   
  -	private class Traverser implements HashTreeTraverser {
  -		private boolean isStart = false;
  -
  -		private Traverser(boolean start) {
  -			isStart = start;
  -		}
  -
  -		public void addNode(Object node, HashTree subTree) {
  -			if (node instanceof TestElement) {
  -				TestElement te = (TestElement) node;
  -				if (isStart) {
  -					te.threadStarted();
  -				} else {
  -					te.threadFinished();
  -				}
  -			}
  -		}
  -
  -		public void subtractNode() {
  -		}
  -
  -		public void processPath() {
  -		}
  -	}
  -
   	public String getThreadName() {
   		return threadName;
   	}
  
  
  

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


Mime
View raw message