Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ShowBackendState.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2005 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.text.commands.dbadmin;
00026 
00027 import java.util.ArrayList;
00028 import java.util.StringTokenizer;
00029 
00030 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
00031 import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean;
00032 import org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin;
00033 
00034 /**
00035  * This class defines a ShowBackendState
00036  * 
00037  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00038  * @version 1.0
00039  */
00040 public class ShowBackendState extends AbstractAdminCommand
00041 {
00042 
00043   /**
00044    * Creates a new <code>ShowBackendState</code> object
00045    * 
00046    * @param module the calling module
00047    */
00048   public ShowBackendState(VirtualDatabaseAdmin module)
00049   {
00050     super(module);
00051   }
00052 
00053   /**
00054    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#parse(java.lang.String)
00055    */
00056   public void parse(String commandText) throws Exception
00057   {
00058     if (commandText == null || commandText.trim().equals(""))
00059     {
00060       console.printError(ConsoleTranslate
00061           .get("admin.command.showbackend.state.no.input"));
00062       return;
00063     }
00064     StringTokenizer st = new StringTokenizer(commandText);
00065 
00066     String backendName = st.nextToken();
00067 
00068     if (!jmxClient.getVirtualDatabaseProxy(dbName, user, password)
00069         .getAllBackendNames().contains(backendName))
00070       console.printError(ConsoleTranslate.get(
00071           "admin.command.showbackend.state.invalid.backend", backendName));
00072 
00073     int count = 0;
00074     if (st.hasMoreTokens())
00075     {
00076       try
00077       {
00078         count = Integer.parseInt(st.nextToken());
00079       }
00080       catch (NumberFormatException e)
00081       {
00082       }
00083     }
00084     boolean fromFirst = true;
00085     if (st.hasMoreTokens())
00086       fromFirst = Boolean.valueOf(st.nextToken()).booleanValue();
00087     boolean clone = false;
00088     if (st.hasMoreTokens())
00089       clone = Boolean.valueOf(st.nextToken()).booleanValue();
00090 
00091     console.println(ConsoleTranslate.get(
00092         "admin.command.showbackend.state.echo", new Object[]{backendName,
00093             String.valueOf(count), String.valueOf(fromFirst),
00094             String.valueOf(clone)}));
00095     DatabaseBackendMBean db = jmxClient.getDatabaseBackendProxy(dbName,
00096         backendName, user, password);
00097 
00098     ArrayList list = db.getActiveTransactions();
00099     console.printInfo(ConsoleTranslate
00100         .get("admin.command.showbackend.state.state"));
00101     console.println(db.getState());
00102     console.printInfo(ConsoleTranslate
00103         .get("admin.command.showbackend.state.active.transactions"));
00104     for (int i = 0; i < list.size(); i++)
00105     {
00106       if (i != 0)
00107         console.print(",");
00108       console.print(list.get(i).toString());
00109     }
00110     console.println();
00111     console.printInfo(ConsoleTranslate
00112         .get("admin.command.showbackend.state.pending.requests"));
00113     try
00114     {
00115       list = db.getPendingRequestsDescription(count, fromFirst, clone);
00116       for (int i = 0; i < list.size(); i++)
00117         console.println((String) list.get(i));
00118     }
00119     catch (Exception e)
00120     {
00121       e.printStackTrace();
00122     }
00123   }
00124 
00125   /**
00126    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
00127    */
00128   public String getCommandName()
00129   {
00130     return "showbackend";
00131   }
00132 
00133   /**
00134    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
00135    */
00136   public String getCommandDescription()
00137   {
00138     return ConsoleTranslate.get("admin.command.showbackend.state");
00139   }
00140 
00141   /**
00142    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
00143    */
00144   public String getCommandParameters()
00145   {
00146     return "<backendName> [<count>] [<fromFirst>] [<clone>]";
00147   }
00148 }

Generated on Mon Apr 11 22:01:34 2005 for C-JDBC by  doxygen 1.3.9.1