KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > text > commands > dbadmin > ShowBackendState


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 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): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.text.commands.dbadmin;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29
30 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
31 import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean;
32 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin;
33
34 /**
35  * This class defines a ShowBackendState
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
38  * @version 1.0
39  */

40 public class ShowBackendState extends AbstractAdminCommand
41 {
42
43   /**
44    * Creates a new <code>ShowBackendState</code> object
45    *
46    * @param module the calling module
47    */

48   public ShowBackendState(VirtualDatabaseAdmin module)
49   {
50     super(module);
51   }
52
53   /**
54    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#parse(java.lang.String)
55    */

56   public void parse(String JavaDoc commandText) throws Exception JavaDoc
57   {
58     if (commandText == null || commandText.trim().equals(""))
59     {
60       console.printError(ConsoleTranslate
61           .get("admin.command.showbackend.state.no.input"));
62       return;
63     }
64     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(commandText);
65
66     String JavaDoc backendName = st.nextToken();
67
68     if (!jmxClient.getVirtualDatabaseProxy(dbName, user, password)
69         .getAllBackendNames().contains(backendName))
70     {
71       console.printError(ConsoleTranslate.get(
72           "admin.command.showbackend.state.invalid.backend", backendName));
73       return;
74     }
75
76     int count = 0;
77     if (st.hasMoreTokens())
78     {
79       try
80       {
81         count = Integer.parseInt(st.nextToken());
82       }
83       catch (NumberFormatException JavaDoc e)
84       {
85       }
86     }
87     boolean fromFirst = true;
88     if (st.hasMoreTokens())
89       fromFirst = Boolean.valueOf(st.nextToken()).booleanValue();
90     boolean clone = false;
91     if (st.hasMoreTokens())
92       clone = Boolean.valueOf(st.nextToken()).booleanValue();
93
94     //TODO: Use a BackendInfo object to transfer the backend state
95
console.println(ConsoleTranslate.get(
96         "admin.command.showbackend.state.echo", new Object JavaDoc[]{backendName,
97             String.valueOf(count), String.valueOf(fromFirst),
98             String.valueOf(clone)}));
99     DatabaseBackendMBean db = jmxClient.getDatabaseBackendProxy(dbName,
100         backendName, user, password);
101
102     ArrayList JavaDoc list = db.getActiveTransactions();
103     console.printInfo(ConsoleTranslate
104         .get("admin.command.showbackend.state.state"));
105     console.println(db.getState());
106     console.printInfo(ConsoleTranslate
107         .get("admin.command.showbackend.state.active.transactions"));
108     for (int i = 0; i < list.size(); i++)
109     {
110       if (i != 0)
111         console.print(",");
112       console.print(list.get(i).toString());
113     }
114     console.println();
115     console.printInfo(ConsoleTranslate
116         .get("admin.command.showbackend.state.pending.requests"));
117     try
118     {
119       list = db.getPendingRequestsDescription(count, fromFirst, clone);
120       for (int i = 0; i < list.size(); i++)
121         console.println((String JavaDoc) list.get(i));
122     }
123     catch (Exception JavaDoc e)
124     {
125       e.printStackTrace();
126     }
127   }
128
129   /**
130    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
131    */

132   public String JavaDoc getCommandName()
133   {
134     return "showbackend";
135   }
136
137   /**
138    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
139    */

140   public String JavaDoc getCommandDescription()
141   {
142     return ConsoleTranslate.get("admin.command.showbackend.state");
143   }
144
145   /**
146    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
147    */

148   public String JavaDoc getCommandParameters()
149   {
150     return "<backendName> [<count>] [<fromFirst>] [<clone>]";
151   }
152 }
Popular Tags