Monday, January 25, 2010

Queue Monitoring using JMX

public static void main(String[] args) throws Exception {
String hostname = "localhost";
String portString = "7001";
String username = "weblogic";
String password = "weblogic";
MonitorJMS s = new MonitorJMS();
initConnection(hostname, portString, username, password);
s.getJVMData();
s.getJMSData();
connector.close();
}


public static ObjectName getServerRuntimes() throws Exception {
return (ObjectName) connection.getAttribute(service,
"ServerRuntime");
}



public void getJMSData() throws Exception {
ObjectName serverRT = getServerRuntimes();
ObjectName jmsRT = (ObjectName)connection.getAttribute(serverRT, "JMSRuntime");
ObjectName[] jmsServRT = (ObjectName[])connection.getAttribute(jmsRT, "JMSServers");
int compLength = (int) jmsServRT.length;
for (int y = 0; y < compLength; y++) {
ObjectName[] destRT = (ObjectName[])connection.getAttribute(jmsServRT[y], "Destinations");
int compLength1 = (int) destRT.length;
for (int k = 0; k < compLength1; k++) {
System.out.println(" -------------------- ");
System.out.println(" Destination Name : " + connection.getAttribute(destRT[k], "Name"));
Long l = (Long)connection.getAttribute(destRT[k], "MessagesCurrentCount");
System.out.println(" MessagesCurrentCount : " + l);
if(l>0 && y==1){
String curs = (String)connection.invoke(destRT[k],"getMessages",new Object[]{null,new Integer(0)}, new String[]{"java.lang.String","java.lang.Integer"});
Long curs1 = (Long)connection.invoke(destRT[k],"getCursorSize",new Object[]{curs}, new String[]{"java.lang.String"});
Long curs2 = (Long)connection.invoke(destRT[k],"getCursorStartPosition",new Object[]{curs}, new String[]{"java.lang.String"});
CompositeData[] curs3 = (CompositeData[])connection.invoke(destRT[k],"getNext",new Object[]{curs,new Integer(0)}, new String[]{"java.lang.String","java.lang.Integer"});
if(l>1){
CompositeData[] curs4 = (CompositeData[])connection.invoke(destRT[k],"getNext",new Object[]{curs,new Integer(1)}, new String[]{"java.lang.String","java.lang.Integer"});
Collection col = curs4[0].values();
System.out.println(col);
}
System.out.println(curs);
System.out.println(curs1);
System.out.println(curs2);
System.out.println(curs3.length);
System.out.println(curs3);
Collection col = curs3[0].values();
System.out.println(col);
//Long size = ((JMSDestinationRuntimeMBean)destRT[k]).getCursorSize(curs);
//Long size1 = ((JMSDestinationRuntimeMBean)destRT[k]).getCursorStartPosition(curs);
//Long size2 = ((JMSDestinationRuntimeMBean)destRT[k]).getCursorEndPosition(curs);
//System.out.println(size + " : " +size1 + " : " + size2);
}
}
}
}

No comments: