001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2006 Continuent.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Gilles Rayrat.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.console.text.commands.dbadmin;
021:
022: import java.util.List;
023: import java.util.StringTokenizer;
024:
025: import javax.management.openmbean.TabularData;
026:
027: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
028: import org.continuent.sequoia.common.jmx.management.TransactionDataSupport;
029: import org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean;
030: import org.continuent.sequoia.console.text.formatter.TableFormatter;
031: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
032:
033: /**
034: * This class defines the command used to dump a given scheduler queues
035: */
036: public class DumpSchedulerQueues extends AbstractAdminCommand {
037:
038: /**
039: * Creates a new <code>DumpSchedulerQueues</code> object
040: *
041: * @param module the commands is attached to
042: */
043: public DumpSchedulerQueues(VirtualDatabaseAdmin module) {
044: super (module);
045: }
046:
047: /**
048: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
049: */
050: public void parse(String commandText) throws Exception {
051: StringTokenizer st = new StringTokenizer(commandText.trim());
052: if (st.countTokens() != 0) {
053: console.printError(getUsage());
054: return;
055: }
056:
057: AbstractSchedulerControlMBean ascMbean = jmxClient
058: .getAbstractScheduler(dbName, user, password);
059:
060: // active transactions
061: TabularData transactions = ascMbean.getActiveTransactions();
062: List entries = JMXUtils.sortEntriesByKey(transactions, "tid");
063:
064: console.println(ConsoleTranslate.get(
065: "DumpSchedulerQueues.activeTransactions", entries
066: .size()));
067: if (entries.size() > 0) {
068: String[][] entriesStr = JMXUtils.from(entries,
069: TransactionDataSupport.NAMES);
070: console.println(TableFormatter.format(new String[] { "tid",
071: "time (in s)" }, entriesStr, true));
072: }
073: console.println();
074:
075: // pending read requests
076: long[] prids = ascMbean.listPendingReadRequestIds();
077: console.println(ConsoleTranslate.get(
078: "DumpSchedulerQueues.pendingReads", prids.length));
079: for (int i = 0; i < prids.length; i++) {
080: console.print(" " + prids[i]);
081: }
082: console.println();
083:
084: // pending write requests
085: long[] pwids = ascMbean.listPendingWriteRequestIds();
086: console.println(ConsoleTranslate.get(
087: "DumpSchedulerQueues.pendingWrites", pwids.length));
088: for (int i = 0; i < pwids.length; i++) {
089: console.print(" " + pwids[i]);
090: }
091: console.println();
092: }
093:
094: /**
095: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
096: */
097: public String getCommandName() {
098: return "dump scheduler queues"; //$NON-NLS-1$
099: }
100:
101: /**
102: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
103: */
104: public String getCommandParameters() {
105: return ""; //$NON-NLS-1$
106: }
107:
108: /**
109: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
110: */
111: public String getCommandDescription() {
112: return ConsoleTranslate.get("DumpSchedulerQueues.description"); //$NON-NLS-1$
113: }
114: }
|