KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > text > commands > dbadmin > DumpParsingCache


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
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  */

21
22 package org.continuent.sequoia.console.text.commands.dbadmin;
23
24 import java.util.StringTokenizer JavaDoc;
25
26 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
27 import org.continuent.sequoia.common.jmx.mbeans.ParsingCacheMBean;
28 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
29
30 /**
31  * This class defines the command used to dump the parsing cache
32  */

33 public class DumpParsingCache extends AbstractAdminCommand
34 {
35   protected static final String JavaDoc LINE_SEPARATOR = System
36                                                    .getProperty("line.separator");
37
38   /**
39    * Creates a new <code>DumpBackendSchema</code> object
40    *
41    * @param module the commands is attached to
42    */

43   public DumpParsingCache(VirtualDatabaseAdmin module)
44   {
45     super(module);
46   }
47
48   /**
49    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
50    */

51   public void parse(String JavaDoc commandText) throws Exception JavaDoc
52   {
53     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commandText.trim());
54     if (st.countTokens() != 0)
55     {
56       console.printError(getUsage());
57       return;
58     }
59
60     ParsingCacheMBean pcMbean = jmxClient.getParsingCache(dbName, user,
61         password);
62     console.println(pcMbean.dumpCacheConfig());
63     console.println(pcMbean.dumpCurrentlyParsedEntries());
64
65     // make dump start from first entry
66
pcMbean.resetDump();
67     String JavaDoc entries = pcMbean.dumpNextCacheEntries();
68     while (entries != null)
69     {
70       console.println(entries);
71       entries = pcMbean.dumpNextCacheEntries();
72       if (entries != null)
73       {
74         String JavaDoc s = console.readLine(ConsoleTranslate
75             .get("DumpParsingCache.cacheNextEntriesOrQuit"));
76         if ("q".equalsIgnoreCase(s))
77           entries = null; // frees mem and stop display
78
}
79     }
80   }
81
82   /**
83    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
84    */

85   public String JavaDoc getCommandName()
86   {
87
88     return "dump parsing cache"; //$NON-NLS-1$
89
}
90
91   /**
92    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
93    */

94   public String JavaDoc getCommandParameters()
95   {
96     return ""; //$NON-NLS-1$
97
}
98
99   /**
100    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
101    */

102   public String JavaDoc getCommandDescription()
103   {
104     return ConsoleTranslate.get("DumpParsingCache.description"); //$NON-NLS-1$
105
}
106 }
107
Popular Tags