Author: anovarini
Date: Sat Mar 10 23:56:20 2012
New Revision: 1299311
URL: http://svn.apache.org/viewvc?rev=1299311&view=rev
Log:
Started extracting the first commands
Added:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Command.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Connect.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy
(contents, props changed)
- copied, changed from r1299299,
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Help.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/io/
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/io/Terminal.groovy
- copied, changed from r1299299,
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Terminal.groovy
Removed:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Terminal.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Help.groovy
Modified:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/IODevice.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/client/Client.groovy
incubator/kitty/trunk/src/test/groovy/org/apache/kitty/test/TestGroovyShell.groovy
Modified: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy?rev=1299311&r1=1299310&r2=1299311&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy
(original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy Sat
Mar 10 23:56:20 2012
@@ -20,25 +20,10 @@ package org.apache.kitty
import org.apache.kitty.client.Client
import org.apache.kitty.utils.Constants
-import org.apache.kitty.utils.Help
+import org.apache.kitty.command.Help
+import org.apache.kitty.command.Connect
-
-/**
- * <pre>
- * <b>Description</b>
- * <p>
- * This is a command shell class that is used for a command line user
interface for the management console
- * </p>
- * </pre>
- *
- * @version $Id$
- *
- */
class CmdShell {
- static final String HOST = "localhost"
-
- static final String PORT = "1099"
-
Client client
IODevice ioDevice
@@ -72,15 +57,15 @@ class CmdShell {
if (input.length() == 0)
continue
- if (["exit", "quit"].contains(input.tokenize().get(0)))
- break LOOP
-
- try {
+ try {
inputHandler(input)
}
catch (Exception e) {
println e.getMessage()
}
+
+ if (["exit", "quit"].contains(input.tokenize().get(0)))
+ break LOOP
}
}
@@ -195,61 +180,41 @@ class CmdShell {
}
}
else {
- ioDevice.write "$input is not a valid command"
+ ioDevice.write "$input: command not found"
}
}
void cmdHelp() {
- Help help = new Help(ioDevice)
- help.availableCommands()
+ Command help = new Help(ioDevice)
+ help.execute(null)
}
void cmdConnect(String... args) {
-
- def host = args.length > 1 ? args[0] : HOST
- def port = args.length >= 2 ? args[1] : PORT
-
- if (args?.length == 4) {
- client.connect(host, port, args[2], args[3])
- }
- else {
- client.connect(host, port)
- }
- this.remote = client.remote
- if (this.remote) {
- ioDevice.write "Successfully connected to host $host:$port"
- }
- else {
- ioDevice.write 'Connection attempt was unsuccessful'
- }
+ Connect connect = new Connect(ioDevice)
+ connect.execute(client, args)
}
void cmdDisconnect() {
- ioDevice.write 'Disconnecting...'
if (client.remote) {
client.disconnect()
if (!client.remote) {
- ioDevice.write 'Successfully disconnected from host'
+ ioDevice.write 'Disconnected'
}
}
else {
- ioDevice.write 'Client can not disconnect because it is not
connected to a host'
+ ioDevice.write 'Not connected'
}
}
void cmdExit() {
- if (client.getRemote()) {
+ if (client.remote) {
client.disconnect()
- if (!client.getRemote()) {
- ioDevice.write 'Successfully disconnected from host'
- }
}
- ioDevice.write 'Exiting...'
- ioDevice.write 'Successfully exited kitty'
+ ioDevice.write 'Bye'
+ ioDevice.close()
}
void cmdLs() {
- ioDevice.write 'listing files and directories...'
if (remote) {
client.ls()
}
@@ -261,17 +226,11 @@ class CmdShell {
void cmdDomains() {
def domains = getClient().domains()
if (domains) {
- ioDevice.write 'Domains Detected: '
domains.eachWithIndex() { obj, i -> ioDevice.write " ${i}: ${obj}"
}
-
- }
- else {
- ioDevice.write 'No domains are available'
}
}
void cmdCd(String path) {
- ioDevice.write 'Changing remote path...'
if (remote) {
client.cd(path)
}
@@ -281,7 +240,6 @@ class CmdShell {
}
void cmdGet(def attr) {
- ioDevice.write "Get $attr..."
if (remote) {
client.get(attr)
}
@@ -291,7 +249,6 @@ class CmdShell {
}
void cmdSet(def attr, def val) {
- ioDevice.write "Set $attr to $val"
if (remote) {
client.set(attr, val)
}
@@ -301,7 +258,6 @@ class CmdShell {
}
void cmdInvoke(def op, def params) {
- ioDevice.write "Invoking the following operation: $op"
if (remote) {
client.invoke(op, params)
}
@@ -311,7 +267,6 @@ class CmdShell {
}
void cmdPwd() {
- ioDevice.write 'Displaying the current remote path...'
if (remote) {
String name = (String) client.pwd()
ioDevice.write name
@@ -322,7 +277,6 @@ class CmdShell {
}
void cmdSetDomain(def domain) {
- ioDevice.write "Setting the domain to $domain..."
if (remote) {
client.domain = domain
}
Modified:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy?rev=1299311&r1=1299310&r2=1299311&view=diff
==============================================================================
---
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy
(original)
+++
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy
Sat Mar 10 23:56:20 2012
@@ -19,6 +19,7 @@ package org.apache.kitty
import org.apache.kitty.client.Client
import jline.ConsoleReader
+import org.apache.kitty.io.Terminal
class CmdShellBuilder {
Added: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Command.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Command.groovy?rev=1299311&view=auto
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Command.groovy
(added)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Command.groovy Sat
Mar 10 23:56:20 2012
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kitty
+
+import org.apache.kitty.client.Client
+
+public interface Command {
+
+ void execute(Client client, String... args)
+}
\ No newline at end of file
Modified: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/IODevice.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/IODevice.groovy?rev=1299311&r1=1299310&r2=1299311&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/IODevice.groovy
(original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/IODevice.groovy Sat
Mar 10 23:56:20 2012
@@ -21,4 +21,5 @@ interface IODevice {
String read()
void write(String msg)
+ void close()
}
Modified: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy?rev=1299311&r1=1299310&r2=1299311&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy
(original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy Sat Mar
10 23:56:20 2012
@@ -18,17 +18,6 @@
package org.apache.kitty
-/**
- * <pre>
- * <b>Description</b>
- * <p>
- * This is the entry point to the remote management framework.
- * </p>
- * </pre>
- *
- * @version $Id$
- *
- */
class Main {
static final String KITTY_USAGE = "java -jar apache-kitty.jar <arg>"
@@ -40,12 +29,6 @@ class Main {
cli.i(longOpt: 'interactive', 'Launch in an interactive prompt
(default)')
cli.s(longOpt: 'script', 'Launch inline for scripted access')
- /*
- cli.d(longOpt: 'debug', 'Display debug information on output')
- cli.q(longOpt: 'quiet', 'Restrict output to bare minimum')
- cli.v(longOpt: 'verbose', 'Display extra information on
output')
- */
-
def opt = cli.parse(args)
if (opt?.h) {
Modified:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/client/Client.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/client/Client.groovy?rev=1299311&r1=1299310&r2=1299311&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/client/Client.groovy
(original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/client/Client.groovy
Sat Mar 10 23:56:20 2012
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package org.apache.kitty.client
import javax.management.Attribute
@@ -25,20 +24,6 @@ import javax.management.remote.JMXServic
import org.apache.kitty.exceptions.*
-
-/**
- * <pre>
- * <b>Description</p>
- * <p>
- * This is a Groovy implementation of the JSR 160 for a remote client.
- * It is generic and will be the basis for the rmi and jmxmp implemenentations
of the client.
- * This class is for development purposes only and will not be used in
production.
- * </p>
- * </pre>
- *
- * @version $Id$
- *
- */
class Client {
def host
@@ -105,12 +90,6 @@ class Client {
}
}
- /**
- * <pre>
- * Get a list of domains from the remote host and print the list to
standard output
- * </pre>
- * @return
- */
public domains() {
if (this.remote) {
this.domainList = remote.getDomains()
@@ -120,13 +99,6 @@ class Client {
}
}
- /**
- * <pre>
- * Assign a value to the domain
- * </pre>
- * @param domain
- * @return
- */
public setDomain(def domain) {
if (this.remote) {
@@ -144,10 +116,6 @@ class Client {
}
}
- /**
- *
- * @return
- */
public ls() {
if (!this.remote) {
@@ -241,10 +209,6 @@ class Client {
}
}
- /**
- *
- * @return
- */
public cd(String path) {
if (this.remote) {
if (this.domain) {
@@ -262,9 +226,6 @@ class Client {
}
}
- /**
- *
- */
public get(att) {
if (this.remote) {
if (this.domain) {
@@ -322,10 +283,6 @@ class Client {
}
}
- /**
- *
- * @return
- */
public set(att, val) {
if (this.remote) {
if (this.domain) {
@@ -366,12 +323,6 @@ class Client {
}
}
- /**
- *
- * @param op
- * @param params
- * @return
- */
public invoke(op, params) {
if (this.remote) {
if (this.domain) {
Added:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Connect.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Connect.groovy?rev=1299311&view=auto
==============================================================================
---
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Connect.groovy
(added)
+++
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Connect.groovy
Sat Mar 10 23:56:20 2012
@@ -0,0 +1,39 @@
+package org.apache.kitty.command
+
+import org.apache.kitty.client.Client
+import org.apache.kitty.Command
+import org.apache.kitty.IODevice
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ale
+ * Date: 10/03/2012
+ * Time: 23:43
+ * To change this template use File | Settings | File Templates.
+ */
+class Connect implements Command {
+ static final String HOST = "localhost"
+ static final String PORT = "1099"
+
+ IODevice ioDevice
+
+ Connect(IODevice ioDevice) {
+ this.ioDevice = ioDevice
+ }
+
+ @Override
+ void execute(Client client, String... args) {
+ def host = args.length > 1 ? args[0] : HOST
+ def port = args.length >= 2 ? args[1] : PORT
+
+ if (args?.length == 4) {
+ client.connect(host, port, args[2], args[3])
+ }
+ else {
+ client.connect(host, port)
+ }
+ if (!client.remote) {
+ ioDevice.write "Couldn't connect to $host:$port"
+ }
+ }
+}
Copied:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy
(from r1299299,
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Help.groovy)
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy?p2=incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy&p1=incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Help.groovy&r1=1299299&r2=1299311&rev=1299311&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Help.groovy
(original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy
Sat Mar 10 23:56:20 2012
@@ -14,16 +14,13 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
-package org.apache.kitty.utils
+package org.apache.kitty.command
import org.apache.kitty.IODevice
+import org.apache.kitty.Command
+import org.apache.kitty.client.Client
-/**
- *
- * @version $Id$
- *
- */
-class Help {
+class Help implements Command {
IODevice ioDevice
@@ -31,24 +28,19 @@ class Help {
this.ioDevice = ioDevice
}
- void availableCommands()
+ void execute(Client client, String... args)
{
- StringBuffer sb = new StringBuffer()
-
- sb.append "COMMANDS\n\n"
- sb.append "connect <host> <port> - Connect to the remote host\n"
- sb.append "disconnect - Disconnect from remote host\n"
- sb.append "cd <path> - Change the current mbean path\n"
- sb.append "exit - Quit the application and return to the
command prompt\n"
- sb.append "get <attribute> - Get an attribute from the remote
host\n"
- sb.append "set <attribute> <value> - Set an attribute on the
remote host\n"
- sb.append "setdomain <domain> - Set the domain in the current
session\n"
- sb.append "domains - List all available MBeanServer domains\n"
- sb.append "invoke <operation> <parameters...> - Invoke an
operation on the remote host\n"
- sb.append "ls - List all objects and attributes in current
mbean path\n"
- sb.append "pwd - print working directory of mbean path \n"
-
- ioDevice.write sb.toString()
+ ioDevice.write 'connect <host> <port> - Connect to the remote host'
+ ioDevice.write 'disconnect - Disconnect from remote host'
+ ioDevice.write 'cd <path> - Change the current mbean path'
+ ioDevice.write 'exit - Quit the application and return to the
command prompt'
+ ioDevice.write 'get <attribute> - Get an attribute from the
remote host'
+ ioDevice.write 'set <attribute> <value> - Set an attribute on
the remote host'
+ ioDevice.write 'setdomain <domain> - Set the domain in the
current session'
+ ioDevice.write 'domains - List all available MBeanServer domains'
+ ioDevice.write 'invoke <operation> <parameters...> - Invoke an
operation on the remote host'
+ ioDevice.write 'ls - List all objects and attributes in current
mbean path'
+ ioDevice.write 'pwd - print working directory of mbean path '
}
}
Propchange:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy
------------------------------------------------------------------------------
svn:keywords = Id Author Date Rev
Propchange:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/command/Help.groovy
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/io/Terminal.groovy (from
r1299299,
incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Terminal.groovy)
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/io/Terminal.groovy?p2=incubator/kitty/trunk/src/main/groovy/org/apache/kitty/io/Terminal.groovy&p1=incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Terminal.groovy&r1=1299299&r2=1299311&rev=1299311&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Terminal.groovy
(original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/io/Terminal.groovy
Sat Mar 10 23:56:20 2012
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.kitty
+package org.apache.kitty.io
import jline.History
import jline.SimpleCompletor
- import jline.ConsoleReader
+import jline.ConsoleReader
+import org.apache.kitty.IODevice
class Terminal implements IODevice {
@@ -39,15 +40,18 @@ class Terminal implements IODevice {
historyFile.createNewFile()
def history = new History(historyFile)
reader.setHistory history
- reader.setDefaultPrompt prompt
reader.addCompletor(new SimpleCompletor(commands))
}
String read() {
- reader?.readLine(0 as char)?.trim()
+ reader?.readLine(prompt, 0 as char)?.trim()
}
void write(String message) {
reader.printString "$message\n"
}
+
+ void close() {
+ reader.flushConsole()
+ }
}
Modified:
incubator/kitty/trunk/src/test/groovy/org/apache/kitty/test/TestGroovyShell.groovy
URL:
http://svn.apache.org/viewvc/incubator/kitty/trunk/src/test/groovy/org/apache/kitty/test/TestGroovyShell.groovy?rev=1299311&r1=1299310&r2=1299311&view=diff
==============================================================================
---
incubator/kitty/trunk/src/test/groovy/org/apache/kitty/test/TestGroovyShell.groovy
(original)
+++
incubator/kitty/trunk/src/test/groovy/org/apache/kitty/test/TestGroovyShell.groovy
Sat Mar 10 23:56:20 2012
@@ -18,7 +18,7 @@
package org.apache.kitty.test
-import org.apache.kitty.utils.Help;
+import org.apache.kitty.command.Help;
/**
* @version $Id$