001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Nicolas Modrzyk
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.console.text.commands.controller;
022:
023: import java.util.StringTokenizer;
024:
025: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
026: import org.continuent.sequoia.console.jmx.RmiJmxClient;
027: import org.continuent.sequoia.console.text.ConsoleException;
028: import org.continuent.sequoia.console.text.ConsoleLauncher;
029: import org.continuent.sequoia.console.text.commands.ConsoleCommand;
030: import org.continuent.sequoia.console.text.module.AbstractConsoleModule;
031:
032: /**
033: * This class defines a Bind
034: *
035: * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
036: * @version 1.0
037: */
038: public class Bind extends ConsoleCommand {
039:
040: /**
041: * Creates a new <code>Bind.java</code> object
042: *
043: * @param module the command is attached to
044: */
045: public Bind(AbstractConsoleModule module) {
046: super (module);
047: }
048:
049: /**
050: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
051: */
052: public void parse(String commandText) throws Exception {
053: StringTokenizer st = new StringTokenizer(commandText.trim());
054:
055: String host = null;
056: String port = null;
057:
058: if (st == null || st.countTokens() != 2) {
059: console.printError(getUsage());
060: return;
061: }
062:
063: try {
064: host = st.nextToken();
065: port = st.nextToken();
066:
067: if (jmxClient == null) {
068: jmxClient = new RmiJmxClient("" + port, host, null);
069: console.setJmxClient(jmxClient);
070: }
071:
072: jmxClient.connect(port, host, jmxClient.getCredentials());
073: console.printInfo(ConsoleTranslate.get(
074: "controller.command.bind.success", //$NON-NLS-1$
075: new String[] { ConsoleLauncher.PRODUCT_NAME, host,
076: port }));
077: } catch (Exception e) {
078: throw new ConsoleException(ConsoleTranslate.get(
079: "controller.command.bind.failed", //$NON-NLS-1$
080: new String[] { ConsoleLauncher.PRODUCT_NAME, host,
081: port }), e);
082: }
083: }
084:
085: /**
086: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
087: */
088: public String getCommandName() {
089: return "connect controller"; //$NON-NLS-1$
090: }
091:
092: /**
093: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
094: */
095: public String getCommandParameters() {
096: return ConsoleTranslate.get("controller.command.bind.params"); //$NON-NLS-1$
097: }
098:
099: /**
100: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
101: */
102: public String getCommandDescription() {
103: return ConsoleTranslate
104: .get(
105: "controller.command.bind.description", ConsoleLauncher.PRODUCT_NAME); //$NON-NLS-1$
106: }
107:
108: }
|