Thanks for replying.
Here’s my full code.
Here’s what it’s doing:
- read client ID from a file.
- Connect to that client
- Get the document names
- Store them in a Hash Map
- Write the Map in a file with each document names and their counts (No. of times they were published)
I have a client with 1000 docs (10 document types each published 100 times). When I ran this code, I got a total of 432 docs (I received 74 of one doc types, 73 of the other, only 37 of another etc…)
Here’s my code:
public static final void getEventFrequencies(IData pipeline)
throws ServiceException {
String broker_host = "localhost:6849";
String broker_name = null;
String client_group = "eventLog";
BrokerClient c;
String client_id;
String everything;
try {
BufferedReader br = new BufferedReader(new FileReader(
"clientID.txt"));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
br.close();
everything = sb.toString();
} catch (IOException ex) {
everything = "";
com.wm.util.JournalLogger.log(3, 90, 3, "" + ex);
}
client_id =everything;
client_id= client_id.trim();
try {
c = BrokerClient.reconnect(broker_host, broker_name, client_id,
null);
com.wm.util.JournalLogger.log(3, 90, 3, "Client working"
+ client_id);
File file = new File("EventNamesWithCounts.txt");
try {
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
try {
Map<String, String> map = new HashMap<String, String>();
String value;
String instring;
int num;
int length;
BrokerEvent[] s;
int count =1;
length = c.getQueueLength();
if (length == 0) {
bw.append("Total Queue Length: " + length);
} else {
bw.append("Total Queue Length: " + length);
bw.newLine();
bw.append("Event Names \t Count");
while(count < 8) {
s = c.getEvents(160, -1);
com.wm.util.JournalLogger.log(3,90,3,"Browse Events: "+ s.length);
bw.newLine();
for (BrokerEvent str : s) {
instring = str.getTypeName();
if (map.containsKey(instring)) {
value = map.get(instring);
num = Integer.parseInt(value);
num = num + 1;
map.put(instring, Integer.toString(num));
} else {
map.put(instring, Integer.toString(1));
}
}
count +=1;
}
for (Map.Entry<String, String> entry : map.entrySet()) {
bw.append(entry.getKey() + "\t\t"
+ entry.getValue());
bw.newLine();
}
}
// com.wm.util.JournalLogger.log(3,90,3,"Length of the Queue: "
// + c.getQueueLength());
} catch (BrokerException ex) {
com.wm.util.JournalLogger.log(3, 90, 3,
"Catch Block: Couldn't Print Queue: " + ex);
// com.wm.util.JournalLogger.log(3,90,3,"EventBrowse Try Block"
// + s.length);
}
bw.close();
} catch (IOException ex) {
com.wm.util.JournalLogger.log(3, 90, 3, "" + ex);
}
try {
c.disconnect();
} catch (BrokerException ex) {
com.wm.util.JournalLogger.log(3, 90, 3,
"Catch block disconnect" + ex);
}
} catch (BrokerException ex) {
com.wm.util.JournalLogger.log(3, 90, 3, "Client ID not working"
+ ex);
}
}
#Integration-Server-and-ESB#webMethods#Universal-Messaging-Broker#broker