use of org.apache.activemq.artemis.core.transaction.TransactionDetail in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method listPreparedTransactionDetailsAsJSON.
public String listPreparedTransactionDetailsAsJSON(TransactionDetailFactory factory) throws Exception {
checkStarted();
clearIO();
try {
Map<Xid, Long> xids = resourceManager.getPreparedTransactionsWithCreationTime();
if (xids == null || xids.size() == 0) {
return "";
}
ArrayList<Entry<Xid, Long>> xidsSortedByCreationTime = new ArrayList<>(xids.entrySet());
Collections.sort(xidsSortedByCreationTime, new Comparator<Entry<Xid, Long>>() {
@Override
public int compare(final Entry<Xid, Long> entry1, final Entry<Xid, Long> entry2) {
// sort by creation time, oldest first
return (int) (entry1.getValue() - entry2.getValue());
}
});
JsonArrayBuilder txDetailListJson = JsonLoader.createArrayBuilder();
for (Map.Entry<Xid, Long> entry : xidsSortedByCreationTime) {
Xid xid = entry.getKey();
Transaction tx = resourceManager.getTransaction(xid);
if (tx == null) {
continue;
}
TransactionDetail detail = factory.createTransactionDetail(xid, tx, entry.getValue());
txDetailListJson.add(detail.toJSON());
}
return txDetailListJson.build().toString();
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.transaction.TransactionDetail in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method listPreparedTransactionDetailsAsHTML.
public String listPreparedTransactionDetailsAsHTML(TransactionDetailFactory factory) throws Exception {
checkStarted();
clearIO();
try {
Map<Xid, Long> xids = resourceManager.getPreparedTransactionsWithCreationTime();
if (xids == null || xids.size() == 0) {
return "<h3>*** Prepared Transaction Details ***</h3><p>No entry.</p>";
}
ArrayList<Entry<Xid, Long>> xidsSortedByCreationTime = new ArrayList<>(xids.entrySet());
Collections.sort(xidsSortedByCreationTime, new Comparator<Entry<Xid, Long>>() {
@Override
public int compare(final Entry<Xid, Long> entry1, final Entry<Xid, Long> entry2) {
// sort by creation time, oldest first
return (int) (entry1.getValue() - entry2.getValue());
}
});
StringBuilder html = new StringBuilder();
html.append("<h3>*** Prepared Transaction Details ***</h3>");
for (Map.Entry<Xid, Long> entry : xidsSortedByCreationTime) {
Xid xid = entry.getKey();
Transaction tx = resourceManager.getTransaction(xid);
if (tx == null) {
continue;
}
TransactionDetail detail = factory.createTransactionDetail(xid, tx, entry.getValue());
JsonObject txJson = detail.toJSON();
html.append("<table border=\"1\">");
html.append("<tr><th>creation_time</th>");
html.append("<td>" + txJson.get(TransactionDetail.KEY_CREATION_TIME) + "</td>");
html.append("<th>xid_as_base_64</th>");
html.append("<td colspan=\"3\">" + txJson.get(TransactionDetail.KEY_XID_AS_BASE64) + "</td></tr>");
html.append("<tr><th>xid_format_id</th>");
html.append("<td>" + txJson.get(TransactionDetail.KEY_XID_FORMAT_ID) + "</td>");
html.append("<th>xid_global_txid</th>");
html.append("<td>" + txJson.get(TransactionDetail.KEY_XID_GLOBAL_TXID) + "</td>");
html.append("<th>xid_branch_qual</th>");
html.append("<td>" + txJson.get(TransactionDetail.KEY_XID_BRANCH_QUAL) + "</td></tr>");
html.append("<tr><th colspan=\"6\">Message List</th></tr>");
html.append("<tr><td colspan=\"6\">");
html.append("<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">");
JsonArray msgs = txJson.getJsonArray(TransactionDetail.KEY_TX_RELATED_MESSAGES);
for (int i = 0; i < msgs.size(); i++) {
JsonObject msgJson = msgs.getJsonObject(i);
JsonObject props = msgJson.getJsonObject(TransactionDetail.KEY_MSG_PROPERTIES);
StringBuilder propstr = new StringBuilder();
Set<String> keys = props.keySet();
for (String key : keys) {
propstr.append(key);
propstr.append("=");
propstr.append(props.get(key));
propstr.append(", ");
}
html.append("<th>operation_type</th>");
html.append("<td>" + msgJson.get(TransactionDetail.KEY_MSG_OP_TYPE) + "</th>");
html.append("<th>message_type</th>");
html.append("<td>" + msgJson.get(TransactionDetail.KEY_MSG_TYPE) + "</td></tr>");
html.append("<tr><th>properties</th>");
html.append("<td colspan=\"3\">" + propstr.toString() + "</td></tr>");
}
html.append("</table></td></tr>");
html.append("</table><br>");
}
return html.toString();
} finally {
blockOnIO();
}
}
Aggregations