KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Nicolas Modrzyk.
20  * Contributor(s): ______________________.
21  */

22
23 package org.continuent.sequoia.console.text.commands.dbadmin;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
29 import org.continuent.sequoia.common.jmx.mbeans.RecoveryLogControlMBean;
30 import org.continuent.sequoia.console.text.formatter.TableFormatter;
31 import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
32
33 /**
34  * This class defines a ViewCheckpointNames
35  *
36  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
37  * @version 1.0
38  */

39 public class ViewCheckpointNames extends AbstractAdminCommand
40 {
41
42   /**
43    * Creates a new <code>ViewCheckpointNames</code> object
44    *
45    * @param module module that owns this commands
46    */

47   public ViewCheckpointNames(VirtualDatabaseAdmin module)
48   {
49     super(module);
50   }
51
52   /**
53    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
54    */

55   public void parse(String JavaDoc commandText) throws Exception JavaDoc
56   {
57     RecoveryLogControlMBean recoveryLog = jmxClient.getRecoveryLog(dbName,
58         user,
59         password);
60     Map JavaDoc checkpoints = recoveryLog.getCheckpoints();
61     if (checkpoints.size() == 0)
62     {
63       console.printInfo(ConsoleTranslate.get("ViewCheckpointNames.nocheckpoints")); //$NON-NLS-1$
64
return;
65     }
66     // iterate over checkpoints
67
String JavaDoc[][] cp = getCheckpointsAsStrings(checkpoints);
68     String JavaDoc[] headers = new String JavaDoc[]{"id", "name"}; //$NON-NLS-1$//$NON-NLS-2$
69
String JavaDoc formattedCheckpoints = TableFormatter.format(headers, cp, true);
70     console.println(formattedCheckpoints);
71
72   }
73
74   private String JavaDoc[][] getCheckpointsAsStrings(Map JavaDoc checkpoints)
75   {
76     String JavaDoc[][] cp = new String JavaDoc[checkpoints.entrySet().size()][2];
77     Iterator JavaDoc iter = checkpoints.entrySet().iterator();
78     int i = 0;
79     while (iter.hasNext())
80     {
81       // we display first the log ID and then the checkpoint names
82
Map.Entry JavaDoc checkpoint = (Map.Entry JavaDoc) iter.next();
83       cp[i][1] = (String JavaDoc) checkpoint.getKey();
84       cp[i][0] = (String JavaDoc) checkpoint.getValue();
85       i++;
86     }
87     return cp;
88   }
89
90   /**
91    * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
92    */

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

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