jakarta-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1067058 - in /jakarta/jmeter/trunk: src/core/org/apache/jmeter/JMeter.java src/core/org/apache/jmeter/engine/StandardJMeterEngine.java xdocs/changes.xml
Date Fri, 04 Feb 2011 01:34:16 GMT
Author: sebb
Date: Fri Feb  4 01:34:16 2011
New Revision: 1067058

URL: http://svn.apache.org/viewvc?rev=1067058&view=rev
Log:
Client JMeter engine now supports external stop/shutdown via UDP

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
    jakarta/jmeter/trunk/xdocs/changes.xml

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java?rev=1067058&r1=1067057&r2=1067058&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java Fri Feb  4 01:34:16 2011
@@ -24,6 +24,9 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.Authenticator;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
 import java.net.MalformedURLException;
 import java.text.SimpleDateFormat;
 import java.util.Collection;
@@ -128,6 +131,8 @@ public class JMeter implements JMeterPlu
 
 
 
+    /** UDP port used in non-GUI runs. Disabled if <=1000. */
+    private static final int UDP_PORT = JMeterUtils.getPropDefault("jmeterengine.nongui.port",
4445);
 
 
 
@@ -784,6 +789,7 @@ public class JMeter implements JMeterPlu
                 println("Remote engines have been started");
                 log.info("Remote engines have been started");
             }
+            startUdpDdaemon(engine);
         } catch (Exception e) {
             System.out.println("Error in NonGUIDriver " + e.toString());
             log.error("Error in NonGUIDriver", e);
@@ -1023,4 +1029,50 @@ public class JMeter implements JMeterPlu
     private void logProperty(String prop,String separator){
         log.info(prop+separator+System.getProperty(prop));//$NON-NLS-1$
     }
+
+    private void startUdpDdaemon(final JMeterEngine engine) {
+        if (UDP_PORT > 1000){
+            Thread waiter = new Thread(){
+                @Override
+                public void run() {
+                    waitForSignals(engine);
+                }
+            };
+            waiter.setDaemon(true);
+            waiter.start();
+        }
+    }
+
+    private void waitForSignals(final JMeterEngine engine) {
+        byte[] buf = new byte[80];
+        DatagramSocket socket = null;
+        System.out.println("Waiting for possible shutdown message on port "+UDP_PORT);
+        try {
+            socket = new DatagramSocket(UDP_PORT);
+            DatagramPacket request = new DatagramPacket(buf, buf.length);
+            while(true) {
+                socket.receive(request);
+                InetAddress address = request.getAddress();
+                // Only accept commands from the local host
+                if (address.isLoopbackAddress()){
+                    String command = new String(request.getData(), request.getOffset(), request.getLength(),"ASCII");
+                    System.out.println("Command: "+command+" received from "+address);
+                    log.info("Command: "+command+" received from "+address);
+                    if (command.equals("StopTestNow")){
+                        engine.stopTest(true);
+                    } else if (command.equals("Shutdown")) {
+                        engine.stopTest(false);
+                    } else {
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (socket != null) {
+                socket.close();
+            }
+        }
+
+    }
 }
\ No newline at end of file

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java?rev=1067058&r1=1067057&r2=1067058&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java Fri Feb
 4 01:34:16 2011
@@ -20,9 +20,6 @@ package org.apache.jmeter.engine;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
@@ -63,9 +60,6 @@ public class StandardJMeterEngine implem
 
     private static final long WAIT_TO_DIE = JMeterUtils.getPropDefault("jmeterengine.threadstop.wait",
5 * 1000); // 5 seconds
 
-    /** UDP port used in non-GUI runs. Disabled if <=1000. */
-    private static final int UDP_PORT = JMeterUtils.getPropDefault("jmeterengine.nongui.port",
4445);
-
     // Should we exit at end of the test? (only applies to server, because host is non-null)
     private static final boolean exitAfterTest =
         JMeterUtils.getPropDefault("server.exitaftertest", false);  // $NON-NLS-1$
@@ -175,7 +169,7 @@ public class StandardJMeterEngine implem
         test = testTree;
     }
 
-    // TODO: in Java1.5, perhaps we can use Thread.setUncaughtExceptionHandler() instead
+    // TODO: in Java1.5, perhaps we can use Thread.setDefaultUncaughtExceptionHandler() instead
     private static class MyThreadGroup extends java.lang.ThreadGroup{
         public MyThreadGroup(String s) {
             super(s);
@@ -198,16 +192,6 @@ public class StandardJMeterEngine implem
         try {
             Thread runningThread = new Thread(new MyThreadGroup("JMeterThreadGroup"),this);
             runningThread.start();
-            if (JMeter.isNonGUI() && UDP_PORT > 1000){
-                Thread waiter = new Thread(){
-                    @Override
-                    public void run() {
-                        waitForSignals();
-                    }
-                };
-                waiter.setDaemon(true);
-                waiter.start();
-            }
         } catch (Exception err) {
             stopTest();
             StringWriter string = new StringWriter();
@@ -217,39 +201,6 @@ public class StandardJMeterEngine implem
         }
     }
 
-    private void waitForSignals() {
-        byte[] buf = new byte[80];
-        DatagramSocket socket = null;
-        System.out.println("Waiting for possible shutdown message on port "+UDP_PORT);
-        try {
-            socket = new DatagramSocket(UDP_PORT);
-            DatagramPacket request = new DatagramPacket(buf, buf.length);
-            while(true) {
-                socket.receive(request);
-                InetAddress address = request.getAddress();
-                // Only accept commands from the local host
-                if (address.isLoopbackAddress()){
-                    String command = new String(request.getData(), request.getOffset(), request.getLength(),"ASCII");
-                    System.out.println("Command: "+command+" received from "+address);
-                    log.info("Command: "+command+" received from "+address);
-                    if (command.equals("StopTestNow")){
-                        stopTest();
-                    } else if (command.equals("Shutdown")) {
-                        askThreadsToStop();
-                    } else {
-                    }
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            if (socket != null) {
-                socket.close();
-            }
-        }
-
-    }
-
     private void removeThreadGroups(List<?> elements) {
         Iterator<?> iter = elements.iterator();
         while (iter.hasNext()) { // Can't use for loop here because we remove elements

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=1067058&r1=1067057&r2=1067058&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Fri Feb  4 01:34:16 2011
@@ -194,6 +194,7 @@ Fixed RMI startup to provide location of
 <li>Bug 50708 - Classpath jar order in NewDriver not alphabetically</li>
 <li>Bug 50659 - JMeter server does not support concurrent tests - prevent client from
starting another</li>
 <li>Added remote shutdown functionality</li>
+<li>Client JMeter engine now supports external stop/shutdown via UDP</li>
 </ul>
 
 <h2>Non-functional changes</h2>



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


Mime
View raw message