KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > text > commands > controller > Shutdown


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): Mathieu Peltier, Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.console.text.commands.controller;
26
27 import java.io.IOException JavaDoc;
28
29 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
30 import org.objectweb.cjdbc.common.util.Constants;
31 import org.objectweb.cjdbc.console.text.ConsoleException;
32 import org.objectweb.cjdbc.console.text.commands.ConsoleCommand;
33 import org.objectweb.cjdbc.console.text.module.AbstractConsoleModule;
34
35 /**
36  * This class defines a Shutdown
37  *
38  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
39  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
40  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
41  * </a>
42  * @version 1.0
43  */

44 public class Shutdown extends ConsoleCommand
45 {
46
47   /**
48    * Creates a new <code>Shutdown.java</code> object
49    *
50    * @param module the command is attached to
51    */

52   public Shutdown(AbstractConsoleModule module)
53   {
54     super(module);
55   }
56
57   /**
58    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#parse(java.lang.String)
59    */

60   public void parse(String JavaDoc commandText) throws IOException JavaDoc, ConsoleException
61   {
62     try
63     {
64       if (commandText.indexOf(String.valueOf(Constants.SHUTDOWN_SAFE)) != -1)
65         jmxClient.getControllerProxy().shutdown(Constants.SHUTDOWN_SAFE);
66       else if (commandText.indexOf(String.valueOf(Constants.SHUTDOWN_WAIT)) != -1)
67         jmxClient.getControllerProxy().shutdown(Constants.SHUTDOWN_WAIT);
68       else if (commandText.indexOf(String.valueOf(Constants.SHUTDOWN_FORCE)) != -1)
69         jmxClient.getControllerProxy().shutdown(Constants.SHUTDOWN_FORCE);
70       else
71         // Defaults to safe mode
72
jmxClient.getControllerProxy().shutdown(Constants.SHUTDOWN_SAFE);
73
74       console.println("Shutdown was complete");
75     }
76     catch (Exception JavaDoc e)
77     {
78       if (jmxClient.isValidConnection())
79         console.printError("Could not shutdown the controller:"
80             + e.getMessage());
81       else
82         console.printInfo("Controller has shutdown");
83     }
84   }
85
86   /**
87    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandName()
88    */

89   public String JavaDoc getCommandName()
90   {
91     return "shutdown";
92   }
93
94   /**
95    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandParameters()
96    */

97   public String JavaDoc getCommandParameters()
98   {
99     return "[mode]";
100   }
101
102   /**
103    * @see org.objectweb.cjdbc.console.text.commands.ConsoleCommand#getCommandDescription()
104    */

105   public String JavaDoc getCommandDescription()
106   {
107     return ConsoleTranslate.get("controller.command.shutdown");
108   }
109 }
Popular Tags