KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > text > module > MonitorConsole


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): Mathieu Peltier.
23  */

24
25 package org.objectweb.cjdbc.console.text.module;
26
27 import java.util.Iterator JavaDoc;
28
29 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
30 import org.objectweb.cjdbc.console.text.Console;
31 import org.objectweb.cjdbc.console.text.commands.monitor.AbstractMonitorCommand;
32 import org.objectweb.cjdbc.console.text.commands.monitor.ChangeTarget;
33 import org.objectweb.cjdbc.console.text.commands.monitor.ShowBackends;
34 import org.objectweb.cjdbc.console.text.commands.monitor.ShowCache;
35 import org.objectweb.cjdbc.console.text.commands.monitor.ShowCacheStats;
36 import org.objectweb.cjdbc.console.text.commands.monitor.ShowController;
37 import org.objectweb.cjdbc.console.text.commands.monitor.ShowDatabases;
38 import org.objectweb.cjdbc.console.text.commands.monitor.ShowRecoveryLog;
39 import org.objectweb.cjdbc.console.text.commands.monitor.ShowScheduler;
40 import org.objectweb.cjdbc.console.text.commands.monitor.ShowStats;
41
42 /**
43  * Monitoring console to retrieve information from the controller.
44  *
45  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
46  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
47  */

48 public class MonitorConsole extends AbstractConsoleModule
49 {
50
51   private String JavaDoc currentTarget;
52
53   /**
54    * Returns the currentTarget value.
55    *
56    * @return Returns the currentTarget.
57    */

58   public String JavaDoc getCurrentTarget()
59   {
60     return currentTarget;
61   }
62
63   /**
64    * Sets the currentTarget value.
65    *
66    * @param currentTarget The currentTarget to set.
67    */

68   public void setCurrentTarget(String JavaDoc currentTarget)
69   {
70     this.currentTarget = currentTarget;
71     Object JavaDoc o;
72     Iterator JavaDoc it = commands.iterator();
73     while (it.hasNext())
74     {
75       o = it.next();
76       if (o instanceof AbstractMonitorCommand)
77       {
78         ((AbstractMonitorCommand) o).setCurrentTarget(currentTarget);
79       }
80     }
81   }
82
83   /**
84    * Creates a new <code>VirtualDatabaseAdmin</code> instance.
85    *
86    * @param console console console
87    */

88   public MonitorConsole(Console console)
89   {
90     super(console);
91   }
92
93   /**
94    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#getDescriptionString()
95    */

96   public String JavaDoc getDescriptionString()
97   {
98     return "Monitoring";
99   }
100
101   /**
102    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#getPromptString()
103    */

104   public String JavaDoc getPromptString()
105   {
106     return "Monitoring:" + currentTarget;
107   }
108
109   /**
110    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#loadCommands()
111    */

112   protected void loadCommands()
113   {
114     commands.add(new ChangeTarget(this));
115     commands.add(new ShowBackends(this));
116     commands.add(new ShowCache(this));
117     commands.add(new ShowCacheStats(this));
118     commands.add(new ShowController(this));
119     commands.add(new ShowDatabases(this));
120     commands.add(new ShowScheduler(this));
121     commands.add(new ShowStats(this));
122     commands.add(new ShowRecoveryLog(this));
123   }
124
125   /**
126    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#login(java.lang.String[])
127    */

128   public void login(String JavaDoc[] params)
129   {
130     quit = false;
131     
132     String JavaDoc command = (params.length > 0 && params[0] != null) ? params[0] : "";
133     if (command.equals(""))
134     {
135       console.printError(ConsoleTranslate.get("module.database.invalid", ""));
136       quit = true;
137     }
138     else
139     {
140       try
141       {
142         new ChangeTarget(this).execute(params[0]);
143         console.getConsoleReader().removeCompletor(
144             console.getControllerModule().getCompletor());
145         console.getConsoleReader().addCompletor(this.getCompletor());
146       }
147       catch (Exception JavaDoc e)
148       {
149         console.printError(e.getMessage(), e);
150         quit = true;
151       }
152     }
153   }
154 }
Popular Tags