sebb        2004/07/02 11:25:22

  Modified:    src/core/org/apache/jmeter/engine StandardJMeterEngine.java
               extras   startup.bsh
  Log:
  Add stopThreadNow() method etc
  
  Revision  Changes    Path
  1.51      +57 -0     
jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
  
  Index: StandardJMeterEngine.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- StandardJMeterEngine.java 20 Jun 2004 01:23:40 -0000      1.50
  +++ StandardJMeterEngine.java 2 Jul 2004 18:25:22 -0000       1.51
  @@ -63,9 +63,66 @@
      private String host = null;
      private transient ListenerNotifier notifier;
   
  +    // Allow engine and threads to be stopped from outside a thread
  +    // e.g. from beanshell server
  +    // Assumes that there is only one instance of the engine
  +    // at any one time so it is not guaranteed to work ...
  +    private static transient Map allThreadNames;
  +    private static StandardJMeterEngine engine;
  +     private static Map allThreadsSave;
  +    public static void stopEngineNow()
  +    {
  +       engine.stopTest();
  +    }
  +    public static void stopEngine()
  +    {
  +       engine.askThreadsToStop();
  +    }
  +    public static boolean stopThread(String threadName)
  +    {
  +     return stopThread(threadName,false);
  +    }
  +    public static boolean stopThreadNow(String threadName)
  +    {
  +     return stopThread(threadName,true);
  +    }
  +    private static boolean stopThread(String threadName, boolean now)
  +    {
  +     if (allThreadNames == null) return false;// e.g. not yet started
  +     JMeterThread thrd;
  +             try {
  +         thrd = (JMeterThread)allThreadNames.get(threadName);
  +     } catch (Exception e) {
  +             log.warn("stopThread: "+e);
  +             return false;
  +     }
  +     if (thrd!= null)
  +     {
  +             thrd.stop();
  +             if (now)
  +             {
  +                 Thread t = (Thread) allThreadsSave.get(thrd);
  +                 if (t != null)
  +                 {
  +                     t.interrupt();
  +                 }
  +                     
  +             }
  +             return true;
  +     }
  +     else
  +     {
  +             return false;
  +     }
  +    }
  +    // End of code to allow engine to be controlled remotely
  +    
      public StandardJMeterEngine()
      {
         allThreads = new HashMap();
  +        engine=this;
  +        allThreadNames = new HashMap();
  +        allThreadsSave = allThreads;
      }
   
      public StandardJMeterEngine(String host)
  
  
  
  1.2       +27 -4     jakarta-jmeter/extras/startup.bsh
  
  Index: startup.bsh
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/extras/startup.bsh,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- startup.bsh       30 Oct 2003 12:12:28 -0000      1.1
  +++ startup.bsh       2 Jul 2004 18:25:22 -0000       1.2
  @@ -19,6 +19,7 @@
   }
   
   setprop(p,v){// set a JMeter property
  +System.out.println("Setting property '"+p+"' to '"+v+"'.");
   JMeterUtils.getJMeterProperties().setProperty(p, v);
   }
   
  @@ -30,12 +31,34 @@
   LoggingManager.setPriority(priority, category);
   }
   
  -logdebug(String category){
  -loglevel("DEBUG",category);
  +logdebug(String text){
  +loglevel("DEBUG",text);
   }
   
  -loginfo(String category){
  -loglevel("INFO",category);
  +loginfo(String text){
  +loglevel("INFO",text);
   }
   
  +// Define routines to stop the test or a thread
  +stopEngine(){// Stop the JMeter test
  +System.out.println("Stop Engine called");
  +org.apache.jmeter.engine.StandardJMeterEngine.stopEngine();
  +}
  +
  +stopEngineNow(){// Stop the JMeter test now
  +System.out.println("Stop Engine NOW called");
  +org.apache.jmeter.engine.StandardJMeterEngine.stopEngineNow();
  +}
  +
  +stopThread(t){// Stop a JMeter thread
  +System.out.println("Stop Thread "+t+" called");
  +ok=org.apache.jmeter.engine.StandardJMeterEngine.stopThread(t);
  +if (ok){print("Thread requested to stop");} else { print("Thread not found");}
  +}
  +
  +stopThreadNow(t){// Stop a JMeter thread
  +System.out.println("Stop Thread Now "+t+" called");
  +ok=org.apache.jmeter.engine.StandardJMeterEngine.stopThreadNow(t);
  +if (ok){print("Thread stopped");} else { print("Thread not found");}
  +}
   print("Startup script completed");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to