use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class UpdateServiceHandler 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);
}
ServiceInfo info = (ServiceInfo) getBodyObject(cmd_msg);
int status = Status.OK;
String errMsg = null;
ServiceManager sm = Globals.getServiceManager();
Service svc = null;
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else {
if (info.name == null || ((svc = sm.getService(info.name)) == null)) {
status = Status.ERROR;
errMsg = rb.getString(rb.X_NO_SUCH_SERVICE, (info.name == null ? "<null>" : info.name));
}
}
// OK .. set the service information
if (status == Status.OK) {
if (!(svc instanceof IMQService)) {
status = Status.ERROR;
errMsg = "Internal Error: can updated non-standard Service";
} else {
// to repair this by fcs
try {
IMQService stsvc = (IMQService) svc;
int port = -1;
int min = -1;
int max = -1;
if (info.isModified(info.PORT)) {
port = info.port;
}
if (info.isModified(info.MIN_THREADS)) {
min = info.minThreads;
}
if (info.isModified(info.MAX_THREADS)) {
max = info.maxThreads;
}
if (port != -1 || min != -1 || max != -1) {
stsvc.updateService(port, min, max);
} else {
status = Status.ERROR;
errMsg = rb.getString(rb.X_NO_SERVICE_PROPS_SET, info.name);
}
} catch (Exception ex) {
logger.logStack(Logger.WARNING, rb.W_ERROR_UPDATING_SERVICE, svc.getName(), ex);
status = Status.ERROR;
errMsg = getMessageFromException(ex);
}
}
}
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.UPDATE_SERVICE_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class CmdRunner method isAdminService.
// Check to see if the service is an admin service.
private void isAdminService(BrokerAdmin broker, String svcName) throws BrokerAdminException {
broker.sendGetServicesMessage(svcName);
Vector svc = broker.receiveGetServicesReplyMessage();
if ((svc != null) && (svc.size() == 1)) {
Enumeration thisEnum = svc.elements();
ServiceInfo sInfo = (ServiceInfo) thisEnum.nextElement();
if (sInfo.type == ServiceType.ADMIN)
throw new BrokerAdminException(BrokerAdminException.INVALID_OPERATION);
}
}
use of com.sun.messaging.jmq.util.admin.ServiceInfo in project openmq by eclipse-ee4j.
the class CmdRunner method runQuery.
private int runQuery(BrokerCmdProperties brokerCmdProps) {
BrokerAdmin broker;
broker = init();
// Check for the target argument.
// Valid values are dst and svc.
String commandArg = brokerCmdProps.getCommandArg();
if (CMDARG_DESTINATION.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_DST_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String destName = brokerCmdProps.getTargetName();
int destTypeMask = getDestTypeMask(brokerCmdProps);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_DST));
printDestinationInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
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();
BrokerCmdPrinter bcp = new BrokerCmdPrinter(2, 4);
String[] row = new String[2];
bcp.setSortNeeded(false);
/*
* Basic info - name/type/state etc.
*/
row[0] = ar.getString(ar.I_JMQCMD_DST_NAME);
row[1] = dInfo.name;
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_TYPE);
row[1] = BrokerAdminUtil.getDestinationType(dInfo.type);
// If the destination is temporary, indicate so.
if (DestType.isTemporary(dInfo.type))
row[1] = row[1] + " (" + ar.getString(ar.I_TEMPORARY) + ")";
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_STATE);
// row[1] = DestState.toString(dInfo.destState);
row[1] = BrokerAdminUtil.getDestinationState(dInfo.destState);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_CREATED_ADMIN);
if (dInfo.autocreated) {
row[1] = Boolean.FALSE.toString();
} else {
row[1] = Boolean.TRUE.toString();
}
bcp.add(row);
row[0] = "";
row[1] = "";
bcp.add(row);
/*
* 'Current' numbers
*/
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_MSG);
row[1] = "";
bcp.add(row);
String indent = " ";
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_ACTUAL);
row[1] = Integer.toString(dInfo.nMessages - dInfo.nTxnMessages);
bcp.add(row);
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_REMOTE);
row[1] = Integer.toString(dInfo.nRemoteMessages);
bcp.add(row);
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_INDELAY);
row[1] = Integer.toString(dInfo.nInDelayMessages);
bcp.add(row);
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_HELD_IN_TXN);
row[1] = Integer.toString(dInfo.nTxnMessages);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_MSG_BYTES);
row[1] = "";
bcp.add(row);
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_ACTUAL);
row[1] = Long.toString(dInfo.nMessageBytes - dInfo.nTxnMessageBytes);
bcp.add(row);
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_REMOTE);
row[1] = Long.toString(dInfo.nRemoteMessageBytes);
bcp.add(row);
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_INDELAY);
row[1] = Long.toString(dInfo.nInDelayMessageBytes);
bcp.add(row);
row[0] = indent + ar.getString(ar.I_JMQCMD_DST_HELD_IN_TXN);
row[1] = Long.toString(dInfo.nTxnMessageBytes);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_PRODUCERS);
row[1] = Integer.toString(dInfo.nProducers);
bcp.add(row);
if (DestType.isQueue(destTypeMask)) {
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_ACTIVE_CONS);
row[1] = Integer.toString(dInfo.naConsumers);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_FAILOVER_CONS);
row[1] = Integer.toString(dInfo.nfConsumers);
bcp.add(row);
} else {
Hashtable h = dInfo.producerWildcards;
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_NUM_PRODUCERS_WILDCARD);
row[1] = Integer.toString(getWildcardCount(h));
bcp.add(row);
/*
* The code below will print something like:
*
* foo.bar.* (2) bar.* (1)
*/
Enumeration keys;
if (h != null) {
keys = h.keys();
while (keys.hasMoreElements()) {
String wildcard = (String) keys.nextElement();
Integer val = (Integer) h.get(wildcard);
row[0] = indent + wildcard + " (" + val + ")";
row[1] = "";
bcp.add(row);
}
}
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_CONS);
row[1] = Integer.toString(dInfo.nConsumers);
bcp.add(row);
h = dInfo.consumerWildcards;
row[0] = ar.getString(ar.I_JMQCMD_DST_CUR_NUM_CONSUMERS_WILDCARD);
row[1] = Integer.toString(getWildcardCount(h));
bcp.add(row);
if (h != null) {
keys = h.keys();
while (keys.hasMoreElements()) {
String wildcard = (String) keys.nextElement();
Integer val = (Integer) h.get(wildcard);
row[0] = indent + wildcard + " (" + val + ")";
row[1] = "";
bcp.add(row);
}
}
}
row[0] = "";
row[1] = "";
bcp.add(row);
/*
* 'Current' numbers
*/
row[0] = ar.getString(ar.I_JMQCMD_DST_MAX_MSG_ALLOW);
row[1] = checkAndPrintUnlimitedInt(dInfo.maxMessages, zeroNegOneInt);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_MAX_MSG_BYTES_ALLOW);
row[1] = checkAndPrintUnlimitedLong(dInfo.maxMessageBytes, zeroNegOneLong);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_MAX_BYTES_PER_MSG_ALLOW);
row[1] = String.valueOf(dInfo.maxMessageSize);
row[1] = checkAndPrintUnlimitedLong(dInfo.maxMessageSize, zeroNegOneLong);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_MAX_PRODUCERS);
row[1] = checkAndPrintUnlimitedInt(dInfo.maxProducers, -1);
bcp.add(row);
if (DestType.isQueue(destTypeMask)) {
row[0] = ar.getString(ar.I_JMQCMD_DST_MAX_ACTIVE_CONSUMER_COUNT);
row[1] = checkAndPrintUnlimitedInt(dInfo.maxActiveConsumers, -1);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_MAX_FAILOVER_CONSUMER_COUNT);
row[1] = checkAndPrintUnlimitedInt(dInfo.maxFailoverConsumers, -1);
bcp.add(row);
}
row[0] = "";
row[1] = "";
bcp.add(row);
/*
* Other misc props
*/
row[0] = ar.getString(ar.I_JMQCMD_DST_LIMIT_BEHAVIOUR);
row[1] = DestLimitBehavior.getString(dInfo.destLimitBehavior);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_CONS_FLOW_LIMIT);
row[1] = checkAndPrintUnlimitedInt(dInfo.maxPrefetch, -1);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_IS_LOCAL_DEST);
if (dInfo.isDestinationLocal()) {
row[1] = Boolean.TRUE.toString();
} else {
row[1] = Boolean.FALSE.toString();
}
bcp.add(row);
if (DestType.isQueue(destTypeMask)) {
row[0] = ar.getString(ar.I_JMQCMD_DST_LOCAL_DELIVERY_PREF);
if (dInfo.destCDP == ClusterDeliveryPolicy.LOCAL_PREFERRED) {
row[1] = Boolean.TRUE.toString();
} else {
row[1] = Boolean.FALSE.toString();
}
bcp.add(row);
}
row[0] = ar.getString(ar.I_JMQCMD_DST_USE_DMQ);
if (dInfo.useDMQ()) {
row[1] = Boolean.TRUE.toString();
} else {
row[1] = Boolean.FALSE.toString();
}
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_VALIDATE_XML_SCHEMA_ENABLED);
if (dInfo.validateXMLSchemaEnabled()) {
row[1] = Boolean.TRUE.toString();
} else {
row[1] = Boolean.FALSE.toString();
}
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_XML_SCHEMA_URI_LIST);
row[1] = dInfo.XMLSchemaUriList;
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_DST_RELOAD_XML_SCHEMA_ON_FAILURE);
if (dInfo.reloadXMLSchemaOnFailure()) {
row[1] = Boolean.TRUE.toString();
} else {
row[1] = Boolean.FALSE.toString();
}
bcp.add(row);
bcp.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_DST_SUC));
} else {
// Should not get here, since if something went wrong we should get
// a BrokerAdminException
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_INCORRECT_DATA_RET));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_DST_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_DST_FAIL));
return (1);
}
} else if (CMDARG_SERVICE.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_SVC_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String svcName = brokerCmdProps.getTargetName();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_SVC));
printServiceInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
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();
BrokerCmdPrinter bcp = new BrokerCmdPrinter(2, 4);
String[] row = new String[2];
bcp.setSortNeeded(false);
/*
* Basic info - name/port/state
*/
row[0] = ar.getString(ar.I_JMQCMD_SVC_NAME);
row[1] = sInfo.name;
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_SVC_STATE);
// row[1] = ServiceState.getString(sInfo.state);
row[1] = BrokerAdminUtil.getServiceState(sInfo.state);
bcp.add(row);
// It is NOT applicable if it is set to -1
if (sInfo.port != -1) {
row[0] = ar.getString(ar.I_JMQCMD_SVC_PORT);
// dynamically generated or statically declared
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) + ")";
}
bcp.add(row);
}
row[0] = "";
row[1] = "";
bcp.add(row);
/*
* 'Curent' numbers
*/
row[0] = ar.getString(ar.I_JMQCMD_SVC_CUR_THREADS);
row[1] = Integer.toString(sInfo.currentThreads);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_SVC_NUM_CXN);
row[1] = Integer.toString(sInfo.nConnections);
bcp.add(row);
row[0] = "";
row[1] = "";
bcp.add(row);
/*
* Min/Max numbers
*/
row[0] = ar.getString(ar.I_JMQCMD_SVC_MIN_THREADS);
row[1] = Integer.toString(sInfo.minThreads);
bcp.add(row);
row[0] = ar.getString(ar.I_JMQCMD_SVC_MAX_THREADS);
row[1] = Integer.toString(sInfo.maxThreads);
bcp.add(row);
bcp.println();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_SVC_SUC));
} else {
// Should not get here, since if something went wrong we should get
// a BrokerAdminException
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_INCORRECT_DATA_RET));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_SVC_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_SVC_FAIL));
return (1);
}
} else if (CMDARG_BROKER.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_BKR_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_BKR));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetBrokerPropsMessage();
Properties bkrProps = broker.receiveGetBrokerPropsReplyMessage();
if (bkrProps == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_BKR_FAIL));
return (1);
}
if (brokerCmdProps.adminDebugModeSet()) {
printAllBrokerAttrs(bkrProps);
} else {
printDisplayableBrokerAttrs(bkrProps);
}
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_BKR_SUC));
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_BKR_FAIL));
return (1);
}
} else if (CMDARG_TRANSACTION.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_TXN_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String tidStr = brokerCmdProps.getTargetName();
Long tid = null;
try {
tid = Long.valueOf(tidStr);
} catch (NumberFormatException nfe) {
Globals.stdErrPrintln(ar.getString(ar.E_INVALID_TXN_ID, tidStr));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_TXN_FAIL));
return (1);
}
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_TXN));
printTransactionInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetTxnsMessage(tid, brokerCmdProps.showPartitionModeSet());
Vector txns = broker.receiveGetTxnsReplyMessage();
if ((txns != null) && (txns.size() == 1)) {
Enumeration thisEnum = txns.elements();
Hashtable txnInfo = (Hashtable) thisEnum.nextElement();
if (brokerCmdProps.debugModeSet()) {
printAllTxnAttrs(txnInfo);
} else {
printDisplayableTxnAttrs(txnInfo);
}
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_TXN_SUC));
} else {
// Should not get here, since if something went wrong we should get
// a BrokerAdminException
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_INCORRECT_DATA_RET));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_TXN_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_TXN_FAIL));
return (1);
}
} else if (CMDARG_CONNECTION.equals(commandArg)) {
if (broker == null) {
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_CXN_FAIL));
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String cxnIdStr = brokerCmdProps.getTargetName();
Long cxnId = null;
try {
cxnId = Long.valueOf(cxnIdStr);
} catch (NumberFormatException nfe) {
Globals.stdErrPrintln(ar.getString(ar.E_INVALID_CXN_ID, cxnIdStr));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_CXN_FAIL));
return (1);
}
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_CXN));
printConnectionInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetConnectionsMessage(null, cxnId);
Vector cxnList = broker.receiveGetConnectionsReplyMessage();
if ((cxnList != null) && (cxnList.size() == 1)) {
Enumeration thisEnum = cxnList.elements();
Hashtable cxnInfo = (Hashtable) thisEnum.nextElement();
if (brokerCmdProps.debugModeSet()) {
printAllCxnAttrs(cxnInfo);
} else {
printDisplayableCxnAttrs(cxnInfo);
}
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_CXN_SUC));
} else {
// Should not get here, since if something went wrong we should get
// a BrokerAdminException
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_INCORRECT_DATA_RET));
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_CXN_FAIL));
return (1);
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_CXN_FAIL));
return (1);
}
} else if (CMDARG_MSG.equals(commandArg)) {
if (broker == null) {
/*
* Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_MSG_FAIL));
*/
Globals.stdErrPrintln("Querying message failed.");
return (1);
}
boolean force = brokerCmdProps.forceModeSet();
if (!force)
broker = promptForAuthentication(broker);
String destName = brokerCmdProps.getTargetName();
int destTypeMask = getDestTypeMask(brokerCmdProps);
String msgID = brokerCmdProps.getMsgID();
/*
* Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_MSG));
*/
Globals.stdOutPrintln("Querying message:");
printMessageInfo();
Globals.stdOutPrintln("In the destination");
printDestinationInfo();
Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_SPECIFY_BKR));
printBrokerInfo(broker);
try {
connectToBroker(broker);
broker.sendGetMessagesMessage(destName, destTypeMask, true, msgID, null, null);
Vector msgList = broker.receiveGetMessagesReplyMessage();
if ((msgList != null) && (msgList.size() == 1)) {
HashMap oneMsg = (HashMap) msgList.get(0);
printDisplayableMsgAttrs(oneMsg);
/*
* Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_MSG_SUC));
*/
Globals.stdOutPrintln("Successfully queried message.");
} else {
/*
* Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_LIST_MSG_NONE));
*/
Globals.stdErrPrintln("There are no messages.");
Globals.stdOutPrintln("");
/*
* Globals.stdOutPrintln(ar.getString(ar.I_JMQCMD_QUERY_MSG_SUC));
*/
Globals.stdOutPrintln("Successfully queried message.");
}
} catch (BrokerAdminException bae) {
handleBrokerAdminException(bae);
/*
* Globals.stdErrPrintln(ar.getString(ar.I_JMQCMD_QUERY_MSG_FAIL));
*/
Globals.stdErrPrintln("Querying message failed.");
return (1);
}
}
if (broker.isConnected()) {
broker.close();
}
return (0);
}
use of com.sun.messaging.jmq.util.admin.ServiceInfo 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.ServiceInfo 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