You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ha...@apache.org on 2004/09/27 15:26:37 UTC
cvs commit: ws-axis/c/tests/utils/monitor/org/apache/test StopTCPMonitor.java RequestForwarder.java TCPMonitor.java
hawkeye 2004/09/27 06:26:37
Modified: c/tests/utils/monitor/org/apache/test RequestForwarder.java
TCPMonitor.java
Added: c/tests/utils/monitor/org/apache/test StopTCPMonitor.java
Log:
Added enhancements to allow a message to be sent to the monitor to tell it to stop. Also ensure that all file and socket connections are closed correctly.
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.3 +14 -4 ws-axis/c/tests/utils/monitor/org/apache/test/RequestForwarder.java
Index: RequestForwarder.java
===================================================================
RCS file: /home/cvs/ws-axis/c/tests/utils/monitor/org/apache/test/RequestForwarder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RequestForwarder.java 21 Sep 2004 15:55:10 -0000 1.2
+++ RequestForwarder.java 27 Sep 2004 13:26:37 -0000 1.3
@@ -25,6 +25,7 @@
private BufferedReader reader;
private BufferedWriter writer;
private RequestHandler requestHandler;
+ private boolean continueToRun = true;
/**
* @param bufferedReader
@@ -40,11 +41,15 @@
this.requestHandler = requestHandler;
}
+ public void cease() {
+ continueToRun = false;
+ }
+
public void run() {
char[] buffer = new char[1024];
try {
int ret = 0;
- while ((ret = reader.read(buffer, 0, 1023)) != -1) {
+ while ((ret = reader.read(buffer, 0, 1023)) != -1 && continueToRun) {
String line = new String(buffer, 0, ret);
if(line.equalsIgnoreCase("STOPTCPM")) {
System.err.println("*** RECEIVED STOP COMMAND. Stopping ***");
@@ -58,8 +63,6 @@
writer.write(line);
writer.flush();
}
- writer.close();
- reader.close();
} catch (SocketException socketException) {
//System.out.println("socketException: " + socketException);
} catch (IOException exception) {
@@ -68,7 +71,14 @@
System.out.println("runtimeException: " + runtimeException);
} catch (Throwable exception) {
requestHandler.handleReadingException(exception);
+ } finally {
+ try {
+ writer.close();
+ reader.close();
+ } catch (IOException ioe) {
+ ;
+ }
+ requestHandler.close();
}
- requestHandler.close();
}
}
1.2 +23 -0 ws-axis/c/tests/utils/monitor/org/apache/test/TCPMonitor.java
Index: TCPMonitor.java
===================================================================
RCS file: /home/cvs/ws-axis/c/tests/utils/monitor/org/apache/test/TCPMonitor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TCPMonitor.java 3 Sep 2004 15:43:27 -0000 1.1
+++ TCPMonitor.java 27 Sep 2004 13:26:37 -0000 1.2
@@ -94,6 +94,27 @@
// spin off the thread to listen for a client request
responseReader.start();
+ try {
+ // Wait for the request reader to finish
+ requestReader.join(25000);
+
+ // If the response reader is still running then
+ // ask it to stop and wait for it.
+ if(responseReader.isAlive()) {
+ responseReader.cease();
+ responseReader.join(2000);
+ }
+ } catch (Exception me) {
+ ;
+ } finally {
+ try {
+ outputSocket.close();
+ clientSocket.close();
+ serverSocket.close();
+ } catch (IOException mie) {
+ ;
+ }
+ }
}
public static void main(String[] args) {
@@ -136,7 +157,9 @@
}
TCPMonitor monitor =
new TCPMonitor(listener_port, forward_host, forward_port, response_file);
+ long now = System.currentTimeMillis();
monitor.listen(new MyRequestHandler(output_file));
+ System.err.println("**** Listened for " + (System.currentTimeMillis() - now) + " ms" );
} catch (IOException exception) {
exception.printStackTrace();
}
1.1 ws-axis/c/tests/utils/monitor/org/apache/test/StopTCPMonitor.java
Index: StopTCPMonitor.java
===================================================================
package org.apache.test;
import java.io.*;
import java.net.*;
public class StopTCPMonitor {
private String hostname = null;
private int port = 0;
public StopTCPMonitor(String monitorHost, int monitorPort) {
hostname = monitorHost;
port = monitorPort;
}
public void stopMonitor() {
Socket socket = null;
DataOutputStream dos = null;
try {
socket = new Socket(hostname, port);
dos = new DataOutputStream(socket.getOutputStream());
dos.writeUTF("STOPTCPM");
} catch (UnknownHostException uhe) {
uhe.printStackTrace();
} catch (ConnectException ce) {
} catch (IOException ie) {
ie.printStackTrace();
} finally {
try {
dos.close();
socket.close();
} catch (Exception exe) {
;
}
}
}
public static void main(String[] args) {
int monitorPort = 0;
String monitorHost = "";
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-p")) {
monitorPort = Integer.parseInt(args[++i]);
continue;
}
if (args[i].equals("-h")) {
monitorHost = new String(args[++i]);
continue;
}
}
if(monitorPort == 0 || monitorHost.equals("")) {
System.out.println("usage: StopTCPmonitor <-p port> <-h host>");
return;
}
StopTCPMonitor stop = new StopTCPMonitor(monitorHost, monitorPort);
stop.stopMonitor();
}
}