use of com.sun.messaging.jmq.util.admin.DurableInfo in project openmq by eclipse-ee4j.
the class GetDurablesHandler method handle.
/**
* Handle the incomming administration message.
*
* @param con The Connection the message came in on.
* @param cmd_msg The administration message
* @param cmd_props The properties from the administration message
*/
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + cmd_props);
}
String destination = (String) cmd_props.get(MessageType.JMQ_DESTINATION);
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
int status = Status.OK;
Vector v = null;
String err = null;
try {
DestinationUID duid = null;
if (destination != null) {
duid = DestinationUID.getUID(destination, false);
}
Set s = Subscription.getAllSubscriptions(duid);
v = new Vector();
Iterator itr = s.iterator();
while (itr.hasNext()) {
Subscription sub = (Subscription) itr.next();
DurableInfo di = new DurableInfo();
di.isDurable = sub.isDurable();
di.isShared = sub.getShared();
di.isJMSShared = sub.getJMSShared();
if (di.isDurable) {
di.name = sub.getDurableName();
} else if (di.isJMSShared) {
di.name = sub.getNDSubscriptionName();
}
di.clientID = sub.getClientID();
di.isActive = sub.isActive();
di.uidString = String.valueOf(sub.getConsumerUID().longValue());
List children = sub.getChildConsumers();
di.activeCount = children.size();
di.activeConsumers = new LinkedHashMap<>();
Iterator itr1 = children.iterator();
while (itr1.hasNext()) {
Consumer c = (Consumer) itr1.next();
ConsumerInfo cinfo = new ConsumerInfo();
cinfo.connection = new ConnectionInfo();
cinfo.connection.uuid = c.getConsumerUID().getConnectionUID().longValue();
cinfo.uidString = String.valueOf(c.getConsumerUID().longValue());
ConsumerUID uid = c.getStoredConsumerUID();
if (uid != null) {
cinfo.subuidString = String.valueOf(uid.longValue());
}
BrokerAddress addr = c.getConsumerUID().getBrokerAddress();
if (addr != null) {
cinfo.brokerAddressShortString = addr.getMQAddress().getHostAddressNPort() + (addr.getBrokerID() == null ? "" : "[" + addr.getBrokerID() + "]");
}
di.activeConsumers.put(cinfo.uidString, cinfo);
}
di.nMessages = sub.numInProcessMsgs();
di.consumer = new ConsumerInfo();
// Ok, I'm not setting id because it really should be an int, maybe later
di.consumer.destination = sub.getDestinationUID().getName();
di.consumer.type = DestType.DEST_TYPE_TOPIC;
di.consumer.selector = sub.getSelectorStr();
// not bothering with the connection this time either
di.consumer.connection = null;
v.add(di);
}
} catch (BrokerException ex) {
err = ex.getMessage();
status = ex.getStatusCode();
}
setProperties(reply, MessageType.GET_DURABLES_REPLY, status, err);
setBodyObject(reply, v);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.util.admin.DurableInfo in project openmq by eclipse-ee4j.
the class CmdRunner method runGetAttr.
private int runGetAttr(BrokerCmdProperties brokerCmdProps, List result) {
BrokerAdmin broker;
int retValue = 1;
broker = init();
try {
// Check for the target argument.
// Valid value are dst, svc, and bkr.
String commandArg = brokerCmdProps.getCommandArg();
if (CMDARG_DESTINATION.equals(commandArg)) {
if (broker == null) {
Globals.stdOutPrintln("Problems connecting to the broker.");
retValue = 1;
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String destName = brokerCmdProps.getTargetName();
int destTypeMask = getDestTypeMask(brokerCmdProps);
String attrName = brokerCmdProps.getSingleTargetAttr();
try {
connectToBroker(broker);
broker.sendGetDestinationsMessage(destName, destTypeMask);
Vector dest = broker.receiveGetDestinationsReplyMessage();
if ((dest != null) && (dest.size() == 1)) {
Enumeration thisEnum = dest.elements();
DestinationInfo dInfo = (DestinationInfo) thisEnum.nextElement();
if (PROP_NAME_OPTION_MAX_MESG_BYTE.equals(attrName)) {
Globals.stdOutPrintln(Long.toString(dInfo.maxMessageBytes));
retValue = 0;
} else if (PROP_NAME_OPTION_MAX_MESG.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(dInfo.maxMessages));
retValue = 0;
} else if (PROP_NAME_OPTION_MAX_PER_MESG_SIZE.equals(attrName)) {
Globals.stdOutPrintln(Long.toString(dInfo.maxMessageSize));
retValue = 0;
} else if (PROP_NAME_OPTION_CUR_MESG_BYTE.equals(attrName)) {
Globals.stdOutPrintln(Long.toString(dInfo.nMessageBytes));
retValue = 0;
} else if (PROP_NAME_OPTION_CUR_MESG.equals(attrName)) {
String val = Integer.toString(dInfo.nMessages);
Globals.stdOutPrintln(val);
if (result != null) {
result.add(val);
}
retValue = 0;
} else if (PROP_NAME_OPTION_CUR_UNACK_MESG.equals(attrName)) {
String val = Integer.toString(dInfo.nUnackMessages);
Globals.stdOutPrintln(val);
if (result != null) {
result.add(val);
}
retValue = 0;
} else if (PROP_NAME_OPTION_CUR_PRODUCERS.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(dInfo.nProducers));
retValue = 0;
} else if (PROP_NAME_MAX_FAILOVER_CONSUMER_COUNT.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(dInfo.maxFailoverConsumers));
retValue = 0;
} else if (PROP_NAME_MAX_ACTIVE_CONSUMER_COUNT.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(dInfo.maxActiveConsumers));
retValue = 0;
} else if (PROP_NAME_IS_LOCAL_DEST.equals(attrName)) {
if (dInfo.isDestinationLocal()) {
Globals.stdOutPrintln(Boolean.TRUE.toString());
} else {
Globals.stdOutPrintln(Boolean.FALSE.toString());
}
retValue = 0;
} else if (PROP_NAME_LIMIT_BEHAVIOUR.equals(attrName)) {
Globals.stdOutPrintln(DestLimitBehavior.getString(dInfo.destLimitBehavior));
retValue = 0;
} else if (PROP_NAME_LOCAL_DELIVERY_PREF.equals(attrName)) {
int cdp = dInfo.destCDP;
if (cdp == ClusterDeliveryPolicy.LOCAL_PREFERRED) {
Globals.stdOutPrintln(Boolean.TRUE.toString());
} else {
Globals.stdOutPrintln(Boolean.FALSE.toString());
}
retValue = 0;
} else if (PROP_NAME_CONSUMER_FLOW_LIMIT.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(dInfo.maxPrefetch));
retValue = 0;
} else if (PROP_NAME_MAX_PRODUCERS.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(dInfo.maxProducers));
retValue = 0;
} else if (PROP_NAME_OPTION_CUR_A_CONSUMERS.equals(attrName)) {
String val = null;
if (DestType.isQueue(destTypeMask)) {
val = Integer.toString(dInfo.naConsumers);
Globals.stdOutPrintln(val);
} else {
val = Integer.toString(dInfo.nConsumers);
Globals.stdOutPrintln(val);
}
if (result != null) {
result.add(val);
}
retValue = 0;
} else if (PROP_NAME_OPTION_CUR_B_CONSUMERS.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(dInfo.nfConsumers));
retValue = 0;
} else if (PROP_NAME_USE_DMQ.equals(attrName)) {
Globals.stdOutPrintln(Boolean.toString(dInfo.useDMQ()));
retValue = 0;
} else if (PROP_NAME_VALIDATE_XML_SCHEMA_ENABLED.equals(attrName)) {
Globals.stdOutPrintln(Boolean.toString(dInfo.validateXMLSchemaEnabled()));
retValue = 0;
} else if (PROP_NAME_XML_SCHEMA_URI_LIST.equals(attrName)) {
Globals.stdOutPrintln(dInfo.XMLSchemaUriList);
retValue = 0;
} else if (PROP_NAME_RELOAD_XML_SCHEMA_ON_FAILURE.equals(attrName)) {
Globals.stdOutPrintln(Boolean.toString(dInfo.reloadXMLSchemaOnFailure()));
retValue = 0;
} else {
// Should not get here since we check for valid attribute
// names in BrokerCmd.checkGetAttr().
Globals.stdErrPrintln(attrName + " is not recognized.");
retValue = 1;
return (1);
}
} else {
Globals.stdErrPrintln("Problems retrieving the destination info.");
retValue = 1;
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
retValue = 1;
return (1);
}
return (retValue);
} else if (CMDARG_SERVICE.equals(commandArg)) {
if (broker == null) {
Globals.stdOutPrintln("Problems connecting to the broker.");
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String svcName = brokerCmdProps.getTargetName();
String attrName = brokerCmdProps.getSingleTargetAttr();
try {
connectToBroker(broker);
broker.sendGetServicesMessage(svcName);
Vector svc = broker.receiveGetServicesReplyMessage();
if ((svc != null) && (svc.size() == 1)) {
Enumeration thisEnum = svc.elements();
ServiceInfo sInfo = (ServiceInfo) thisEnum.nextElement();
if (BrokerCmdOptions.PROP_NAME_SVC_PORT.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(sInfo.port));
retValue = 0;
} else if (BrokerCmdOptions.PROP_NAME_SVC_MIN_THREADS.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(sInfo.minThreads));
retValue = 0;
} else if (BrokerCmdOptions.PROP_NAME_SVC_MAX_THREADS.equals(attrName)) {
Globals.stdOutPrintln(Integer.toString(sInfo.maxThreads));
retValue = 0;
} else {
// Should not get here since we check for valid attribute
// names in BrokerCmd.checkGetAttr().
Globals.stdOutPrintln(attrName + " is not recognized.");
retValue = 1;
return (1);
}
} else {
Globals.stdOutPrintln("Problems retrieving the service info.");
retValue = 1;
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
retValue = 1;
return (1);
}
return (retValue);
} else if (CMDARG_BROKER.equals(commandArg)) {
if (broker == null) {
Globals.stdOutPrintln("Problems connecting to the broker.");
retValue = 1;
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String attrName = brokerCmdProps.getSingleTargetAttr();
try {
connectToBroker(broker);
broker.sendGetBrokerPropsMessage();
Properties bkrProps = broker.receiveGetBrokerPropsReplyMessage();
if (bkrProps == null) {
Globals.stdOutPrintln("Problems retrieving the broker info.");
retValue = 1;
return (1);
}
String value;
value = bkrProps.getProperty(attrName, "");
Globals.stdOutPrintln(value);
retValue = 0;
/*
* if (PROP_NAME_BKR_PRIMARY_PORT.equals(attrName)) { value = bkrProps.getProperty(PROP_NAME_BKR_PRIMARY_PORT, "");
* Globals.stdOutPrintln(value); retValue = 0;
*
* } else if (PROP_NAME_BKR_AUTOCREATE_TOPIC.equals(attrName)) { value =
* bkrProps.getProperty(PROP_NAME_BKR_AUTOCREATE_TOPIC, ""); Globals.stdOutPrintln(value); retValue = 0;
*
* } else if (PROP_NAME_BKR_AUTOCREATE_QUEUE.equals(attrName)) { value =
* bkrProps.getProperty(PROP_NAME_BKR_AUTOCREATE_QUEUE, ""); Globals.stdOutPrintln(value); retValue = 0;
*
* } else if (PROP_NAME_BKR_MAX_MSG.equals(attrName)) { value = bkrProps.getProperty(PROP_NAME_BKR_MAX_MSG, "");
* Globals.stdOutPrintln(value); retValue = 0;
*
* } else if (PROP_NAME_BKR_MAX_TTL_MSG_BYTES.equals(attrName)) { value =
* bkrProps.getProperty(PROP_NAME_BKR_MAX_TTL_MSG_BYTES, ""); Globals.stdOutPrintln(value); retValue = 0;
*
* } else if (PROP_NAME_BKR_MAX_MSG_BYTES.equals(attrName)) { value = bkrProps.getProperty(PROP_NAME_BKR_MAX_MSG_BYTES,
* ""); Globals.stdOutPrintln(value); retValue = 0;
*
* } else if (PROP_NAME_BKR_CUR_MSG.equals(attrName)) { value = bkrProps.getProperty(PROP_NAME_BKR_CUR_MSG, "");
* Globals.stdOutPrintln(value); retValue = 0;
*
* } else if (PROP_NAME_BKR_CUR_TTL_MSG_BYTES.equals(attrName)) { value =
* bkrProps.getProperty(PROP_NAME_BKR_CUR_TTL_MSG_BYTES, ""); Globals.stdOutPrintln(value); retValue = 0;
*
* } else { // Should not get here since we check for valid attribute // names in BrokerCmd.checkGetAttr().
* Globals.stdOutPrintln(attrName + " is not recognized."); retValue = 1; return (1); }
*/
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
retValue = 1;
return (1);
}
} else if (CMDARG_DURABLE.equals(commandArg)) {
String destName = brokerCmdProps.getDestName();
String subName = brokerCmdProps.getTargetName();
String clientID = brokerCmdProps.getClientID();
String attrName = brokerCmdProps.getSingleTargetAttr();
if (!BrokerCmdOptions.PROP_NAME_OPTION_CUR_A_CONSUMERS.equals(attrName)) {
return 1;
}
if (broker == null) {
Globals.stdOutPrintln("Problems connecting to the broker.");
retValue = 1;
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force) {
broker = promptForAuthentication(broker);
}
try {
connectToBroker(broker);
if (destName != null) {
isDestTypeTopic(broker, destName);
}
broker.sendGetDurablesMessage(destName, null);
Vector durs = broker.receiveGetDurablesReplyMessage();
retValue = 1;
Enumeration thisEnum = durs.elements();
while (thisEnum.hasMoreElements()) {
DurableInfo dinfo = (DurableInfo) thisEnum.nextElement();
if (subName != null) {
if (dinfo.name.equals(subName)) {
String val = null;
if (clientID != null && clientID.equals(dinfo.clientID)) {
val = Integer.toString(dinfo.activeCount);
Globals.stdOutPrintln(val);
} else {
val = Integer.toString(dinfo.activeCount);
Globals.stdOutPrintln(val);
}
if (result != null) {
result.add(val);
}
return 0;
}
} else if (destName != null && dinfo.consumer != null && destName.equals(dinfo.consumer.destination)) {
if (clientID != null && clientID.equals(dinfo.clientID)) {
Globals.stdOutPrintln(Integer.toString(dinfo.activeCount));
return 0;
} else {
Globals.stdOutPrintln(Integer.toString(dinfo.activeCount));
return 0;
}
}
}
Globals.stdErrPrintln("Subscription not found.");
return 1;
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
return (1);
}
} else if (CMDARG_TRANSACTION.equals(commandArg)) {
String attrName = brokerCmdProps.getSingleTargetAttr();
if (broker == null) {
Globals.stdOutPrintln("Problems connecting to the broker.");
retValue = 1;
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force) {
broker = promptForAuthentication(broker);
}
try {
connectToBroker(broker);
broker.sendGetTxnsMessage(brokerCmdProps.showPartitionModeSet());
Vector txns = broker.receiveGetTxnsReplyMessage();
if (txns == null) {
throw new BrokerAdminException(BrokerAdminException.REPLY_NOT_RECEIVED);
}
if (BrokerCmdOptions.PROP_NAME_OPTION_CUR_TXNS.equals(attrName)) {
String val = String.valueOf(txns.size());
Globals.stdOutPrintln(val);
if (result != null) {
result.add(val);
}
retValue = 0;
} else if (BrokerCmdOptions.PROP_NAME_OPTION_ALL_TXNS.equals(attrName)) {
Globals.stdOutPrintln(txns.toString());
if (result != null) {
result.addAll(txns);
}
retValue = 0;
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
return (1);
}
}
return (retValue);
} finally {
if (broker != null) {
if (retValue == 1) {
broker.forceClose();
} else {
broker.close();
}
}
}
}
use of com.sun.messaging.jmq.util.admin.DurableInfo in project openmq by eclipse-ee4j.
the class CmdRunner method runList.
/*
* END INTERFACE AdminEventListener
*/
private int runList(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
broker = init();
// Check for the target argument
String commandArg = brokerCmdProps.getCommandArg(), destTypeStr = brokerCmdProps.getDestType();
int destTypeMask = getDestTypeMask(brokerCmdProps);
boolean listAll = (destTypeStr == null);
if (CMDARG_DESTINATION.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_DST_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
if (listAll) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_DST));
} else if (DestType.isQueue(destTypeMask)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_QUEUE_DST));
} else if (DestType.isTopic(destTypeMask)) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_TOPIC_DST));
}
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetDestinationsMessage(null, -1, brokerCmdProps.showPartitionModeSet(), brokerCmdProps.loadDestinationSet());
Vector dests = broker.receiveGetDestinationsReplyMessage();
if (dests != null) {
if (listAll) {
listDests(brokerCmdProps, dests, LIST_ALL);
} else if (DestType.isTopic(destTypeMask)) {
listDests(brokerCmdProps, dests, LIST_TOPIC);
} else if (DestType.isQueue(destTypeMask)) {
listDests(brokerCmdProps, dests, LIST_QUEUE);
}
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_DST_SUC));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_DST_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_DST_FAIL));
return (1);
}
} else if (CMDARG_SERVICE.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SVC_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_SVC));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetServicesMessage(null);
Vector svcs = broker.receiveGetServicesReplyMessage();
if (svcs != null) {
BrokerCmdPrinter bcp = new BrokerCmdPrinter(3, 4, "-");
String[] row = new String[3];
row[0] = ar.getString(ar.I_JMQCMD_SVC_NAME);
row[1] = ar.getString(ar.I_JMQCMD_SVC_PORT);
row[2] = ar.getString(ar.I_JMQCMD_SVC_STATE);
bcp.addTitle(row);
Enumeration thisEnum = svcs.elements();
while (thisEnum.hasMoreElements()) {
ServiceInfo sInfo = (ServiceInfo) thisEnum.nextElement();
row[0] = sInfo.name;
// The port number is not applicable to this service
if (sInfo.port == -1) {
row[1] = "-";
// Add more information about the port number:
// dynamically generated or statically declared
} else if (sInfo.dynamicPort) {
switch(sInfo.state) {
case ServiceState.UNKNOWN:
row[1] = ar.getString(ar.I_DYNAMIC);
break;
default:
row[1] = Integer.toString(sInfo.port) + " (" + ar.getString(ar.I_DYNAMIC) + ")";
}
} else {
row[1] = Integer.toString(sInfo.port) + " (" + ar.getString(ar.I_STATIC) + ")";
}
// row[2] = ServiceState.getString(sInfo.state);
row[2] = BrokerAdminUtil.getServiceState(sInfo.state);
bcp.add(row);
}
bcp.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_SVC_SUC));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SVC_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SVC_FAIL));
return (1);
}
} else if (CMDARG_DURABLE.equals(commandArg)) {
// display dst if we list all
boolean listDstName = false;
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SUB_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String destName = brokerCmdProps.getDestName();
if (destName != null)
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_SUB, destName));
else
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_ALL_SUB));
printBrokerInfo(broker);
try {
connectToBroker(broker);
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SUB_FAIL));
return (1);
}
try {
if (destName == null) {
listDstName = true;
} else {
isDestTypeTopic(broker, destName);
}
} catch (BrokerAdminException bae) {
if (BrokerAdminException.INVALID_OPERATION == bae.getType())
bae.setBrokerErrorStr(ar.getString(ar.I_ERROR_MESG) + ar.getKString(ar.E_DEST_NOT_TOPIC, destName));
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SUB_FAIL));
return (1);
}
try {
broker.sendGetDurablesMessage(destName, null);
Vector durs = broker.receiveGetDurablesReplyMessage();
if (durs != null) {
BrokerCmdPrinter bcp = null;
String[] row = null;
if (listDstName) {
row = new String[6];
bcp = new BrokerCmdPrinter(6, 3, "-");
} else {
row = new String[5];
bcp = new BrokerCmdPrinter(5, 3, "-");
}
if (brokerCmdProps.detailModeSet()) {
bcp.setSortNeeded(false);
}
int indx = 0;
row[indx++] = ar.getString(ar.I_JMQCMD_SUB_NAME);
row[indx++] = ar.getString(ar.I_JMQCMD_CLIENT_ID);
if (listDstName)
row[indx++] = ar.getString(ar.I_JMQCMD_DST_NAME);
row[indx++] = ar.getString(ar.I_JMQCMD_DURABLE);
row[indx++] = ar.getString(ar.I_JMQCMD_SUB_NUM_MSG);
row[indx++] = ar.getString(ar.I_JMQCMD_SUB_STATE);
bcp.addTitle(row);
Enumeration thisEnum = durs.elements();
while (thisEnum.hasMoreElements()) {
DurableInfo dInfo = (DurableInfo) thisEnum.nextElement();
indx = 0;
row[indx++] = (dInfo.name == null) ? "" : dInfo.name;
row[indx++] = (dInfo.clientID == null) ? "" : dInfo.clientID;
if (listDstName) {
row[indx++] = (dInfo.consumer == null) ? "" : dInfo.consumer.destination;
}
row[indx++] = String.valueOf(dInfo.isDurable);
row[indx++] = Integer.toString(dInfo.nMessages);
if (dInfo.isActive) {
if (dInfo.isShared) {
row[indx] = ar.getString(ar.I_ACTIVE) + "[" + dInfo.activeCount + "]" + (dInfo.isJMSShared ? "jms" : "mq");
} else {
row[indx] = ar.getString(ar.I_ACTIVE);
}
} else {
if (dInfo.isShared) {
row[indx] = ar.getString(ar.I_INACTIVE) + "[0]" + (dInfo.isJMSShared ? "jms" : "mq");
} else {
row[indx] = ar.getString(ar.I_INACTIVE);
}
}
if (brokerCmdProps.detailModeSet()) {
row[indx] = row[indx] + ", [" + dInfo.uidString + "]";
}
indx++;
bcp.add(row);
if (brokerCmdProps.detailModeSet()) {
if (dInfo.activeConsumers == null) {
continue;
}
for (Map.Entry<String, ConsumerInfo> pair : dInfo.activeConsumers.entrySet()) {
ConsumerInfo cinfo = pair.getValue();
String cinfostr = null;
if (cinfo.connection != null) {
cinfostr = "[" + cinfo.uidString + ", " + cinfo.subuidString + ", [" + cinfo.connection.uuid + ", " + cinfo.connection + "], " + cinfo.brokerAddressShortString + "]";
} else {
cinfostr = "[" + cinfo.uidString + ", " + cinfo.subuidString + ", " + cinfo.brokerAddressShortString + "]";
}
int tmpindx = 0;
row[tmpindx++] = " ";
row[tmpindx++] = " ";
if (listDstName) {
row[tmpindx++] = " ";
}
row[tmpindx++] = " ";
row[tmpindx++] = " ";
row[tmpindx++] = cinfostr;
bcp.add(row);
}
}
}
// Use durname+clientID as the key when listing.
bcp.setKeyCriteria(new int[] { 0, 1 });
bcp.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_SUB_SUC));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SUB_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_SUB_FAIL));
return (1);
}
} else if (CMDARG_TRANSACTION.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_TXN_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_TXN));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetTxnsMessage(brokerCmdProps.showPartitionModeSet());
Vector txns = broker.receiveGetTxnsReplyMessage();
if (txns != null && !txns.isEmpty()) {
BrokerCmdPrinter bcp = new BrokerCmdPrinter(5, 3, "-");
BrokerCmdPrinter bcp_local = new BrokerCmdPrinter(4, 3, "-");
BrokerCmdPrinter bcp_remote = new BrokerCmdPrinter(4, 3, "-");
String[] row = new String[5];
Long tmpLong;
Integer tmpInt;
String tmpStr, tmpStr2;
row[0] = ar.getString(ar.I_JMQCMD_TXN_ID);
row[1] = ar.getString(ar.I_JMQCMD_TXN_STATE);
row[2] = ar.getString(ar.I_JMQCMD_TXN_USERNAME);
row[3] = ar.getString(ar.I_JMQCMD_TXN_NUM_MSGS_ACKS);
row[4] = ar.getString(ar.I_JMQCMD_TXN_TIMESTAMP);
bcp.addTitle(row);
row[0] = ar.getString(ar.I_JMQCMD_TXN_ID);
row[1] = ar.getString(ar.I_JMQCMD_TXN_STATE);
row[2] = ar.getString(ar.I_JMQCMD_TXN_USERNAME);
row[3] = ar.getString(ar.I_JMQCMD_TXN_TIMESTAMP);
bcp_local.addTitle(row);
row[0] = ar.getString(ar.I_JMQCMD_TXN_ID);
row[1] = ar.getString(ar.I_JMQCMD_TXN_STATE);
row[2] = "# Acks";
row[3] = "Remote broker";
bcp_remote.addTitle(row);
Enumeration thisEnum = txns.elements();
while (thisEnum.hasMoreElements()) {
Hashtable txnInfo = (Hashtable) thisEnum.nextElement();
Integer type = (Integer) txnInfo.get("type");
if (type.intValue() == TXN_LOCAL) {
tmpStr = (String) txnInfo.get(PROP_NAME_TXN_ID);
row[0] = checkNullAndPrint(tmpStr);
tmpInt = (Integer) txnInfo.get(PROP_NAME_TXN_STATE);
row[1] = getTxnStateString(tmpInt);
tmpStr = (String) txnInfo.get(PROP_NAME_TXN_USER);
row[2] = checkNullAndPrint(tmpStr);
tmpInt = (Integer) txnInfo.get(PROP_NAME_TXN_NUM_MSGS);
tmpStr = checkNullAndPrint(tmpInt);
tmpInt = (Integer) txnInfo.get(PROP_NAME_TXN_NUM_ACKS);
tmpStr2 = checkNullAndPrint(tmpInt);
row[3] = tmpStr + "/" + tmpStr2;
tmpLong = (Long) txnInfo.get(PROP_NAME_TXN_TIMESTAMP);
row[4] = checkNullAndPrintTimestamp(tmpLong);
bcp.add(row);
} else if (type.intValue() == TXN_CLUSTER) {
tmpStr = (String) txnInfo.get(PROP_NAME_TXN_ID);
row[0] = checkNullAndPrint(tmpStr);
tmpInt = (Integer) txnInfo.get(PROP_NAME_TXN_STATE);
row[1] = getTxnStateString(tmpInt);
tmpStr = (String) txnInfo.get(PROP_NAME_TXN_USER);
row[2] = checkNullAndPrint(tmpStr);
tmpLong = (Long) txnInfo.get(PROP_NAME_TXN_TIMESTAMP);
row[3] = checkNullAndPrintTimestamp(tmpLong);
bcp_local.add(row);
} else if (type.intValue() == TXN_REMOTE) {
tmpStr = (String) txnInfo.get(PROP_NAME_TXN_ID);
row[0] = checkNullAndPrint(tmpStr);
tmpInt = (Integer) txnInfo.get(PROP_NAME_TXN_STATE);
row[1] = getTxnStateString(tmpInt);
tmpInt = (Integer) txnInfo.get(PROP_NAME_TXN_NUM_ACKS);
tmpStr2 = checkNullAndPrint(tmpInt);
row[2] = tmpStr2;
tmpStr = (String) txnInfo.get("homebroker");
row[3] = checkNullAndPrint(tmpStr);
bcp_remote.add(row);
}
}
Globals.stdOutPrintln("Transactions that are owned by this broker");
bcp.println();
Globals.stdOutPrintln(" Transactions that involve remote brokers");
bcp_local.setIndent(3);
bcp_local.println();
Globals.stdOutPrintln("Transactions that are owned by a remote broker");
bcp_remote.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_TXN_SUC));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_TXN_NONE));
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_TXN_FAIL));
return (1);
}
} else if (CMDARG_CONNECTION.equals(commandArg)) {
String svcName = brokerCmdProps.getService();
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_CXN_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
if (svcName == null) {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_CXN));
printBrokerInfo(broker);
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_CXN_FOR_SVC));
printServiceInfo(svcName);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
}
try {
connectToBroker(broker);
broker.sendGetConnectionsMessage(svcName, null);
Vector cxnList = broker.receiveGetConnectionsReplyMessage();
if (cxnList != null && !cxnList.isEmpty()) {
BrokerCmdPrinter bcp = new BrokerCmdPrinter(6, 2, "-");
String[] row = new String[6];
Long tmpLong;
Integer tmpInt;
String tmpStr;
int i;
i = 0;
row[i++] = ar.getString(ar.I_JMQCMD_CXN_CXN_ID);
row[i++] = ar.getString(ar.I_JMQCMD_CXN_USER);
row[i++] = ar.getString(ar.I_JMQCMD_CXN_SERVICE);
row[i++] = ar.getString(ar.I_JMQCMD_CXN_NUM_PRODUCER);
row[i++] = ar.getString(ar.I_JMQCMD_CXN_NUM_CONSUMER);
row[i++] = ar.getString(ar.I_JMQCMD_CXN_HOST);
/*
* row[i++] = ar.getString(ar.I_JMQCMD_CXN_CLIENT_ID); row[i++] = ar.getString(ar.I_JMQCMD_CXN_PORT); row[i++] =
* ar.getString(ar.I_JMQCMD_CXN_CLIENT_PLATFORM);
*/
bcp.addTitle(row);
Enumeration thisEnum = cxnList.elements();
while (thisEnum.hasMoreElements()) {
Hashtable cxnInfo = (Hashtable) thisEnum.nextElement();
i = 0;
tmpLong = (Long) cxnInfo.get(PROP_NAME_CXN_CXN_ID);
row[i++] = checkNullAndPrint(tmpLong);
tmpStr = (String) cxnInfo.get(PROP_NAME_CXN_USER);
row[i++] = checkNullAndPrint(tmpStr);
tmpStr = (String) cxnInfo.get(PROP_NAME_CXN_SERVICE);
row[i++] = checkNullAndPrint(tmpStr);
tmpInt = (Integer) cxnInfo.get(PROP_NAME_CXN_NUM_PRODUCER);
row[i++] = checkNullAndPrint(tmpInt);
tmpInt = (Integer) cxnInfo.get(PROP_NAME_CXN_NUM_CONSUMER);
row[i++] = checkNullAndPrint(tmpInt);
tmpStr = (String) cxnInfo.get(PROP_NAME_CXN_HOST);
row[i++] = checkNullAndPrint(tmpStr);
/*
* tmpStr = (String)cxnInfo.get(PROP_NAME_CXN_CLIENT_ID); row[i++] = checkNullAndPrint(tmpStr);
*
* tmpInt = (Integer)cxnInfo.get(PROP_NAME_CXN_PORT); row[i++] = checkNullAndPrint(tmpInt);
*
* tmpStr = (String)cxnInfo.get(PROP_NAME_CXN_CLIENT_PLATFORM); row[i++] = checkNullAndPrint(tmpStr);
*/
bcp.add(row);
}
bcp.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_CXN_SUC));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_CXN_NONE));
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_CXN_FAIL));
return (1);
}
} else if (CMDARG_BROKER.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_BKR_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_BKR));
printBrokerInfo(broker);
try {
connectToBroker(broker);
/*
* Get broker props to find out if broker is in HA cluster and broker cluster ID
*/
broker.sendGetBrokerPropsMessage();
Properties bkrProps = broker.receiveGetBrokerPropsReplyMessage();
BrokerCmdPrinter haBcp = new BrokerCmdPrinter(2, 3, null);
String[] haInfoRow = new String[2];
/*
* Check if cluster is HA or not
*/
String value = bkrProps.getProperty(PROP_NAME_BKR_CLS_HA);
boolean isHA = Boolean.parseBoolean(value);
value = bkrProps.getProperty(PROP_NAME_BKR_STORE_MIGRATABLE);
boolean isStoreMigratable = Boolean.parseBoolean(value);
/*
* Display cluster ID only if HA cluster
*/
// if (isHA) {
haInfoRow[0] = ar.getString(ar.I_CLS_CLUSTER_ID);
value = bkrProps.getProperty(PROP_NAME_BKR_CLS_CLUSTER_ID, "");
haInfoRow[1] = value;
haBcp.add(haInfoRow);
// }
haInfoRow[0] = ar.getString(ar.I_CLS_IS_HA);
if (!isHA) {
haInfoRow[1] = Boolean.FALSE.toString();
} else {
haInfoRow[1] = Boolean.TRUE.toString();
}
haBcp.add(haInfoRow);
haBcp.println();
/*
* Get state of each broker in cluster
*/
broker.sendGetClusterMessage(true);
Vector bkrList = broker.receiveGetClusterReplyMessage();
if (bkrList != null && !bkrList.isEmpty()) {
BrokerCmdPrinter bcp;
String[] row;
Long tmpLong;
Integer tmpInt;
long idle;
int i;
if (isHA) {
bcp = new BrokerCmdPrinter(6, 3, "-");
row = new String[6];
bcp.setSortNeeded(false);
bcp.setTitleAlign(BrokerCmdPrinter.CENTER);
i = 0;
row[i++] = "";
row[i++] = "";
row[i++] = "";
row[i++] = "";
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TAKEOVER_ID1);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TIME_SINCE_TIMESTAMP1);
bcp.addTitle(row);
i = 0;
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_ID);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_ADDRESS);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_STATE);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_NUM_MSGS);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TAKEOVER_ID2);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_TIME_SINCE_TIMESTAMP2);
bcp.addTitle(row);
Enumeration thisEnum = bkrList.elements();
while (thisEnum.hasMoreElements()) {
Hashtable bkrClsInfo = (Hashtable) thisEnum.nextElement();
i = 0;
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.ID));
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.ADDRESS));
tmpInt = (Integer) bkrClsInfo.get(BrokerClusterInfo.STATE);
if (tmpInt != null) {
row[i++] = BrokerState.toString(tmpInt.intValue());
} else {
row[i++] = "";
}
tmpLong = (Long) bkrClsInfo.get(BrokerClusterInfo.NUM_MSGS);
row[i++] = checkNullAndPrint(tmpLong);
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.TAKEOVER_BROKER_ID));
tmpLong = (Long) bkrClsInfo.get(BrokerClusterInfo.STATUS_TIMESTAMP);
if (tmpLong != null) {
idle = System.currentTimeMillis() - tmpLong.longValue();
row[i++] = CommonCmdRunnerUtil.getTimeString(idle);
} else {
row[i++] = "";
}
bcp.add(row);
}
} else if (isStoreMigratable) {
bcp = new BrokerCmdPrinter(3, 3, "-");
row = new String[3];
bcp.setSortNeeded(false);
bcp.setTitleAlign(BrokerCmdPrinter.CENTER);
i = 0;
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_ID);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_ADDRESS);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_STATE);
bcp.addTitle(row);
Enumeration thisEnum = bkrList.elements();
while (thisEnum.hasMoreElements()) {
Hashtable bkrClsInfo = (Hashtable) thisEnum.nextElement();
i = 0;
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.ID));
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.ADDRESS));
tmpInt = (Integer) bkrClsInfo.get(BrokerClusterInfo.STATE);
if (tmpInt != null) {
row[i++] = BrokerState.toString(tmpInt.intValue());
} else {
row[i++] = "";
}
bcp.add(row);
}
} else {
bcp = new BrokerCmdPrinter(2, 3, "-");
row = new String[2];
bcp.setSortNeeded(false);
bcp.setTitleAlign(BrokerCmdPrinter.CENTER);
i = 0;
row[i++] = ar.getString(ar.I_JMQCMD_CLS_ADDRESS);
row[i++] = ar.getString(ar.I_JMQCMD_CLS_BROKER_STATE);
bcp.addTitle(row);
Enumeration thisEnum = bkrList.elements();
while (thisEnum.hasMoreElements()) {
Hashtable bkrClsInfo = (Hashtable) thisEnum.nextElement();
i = 0;
row[i++] = checkNullAndPrint(bkrClsInfo.get(BrokerClusterInfo.ADDRESS));
tmpInt = (Integer) bkrClsInfo.get(BrokerClusterInfo.STATE);
if (tmpInt != null) {
row[i++] = BrokerState.toString(tmpInt.intValue());
} else {
row[i++] = "";
}
bcp.add(row);
}
}
bcp.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_BKR_SUC));
} else {
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_BKR_NONE));
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_BKR_FAIL));
return (1);
}
} else if (CMDARG_JMX_CONNECTOR.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_JMX_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_JMX));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetJMXConnectorsMessage(null);
Vector jmxList = broker.receiveGetJMXConnectorsReplyMessage();
if (jmxList != null) {
BrokerCmdPrinter bcp = new BrokerCmdPrinter(3, 4, null);
String[] row = new String[3];
row[0] = ar.getString(ar.I_JMQCMD_JMX_NAME);
row[1] = ar.getString(ar.I_JMQCMD_JMX_ACTIVE);
row[2] = ar.getString(ar.I_JMQCMD_JMX_URL);
bcp.addTitle(row);
Enumeration thisEnum = jmxList.elements();
while (thisEnum.hasMoreElements()) {
Hashtable jmxInfo = (Hashtable) thisEnum.nextElement();
int i = 0;
row[i++] = checkNullAndPrint(jmxInfo.get(PROP_NAME_JMX_NAME));
row[i++] = checkNullAndPrint(jmxInfo.get(PROP_NAME_JMX_ACTIVE));
row[i++] = checkNullAndPrint(jmxInfo.get(PROP_NAME_JMX_URL));
bcp.add(row);
}
bcp.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_JMX_SUC));
} else {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_JMX_NONE));
Globals.stdOutPrintln("");
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_LIST_JMX_SUC));
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_JMX_FAIL));
return (1);
}
} else if (CMDARG_MSG.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln("Listing messages failed.");
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String destName = brokerCmdProps.getTargetName();
destTypeMask = getDestTypeMask(brokerCmdProps);
Long maxNumMsgsRetrieved = brokerCmdProps.getMaxNumMsgsRetrieved(), startMsgIndex = brokerCmdProps.getStartMsgIndex();
Globals.stdOutPrintln("Listing messages for the destination");
printDestinationInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetMessagesMessage(destName, destTypeMask, false, null, startMsgIndex, maxNumMsgsRetrieved);
Vector msgList = broker.receiveGetMessagesReplyMessage();
if (msgList != null && !msgList.isEmpty()) {
BrokerCmdPrinter bcp = new BrokerCmdPrinter(4, 3, "-");
String[] row = new String[4];
bcp.setSortNeeded(false);
int i = 0;
row[i++] = "Message #";
row[i++] = "Message IDs";
row[i++] = "Priority";
row[i++] = "Body Type";
bcp.addTitle(row);
long start = 0;
if (startMsgIndex != null) {
start = startMsgIndex.longValue();
}
Enumeration thisEnum = msgList.elements();
while (thisEnum.hasMoreElements()) {
HashMap oneMsg = (HashMap) thisEnum.nextElement();
i = 0;
/*
* String oneID = (String)thisEnum.nextElement();
*/
row[i++] = Long.toString(start++);
row[i++] = checkNullAndPrint(oneMsg.get("MessageID"));
row[i++] = checkNullAndPrint(oneMsg.get("Priority"));
row[i++] = checkNullAndPrintMsgBodyType((Integer) oneMsg.get("MessageBodyType"), false);
bcp.add(row);
}
bcp.println();
Globals.stdOutPrintln("Successfully listed messages.");
} else {
Globals.stdErrPrintln("There are no messages.");
Globals.stdOutPrintln("");
Globals.stdOutPrintln("Successfully listed messages.");
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln("Listing messages failed.");
return (1);
}
}
broker.close();
return (0);
}
Aggregations