From: erickson Date: Fri, 18 May 2007 19:44:31 +0000 (+0000) Subject: added math bench code. added shutdown method to disconnect from jabber. updated... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9d8cda467b80d51bb381b55938fedd7ab28a492e;p=opensrf%2Fbjwebb.git added math bench code. added shutdown method to disconnect from jabber. updated makefile to used fetched version of the stax jar git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@902 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/java/Makefile b/src/java/Makefile index 594be98..7bcd020 100644 --- a/src/java/Makefile +++ b/src/java/Makefile @@ -2,7 +2,7 @@ JAVA_LIBDIR = .lib JAVAC=javac -J-Xmx256m JAVA=java -Xmx256m -JAVA_LIBS = .:$(JAVA_LIBDIR):ext/json-jdk1.5-2007-05-01.jar:ext/wstx-asl-3.2.1.jar:ext/stax-api-1.0.1.jar:ext/java_memcached-release_1.5.1.jar +JAVA_LIBS = .:$(JAVA_LIBDIR):ext/json-jdk1.5-2007-05-01.jar:ext/wstx-lgpl-3.2.1.jar:ext/stax-api-1.0.1.jar:ext/java_memcached-release_1.5.1.jar JAVA_SRC = \ org/opensrf/net/xmpp/*.java \ org/opensrf/util/*.java \ diff --git a/src/java/org/opensrf/Sys.java b/src/java/org/opensrf/Sys.java index 857008d..8520838 100644 --- a/src/java/org/opensrf/Sys.java +++ b/src/java/org/opensrf/Sys.java @@ -36,5 +36,12 @@ public class Sys { throw new SessionException("Unable to bootstrap client", e); } } + + /** + * Shuts down the connection to the opensrf network + */ + public static void shutdown() { + XMPPSession.getGlobalSession().disconnect(); + } } diff --git a/src/java/org/opensrf/net/xmpp/XMPPSession.java b/src/java/org/opensrf/net/xmpp/XMPPSession.java index ce7e36c..e8b639e 100644 --- a/src/java/org/opensrf/net/xmpp/XMPPSession.java +++ b/src/java/org/opensrf/net/xmpp/XMPPSession.java @@ -19,6 +19,8 @@ public class XMPPSession { "" + "%s%s%s"; + public static final String JABBER_DISCONNECT = ""; + /** jabber domain */ private String host; /** jabber port */ @@ -36,6 +38,8 @@ public class XMPPSession { PrintWriter writer; /** Raw socket output stream */ OutputStream outStream; + /** The raw socket */ + Socket socket; /** The process-wide session. All communication occurs * accross this single connection */ @@ -88,8 +92,6 @@ public class XMPPSession { this.password = password; this.resource = resource; - Socket socket; - try { /* open the socket and associated streams */ socket = new Socket(host, port); @@ -193,5 +195,16 @@ public class XMPPSession { return null; } + + + /** + * Disconnects from the jabber server and closes the socket + */ + public void disconnect() { + try { + outStream.write(JABBER_DISCONNECT.getBytes()); + socket.close(); + } catch(Exception e) {} + } } diff --git a/src/java/org/opensrf/test/MathBench.java b/src/java/org/opensrf/test/MathBench.java new file mode 100644 index 0000000..3086bf3 --- /dev/null +++ b/src/java/org/opensrf/test/MathBench.java @@ -0,0 +1,60 @@ +package org.opensrf.test; +import org.opensrf.*; +import org.opensrf.util.*; +import java.util.Date; +import java.util.List; +import java.util.ArrayList; +import java.io.PrintStream; + + +public class MathBench { + + public static void main(String args[]) throws Exception { + + PrintStream out = System.out; + if(args.length < 2) { + out.println("usage: java org.opensrf.test.MathBench "); + return; + } + + Sys.bootstrapClient(args[0], "/config/opensrf"); + int count = Integer.parseInt(args[1]); + + ClientSession session = new ClientSession("opensrf.math"); + List params = new ArrayList(); + params.add(new Integer(1)); + params.add(new Integer(2)); + + Request request; + Result result; + long start; + double total = 0; + + for(int i = 0; i < count; i++) { + + start = new Date().getTime(); + request = session.request("add", params); + result = request.recv(5000); + total += new Date().getTime() - start; + + if(result.getStatusCode() == Status.OK) { + out.print("+"); + } else { + out.println("\nrequest failed"); + out.println("status = " + result.getStatus()); + out.println("status code = " + result.getStatusCode()); + } + + request.cleanup(); + + if((i+1) % 100 == 0) /* print 100 per line */ + out.println(""); + } + + out.println("\nAverage request time is " + (total/count) + " ms"); + Sys.shutdown(); + } +} + + +