01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2006 Continuent.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: * Initial developer(s): Gilles Rayrat.
19: * Contributor(s): ______________________.
20: */package org.continuent.sequoia.console.text.commands.dbadmin;
21:
22: import java.util.StringTokenizer;
23:
24: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
25: import org.continuent.sequoia.common.jmx.mbeans.ParsingCacheMBean;
26: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
27:
28: /**
29: * This class defines the command used to dump the parsing cache
30: */
31: public class DumpParsingCache extends AbstractAdminCommand {
32: protected static final String LINE_SEPARATOR = System
33: .getProperty("line.separator");
34:
35: /**
36: * Creates a new <code>DumpBackendSchema</code> object
37: *
38: * @param module the commands is attached to
39: */
40: public DumpParsingCache(VirtualDatabaseAdmin module) {
41: super (module);
42: }
43:
44: /**
45: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
46: */
47: public void parse(String commandText) throws Exception {
48: StringTokenizer st = new StringTokenizer(commandText.trim());
49: if (st.countTokens() != 0) {
50: console.printError(getUsage());
51: return;
52: }
53:
54: ParsingCacheMBean pcMbean = jmxClient.getParsingCache(dbName,
55: user, password);
56: console.println(pcMbean.dumpCacheConfig());
57: console.println(pcMbean.dumpCurrentlyParsedEntries());
58:
59: // make dump start from first entry
60: pcMbean.resetDump();
61: String entries = pcMbean.dumpNextCacheEntries();
62: while (entries != null) {
63: console.println(entries);
64: entries = pcMbean.dumpNextCacheEntries();
65: if (entries != null) {
66: String s = console
67: .readLine(ConsoleTranslate
68: .get("DumpParsingCache.cacheNextEntriesOrQuit"));
69: if ("q".equalsIgnoreCase(s))
70: entries = null; // frees mem and stop display
71: }
72: }
73: }
74:
75: /**
76: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
77: */
78: public String getCommandName() {
79:
80: return "dump parsing cache"; //$NON-NLS-1$
81: }
82:
83: /**
84: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
85: */
86: public String getCommandParameters() {
87: return ""; //$NON-NLS-1$
88: }
89:
90: /**
91: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
92: */
93: public String getCommandDescription() {
94: return ConsoleTranslate.get("DumpParsingCache.description"); //$NON-NLS-1$
95: }
96: }
|