added math bench code. added shutdown method to disconnect from jabber. updated...
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 18 May 2007 19:44:31 +0000 (19:44 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 18 May 2007 19:44:31 +0000 (19:44 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@902 9efc2488-bf62-4759-914b-345cdb29e865

src/java/Makefile
src/java/org/opensrf/Sys.java
src/java/org/opensrf/net/xmpp/XMPPSession.java
src/java/org/opensrf/test/MathBench.java [new file with mode: 0644]

index 594be98..7bcd020 100644 (file)
@@ -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 \
index 857008d..8520838 100644 (file)
@@ -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();
+    }
 }
 
index ce7e36c..e8b639e 100644 (file)
@@ -19,6 +19,8 @@ public class XMPPSession {
         "<iq id='123' type='set'><query xmlns='jabber:iq:auth'>" +
         "<username>%s</username><password>%s</password><resource>%s</resource></query></iq>";
 
+    public static final String JABBER_DISCONNECT = "</stream:stream>";
+
     /** 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 (file)
index 0000000..3086bf3
--- /dev/null
@@ -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 <osrfConfig> <numIterations>");
+            return;
+        }
+
+        Sys.bootstrapClient(args[0], "/config/opensrf");
+        int count = Integer.parseInt(args[1]);
+
+        ClientSession session = new ClientSession("opensrf.math");
+        List<Object> params = new ArrayList<Object>();
+        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();
+    }
+}
+
+
+