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): Damian Arregui.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.console.text.commands.dbadmin;
021:
022: import java.util.HashMap;
023: import java.util.Hashtable;
024: import java.util.Iterator;
025: import java.util.Map;
026: import java.util.Set;
027: import java.util.StringTokenizer;
028:
029: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
030: import org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean;
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 DumpConnections extends AbstractAdminCommand {
037:
038: /**
039: * Creates a new <code>DumpConnections</code> object
040: *
041: * @param module the commands is attached to
042: */
043: public DumpConnections(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: Map loginToConnId = new HashMap();
061: Hashtable connIdToLogin = ascMbean
062: .listOpenPersistentConnections();
063: Long connId;
064: String login;
065: for (Iterator iter = connIdToLogin.entrySet().iterator(); iter
066: .hasNext();) {
067: Map.Entry entry = (Map.Entry) iter.next();
068: connId = (Long) entry.getKey();
069: login = (String) entry.getValue();
070: if (!loginToConnId.containsKey(login)) {
071: loginToConnId.put(login, new StringBuffer("\n\t"
072: + login + ": "));
073: }
074: ((StringBuffer) loginToConnId.get(login)).append(connId
075: + " ");
076: }
077:
078: StringBuffer disp = new StringBuffer();
079: disp
080: .append(ConsoleTranslate
081: .get("DumpConnections.connections"));
082: for (Iterator iter = loginToConnId.values().iterator(); iter
083: .hasNext();) {
084: StringBuffer sb = (StringBuffer) iter.next();
085: disp.append(sb);
086: }
087:
088: console.println(disp.toString());
089: }
090:
091: /**
092: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
093: */
094: public String getCommandName() {
095: return "dump connections"; //$NON-NLS-1$
096: }
097:
098: /**
099: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
100: */
101: public String getCommandParameters() {
102: return ""; //$NON-NLS-1$
103: }
104:
105: /**
106: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
107: */
108: public String getCommandDescription() {
109: return ConsoleTranslate.get("DumpConnections.description"); //$NON-NLS-1$
110: }
111: }
|