Wednesday, May 21, 2008

First and Only Java CAPS Book is Available

Sun's Michael Czapski has recently published a book about Java CAPS. As far as I know that is the very first book about the subject, it covers the product deeply by showing how to implement common integration design patterns. I hope I can buy a copy soon, it should be available through Amazon.

stcqueueviewer: Dinamically Monitoring JCAPS JMS Server Queues

Disclaimer: the below procedure is undocumented and not officially supported, so you are using this at your own risk only. Please contact Sun's JavaCAPS support or Professional Services for more

I recently had to dynamically monitor some JMS queues within JavaCAPS , especially my need was to count the number of messages in a given queue before posting additional messages, to avoid unnecessary queue flooding. JavaCAPS is fully JMX compliant, the embedded Sun Application Server is well-documented on that side but the SeeBeyond IQ Manager (default JavaCAPS' JMS server implementation) is lacking some info, so I decided to go for some hacking.
My colleague Paul pointed me in the right direction, he suggested to have a look at the com.stc.jms.stcqueueviewer.jar contained into
logicalhost\is\stcms\lib
This library is almost undocumented, so I had to reverse-engineer its classes by using the nice DJ tool. The most interesting file is called Server.java, the Server class contains what is necessary to fully monitor the SeeBeyond IQ manager from a Java program. Below an example:

package queuemonitor;

import com.stc.jms.queueviewer.*;

public class Main {

public static void main(String[] args) throws Exception {

Server sv = new Server();

sv.connect("localhost", 18007, "Administrator", "STC");

QueueStatistics queueStatistics = new QueueStatistics();

sv.getQueueStatistics(queueStatistics, "qStoreDocument");
System.out.println("MinSeqNo=" + queueStatistics.MinSeqNo);
System.out.println("MaxSeqNo=" + queueStatistics.MaxSeqNo);
System.out.println("MessageCount=" + queueStatistics.MessageCount);
sv.disconnect();
}
}

To compile and run this with Netbeans 6 you need to import some additional JAR files from the JavaCAPS Logicalhost logicalhost\is\stcms\lib folder:
  • com.stc.jms.stcjms.jar
  • com.stc.jms.stcqueueviewer.jar
  • jms.jar


By the way, if you have not tried the new Netbeans 6 yet, then shame on you!

If you want instead to do the same within a JavaCAPS JCD you need to execute the following steps:
1. create a new JCD
2. Import the com.stc.jms.stcqueueviewer.jar JAR file into repository
3. Import the above JAR into the JCD


4. Do something useful with the dynamic information you get


The above JCD example is pretty silly, just to show you something

That's it. There other useful methods into Server class, you can explore and discover other interesting things. Hopefully somewhere more queueviewer's documentation is available, so it won't be necessary to decompile the Java classes...