Last active
December 19, 2015 00:09
-
-
Save soapplied/5867202 to your computer and use it in GitHub Desktop.
SIB queues message details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void getAllQueuesInfo() { | |
try | |
{ | |
final ObjectName sibMes = new ObjectName( | |
"WebSphere:type=SIBMessagingEngine,*"); | |
final Set sibMesSet = AdminClient.queryNames(sibMes, null); | |
for (Iterator i = sibMesSet.iterator(); i.hasNext();) { | |
final ObjectName meObj = (ObjectName) i.next(); | |
final String meName = meObj.getKeyProperty("name"); | |
final ObjectName queuePoints = new ObjectName( | |
"WebSphere:type=SIBQueuePoint,SIBMessagingEngine=" | |
+ meName + ",*"); | |
final Set queueNameSet = AdminClient.queryNames(queuePoints, | |
null); | |
final Iterator it = queueNameSet.iterator(); | |
while (it.hasNext()) { | |
final ObjectName obj = (ObjectName) it.next(); | |
final String name = obj.getKeyProperty("name"); | |
AttributeList attribList = AdminClient.getAttributes(obj, | |
new String[] { "depth", "state", "id", | |
"highMessageThreshold", "sendAllowed" }); | |
Long depth = null; | |
String state = ""; | |
String id = ""; | |
Long highMessageThreshold = null; | |
Boolean sendAllowed = null; | |
for (Iterator j = attribList.iterator(); j.hasNext();) { | |
final Attribute a = (Attribute) j.next(); | |
if (a.getName().equals("depth")) | |
depth = (Long) a.getValue(); | |
else if (a.getName().equals("state")) | |
state = (String) a.getValue(); | |
else if (a.getName().equals("id")) | |
id = (String) a.getValue(); | |
else if (a.getName().equals("highMessageThreshold")) | |
highMessageThreshold = (Long) a.getValue(); | |
else if (a.getName().equals("sendAllowed")) | |
sendAllowed = (Boolean) a.getValue(); | |
} | |
if (null != depth && depth > 0) { | |
System.out.println("Queue Name:" + name | |
+ " has queue depth:" + depth); | |
final SIBQueuedMessage[] msgs = getQueueMessages(obj); | |
if (null != msgs){ | |
System.out | |
.println("--------------------------------------------------------------"); | |
printQueueMessages(obj, msgs); | |
System.out | |
.println("--------------------------------------------------------------"); | |
} | |
} | |
} | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
private static void printQueueMessages(ObjectName obj,SIBQueuedMessage[] msgs) { | |
System.out | |
.println("--------------------------------------------------------------"); | |
for (int i = 0; i < msgs.length; i++) { | |
SIBQueuedMessage msg = (SIBQueuedMessage) msgs[i]; | |
try { | |
System.out.println("id:" + msg.getId() + ", name:" | |
+ msg.getName() + ", state:" + msg.getState() | |
+ ", transactionID:" + msg.getTransactionId() | |
+ ", type:" + msg.getType()); | |
printQueueMessageDetail(getQueueMessageDetail(obj, msg.getId())); | |
System.out.println(getMessageBytesForDisplay(msg.getId(), | |
getQueueMessageContents(obj, msg.getId()))); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
System.out | |
.println("--------------------------------------------------------------"); | |
} | |
private static void printQueueMessageDetail(SIBQueuedMessageDetail s) { | |
System.out.println("BusDiscriminator:" + s.getBusDiscriminator()); | |
System.out.println("BusPriority:" + s.getBusPriority()); | |
System.out.println("BusReliability:" + s.getBusReliability()); | |
System.out.println("BusTimeToLive:" + s.getBusTimeToLive()); | |
System.out.println("BusReplyDiscriminator:" + s.getBusReplyDiscriminator()); | |
System.out.println("BusReplyPriority:" + s.getBusReplyPriority()); | |
System.out.println("BusSystemMessageId:" + s.getBusSystemMessageId()); | |
System.out.println("ExceptionMessage:" + s.getExceptionMessage()); | |
System.out.println("JsMessageType:" + s.getJsMessageType()); | |
System.out.println("JsMessageWaitTime:" + s.getJsMessageWaitTime()); | |
} | |
private static SIBQueuedMessage[] getQueueMessages(ObjectName obj) | |
{ | |
SIBQueuedMessage[] msgs = null; | |
try { | |
msgs = (SIBQueuedMessage[]) AdminClient.invoke(obj, | |
"getQueuedMessages", null, null); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return msgs; | |
} | |
private static byte[] getQueueMessageContents(ObjectName obj, String msgId) { | |
byte[] msgContents = null; | |
try { | |
msgContents = (byte[]) AdminClient.invoke(obj, "getMessageData", | |
new Object[] { msgId, new Integer(0x19000) }, new String[] { | |
"java.lang.String", "java.lang.Integer" }); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return msgContents; | |
} | |
private static SIBQueuedMessageDetail getQueueMessageDetail(ObjectName obj,String id) { | |
SIBQueuedMessageDetail sqmd = null; | |
try { | |
sqmd = (SIBQueuedMessageDetail) AdminClient.invoke(obj, | |
"getQueuedMessageDetail", new Object[] { id }, | |
new String[] { "java.lang.String" }); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return sqmd; | |
} | |
private static String getMessageBytesForDisplay(String messageId,byte msgContents[]) { | |
StringBuffer sb = new StringBuffer(); | |
sb.append("Contents of Message ").append(messageId).append(":\r\n\r\n"); | |
if (msgContents != null) { | |
int dataLength = msgContents.length; | |
sb.append("Data length = 0x").append( | |
Integer.toHexString(dataLength)).append(" (").append( | |
dataLength).append(") bytes\r\n\r\n"); | |
sb.append(" : 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 2 4 6 8 A C E \r\n"); | |
String cur[] = new String[16]; | |
String str[] = new String[16]; | |
for (int j = 0; j < 16; j++) { | |
cur[j] = null; | |
str[j] = null; | |
} | |
for (int x = 0; x < dataLength; x += 16) { | |
for (int y = 0; y < 16; y++) { | |
int t = x + y; | |
if (t < dataLength) { | |
cur[y] = pad(Integer.toHexString(msgContents[t]), 2, | |
null); | |
if (msgContents[t] < 32) | |
str[y] = "."; | |
else | |
str[y] = new String(msgContents, t, 1); | |
} else { | |
cur[y] = " "; | |
str[y] = "."; | |
} | |
} | |
sb.append("0x" + pad(Integer.toHexString(x), 8, null) + " (" | |
+ pad((new Integer(x)).toString(), 8, " ") + ") : "); | |
sb.append(cur[0] + cur[1] + cur[2] + cur[3] + " " + cur[4] | |
+ cur[5] + cur[6] + cur[7] + " " + cur[8] + cur[9] | |
+ cur[10] + cur[11] + " " + cur[12] + cur[13] + cur[14] | |
+ cur[15]); | |
sb.append(" | "); | |
sb.append(str[0] + str[1] + str[2] + str[3] + str[4] + str[5] | |
+ str[6] + str[7] + str[8] + str[9] + str[10] + str[11] | |
+ str[12] + str[13] + str[14] + str[15]); | |
sb.append("\r\n"); | |
} | |
} | |
return sb.toString(); | |
} | |
private static String pad(String str, int length, String initial) { | |
if (initial == null) | |
initial = "0"; | |
String rc; | |
if (str.length() < length) { | |
StringBuffer sb = new StringBuffer(); | |
for (int i = 0; i < length - str.length(); i++) | |
sb.append(initial); | |
rc = new String(sb.toString() + str); | |
} else { | |
rc = str.substring(str.length() - length); | |
} | |
return rc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment