1 package org.xmlBlaster.test.memoryleak;
2
3 import java.util.logging.Logger;
4 import java.util.logging.Level;
5 import org.xmlBlaster.util.*;
6 import org.xmlBlaster.client.I_Callback;
7 import org.xmlBlaster.client.key.UpdateKey;
8 import org.xmlBlaster.client.qos.ConnectQos;
9 import org.xmlBlaster.client.qos.ConnectReturnQos;
10 import org.xmlBlaster.client.qos.DisconnectQos;
11 import org.xmlBlaster.client.qos.PublishQos;
12 import org.xmlBlaster.client.qos.UpdateQos;
13 import org.xmlBlaster.client.I_XmlBlasterAccess;
14 import org.xmlBlaster.util.MsgUnit;
15
16 import java.io.*;
17
18
19 /**
20 * You can use this client to test with tools like OptimizeIt if we
21 * have memory leaks with volatile messages.
22 *
23 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
24 */
25 public class PublishSame
26 {
27 private final String ME = "PublishSame";
28 private static Logger log = Logger.getLogger(PublishSame.class.getName());
29 private I_XmlBlasterAccess con = null;
30 private ConnectReturnQos conRetQos = null;
31 private boolean connected;
32 private int bulkSize = 100;
33 private boolean interactive = true;
34
35 public PublishSame(final Global glob) {
36
37
38 long lCount = 0L;
39 bulkSize = glob.getProperty().get("bulkSize", bulkSize);
40 interactive = glob.getProperty().get("interactive", interactive);
41
42 try {
43 con = glob.getXmlBlasterAccess();
44 ConnectQos qos = new ConnectQos(glob);
45 conRetQos = con.connect(qos, new I_Callback() {
46
47 public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
48 log.info("Receiving asynchronous message '" + updateKey.getOid() +
49 "' state=" + updateQos.getState() + " in default handler");
50 return "";
51 }
52
53 }); // Login to xmlBlaster, default handler for updates
54
55 String xmlKey = null;
56 PublishQos qw = new PublishQos(glob);
57 System.out.println("qos = " + qw.toXml() );
58 byte[] b = new byte[1024];
59 while(true) {
60 lCount++;
61 xmlKey = "<key oid='OneMessage'> <topic id='aaaa'/> </key>";
62 con.publish(new MsgUnit(xmlKey,b,qw.toXml()));
63 // System.out.println(new Timestamp(System.currentTimeMillis())+":"+lCount);
64 if ((lCount % bulkSize) == 0) {
65 try {
66 if (interactive) {
67 log.info("Sent " + lCount + " identical messages, enter return to continue, enter 'q' to quit");
68 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
69 String line = in.readLine(); // Blocking in I/O
70 if (line == null) continue;
71 line = line.trim();
72 if (line.toLowerCase().equals("q")) {
73 break;
74 }
75 }
76 else {
77 log.info("Sent " + lCount + " identical messages, sleeping 10 sec");
78 Thread.sleep(10000);
79 }
80 }
81 catch(Exception e) {
82 log.severe(e.toString());
83 break;
84 }
85 }
86
87 try { Thread.sleep(5L); } catch( InterruptedException i) {}
88 }
89 }
90 catch (XmlBlasterException e) {
91 log.severe("Houston, we have a problem count=" + lCount + ": " + e.toString());
92 }
93 finally {
94 log.info("Success, hit a key to logout and exit");
95 try { System.in.read(); } catch(java.io.IOException e) {}
96 con.disconnect(new DisconnectQos(glob));
97 }
98 }
99
100 /**
101 * Try
102 * <pre>
103 * java org.xmlBlaster.test.memoryleak.PublishSame -help
104 * </pre>
105 * for usage help
106 */
107 public static void main(String args[]) {
108 Global glob = new Global();
109
110 if (glob.init(args) != 0) { // Get help with -help
111 System.out.println(glob.usage());
112 System.out.println("Example: java PublishSame -loginName Jeff\n");
113 System.exit(1);
114 }
115
116 new PublishSame(glob);
117 }
118 }
syntax highlighted by Code2HTML, v. 0.9.1