Search in sources :

Example 1 with ConsumerInfo

use of com.sun.messaging.jmq.util.admin.ConsumerInfo 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;
}
Also used : Set(java.util.Set) ConsumerInfo(com.sun.messaging.jmq.util.admin.ConsumerInfo) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) DurableInfo(com.sun.messaging.jmq.util.admin.DurableInfo) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Iterator(java.util.Iterator) List(java.util.List) ConnectionInfo(com.sun.messaging.jmq.util.admin.ConnectionInfo) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) Vector(java.util.Vector)

Example 2 with ConsumerInfo

use of com.sun.messaging.jmq.util.admin.ConsumerInfo 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);
}
Also used : BrokerAdminException(com.sun.messaging.jmq.admin.bkrutil.BrokerAdminException) BrokerAdmin(com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin) Enumeration(java.util.Enumeration) ConsumerInfo(com.sun.messaging.jmq.util.admin.ConsumerInfo) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) SizeString(com.sun.messaging.jmq.util.SizeString) Properties(java.util.Properties) ServiceInfo(com.sun.messaging.jmq.util.admin.ServiceInfo) DurableInfo(com.sun.messaging.jmq.util.admin.DurableInfo) Vector(java.util.Vector) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConsumerInfo (com.sun.messaging.jmq.util.admin.ConsumerInfo)2 DurableInfo (com.sun.messaging.jmq.util.admin.DurableInfo)2 Vector (java.util.Vector)2 BrokerAdmin (com.sun.messaging.jmq.admin.bkrutil.BrokerAdmin)1 BrokerAdminException (com.sun.messaging.jmq.admin.bkrutil.BrokerAdminException)1 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)1 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)1 Subscription (com.sun.messaging.jmq.jmsserver.core.Subscription)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 SizeString (com.sun.messaging.jmq.util.SizeString)1 ConnectionInfo (com.sun.messaging.jmq.util.admin.ConnectionInfo)1 ServiceInfo (com.sun.messaging.jmq.util.admin.ServiceInfo)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1