Author: niclas Date: Sat Aug 7 03:20:37 2004 New Revision: 36057 Added: avalon/trunk/planet/facilities/console/ avalon/trunk/planet/facilities/console/api/ avalon/trunk/planet/facilities/console/api/build.properties (contents, props changed) avalon/trunk/planet/facilities/console/api/build.xml (contents, props changed) avalon/trunk/planet/facilities/console/api/src/ avalon/trunk/planet/facilities/console/api/src/main/ avalon/trunk/planet/facilities/console/api/src/main/org/ avalon/trunk/planet/facilities/console/api/src/main/org/apache/ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/Console.java (contents, props changed) avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/ConsoleCommand.java (contents, props changed) avalon/trunk/planet/facilities/console/blocks/ avalon/trunk/planet/facilities/console/blocks/build.properties (contents, props changed) avalon/trunk/planet/facilities/console/blocks/build.xml (contents, props changed) avalon/trunk/planet/facilities/console/blocks/default/ avalon/trunk/planet/facilities/console/blocks/default/build.properties (contents, props changed) avalon/trunk/planet/facilities/console/blocks/default/build.xml (contents, props changed) avalon/trunk/planet/facilities/console/blocks/default/src/ avalon/trunk/planet/facilities/console/blocks/default/src/deliverables/ avalon/trunk/planet/facilities/console/blocks/default/src/deliverables/console.block (contents, props changed) avalon/trunk/planet/facilities/console/build.properties (contents, props changed) avalon/trunk/planet/facilities/console/build.xml (contents, props changed) avalon/trunk/planet/facilities/console/commands/ avalon/trunk/planet/facilities/console/commands/build.properties (contents, props changed) avalon/trunk/planet/facilities/console/commands/build.xml (contents, props changed) avalon/trunk/planet/facilities/console/commands/src/ avalon/trunk/planet/facilities/console/commands/src/main/ avalon/trunk/planet/facilities/console/commands/src/main/org/ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/DummyCmd.java (contents, props changed) avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/EchoCmd.java (contents, props changed) avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ExitCmd.java (contents, props changed) avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/HelpCmd.java (contents, props changed) avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ThreadCmd.java (contents, props changed) avalon/trunk/planet/facilities/console/impl/ avalon/trunk/planet/facilities/console/impl/build.properties (contents, props changed) avalon/trunk/planet/facilities/console/impl/build.xml (contents, props changed) avalon/trunk/planet/facilities/console/impl/src/ avalon/trunk/planet/facilities/console/impl/src/main/ avalon/trunk/planet/facilities/console/impl/src/main/org/ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreter.java (contents, props changed) avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ConsoleImpl.java (contents, props changed) avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginCmd.java (contents, props changed) avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginException.java (contents, props changed) Log: Added a console interface, which I intend to populate with operations commands, such as viewing the model, hot-deploy, reload and other funky commands.
Added: avalon/trunk/planet/facilities/console/api/build.properties ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/api/build.properties Sat Aug 7 03:20:37 2004 @@ -0,0 +1,3 @@ +project.name = avalon-facilities-console-api +project.home = ../.. +project.system = ../../../../central/system Added: avalon/trunk/planet/facilities/console/api/build.xml ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/api/build.xml Sat Aug 7 03:20:37 2004 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<project name="avalon-facilities-console-api" default="install" basedir="."> + <property file="build.properties"/> + <import file="${project.system}/build/standard.xml"/> +</project> Added: avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/Console.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/Console.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,38 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console; + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +import java.util.Collection; + +/** Interface for the console. + * + * @avalon.service name="org.apache.avalon.facilities.console.Console" version="1.0" + */ +public interface Console +{ + void addCommand( ConsoleCommand cmd ); + + void removeCommand( ConsoleCommand cmd ); + + void removeCommand( String name ); + + ConsoleCommand getCommand( String name ); + + Collection getCommandNames(); +} Added: avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/ConsoleCommand.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/ConsoleCommand.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,39 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console; + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +/** Interface for a console command. + * + * @avalon.service name="org.apache.avalon.facilities.console.ConsoleCommand" version="1.0" + */ +public interface ConsoleCommand +{ + /** Returns the name, which also is the command with which it is invoked. + */ + String getName(); + + /** Returns a description of the command. + * <p>The Help command will utilize this method to provide more + * information about each command if that is sought by the user.</p> + */ + String getDescription(); + + void execute( BufferedReader input, BufferedWriter output, String[] arguments ) + throws Exception; +} Added: avalon/trunk/planet/facilities/console/blocks/build.properties ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/blocks/build.properties Sat Aug 7 03:20:37 2004 @@ -0,0 +1,2 @@ +project.system = ../../../../central/system +project.home = ../.. Added: avalon/trunk/planet/facilities/console/blocks/build.xml ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/blocks/build.xml Sat Aug 7 03:20:37 2004 @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<project name="runtime" default="default" basedir="." xmlns:x="antlib:org.apache.avalon.tools"> + + <property file="build.properties"/> + <import file="${project.system}/build/reactor.xml"/> + +</project> Added: avalon/trunk/planet/facilities/console/blocks/default/build.properties ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/blocks/default/build.properties Sat Aug 7 03:20:37 2004 @@ -0,0 +1,3 @@ +project.name = avalon-facilities-console-default +project.home = ../../.. +project.system = ../../../../../central/system Added: avalon/trunk/planet/facilities/console/blocks/default/build.xml ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/blocks/default/build.xml Sat Aug 7 03:20:37 2004 @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<project name="avalon-facilities-console-api" + default="install" + basedir="." + xmlns:x="antlib:org.apache.avalon.tools" +> + <property file="build.properties"/> + <import file="${project.system}/build/standard.xml"/> + + <target name="build" depends="standard.build"> + <x:block name="console-default"> + <x:component name="console" + class="org.apache.avalon.facilities.console.impl.ConsoleImpl" > + <x:parameters> + <x:parameter name="port" value="3333"/> + <x:parameter name="welcome-text" +value="Welcome to Merlin Console. +type help for more info."/> + </x:parameters> + </x:component> + + <x:component name="login" class="org.apache.avalon.facilities.console.impl.LoginCmd" > + <x:parameters> + <x:parameter name="root-password" value="yabadabadoo"/> + </x:parameters> + </x:component> + + <x:component name="thread" + class="org.apache.avalon.facilities.console.commands.ThreadCmd"/> + + <x:component name="echo" + class="org.apache.avalon.facilities.console.commands.EchoCmd"/> + + <x:component name="dummy" + class="org.apache.avalon.facilities.console.commands.DummyCmd"/> + + <x:component name="exit" + class="org.apache.avalon.facilities.console.commands.ExitCmd"/> + + <x:component name="help" + class="org.apache.avalon.facilities.console.commands.HelpCmd"/> + </x:block> + </target> + +</project> Added: avalon/trunk/planet/facilities/console/blocks/default/src/deliverables/console.block ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/blocks/default/src/deliverables/console.block Sat Aug 7 03:20:37 2004 @@ -0,0 +1 @@ + Added: avalon/trunk/planet/facilities/console/build.properties ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/build.properties Sat Aug 7 03:20:37 2004 @@ -0,0 +1,2 @@ +project.system = ../../../central/system +project.home = ../ Added: avalon/trunk/planet/facilities/console/build.xml ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/build.xml Sat Aug 7 03:20:37 2004 @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<project name="runtime" default="default" basedir="." xmlns:x="antlib:org.apache.avalon.tools"> + + <property file="build.properties"/> + <import file="${project.system}/build/reactor.xml"/> + +</project> Added: avalon/trunk/planet/facilities/console/commands/build.properties ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/commands/build.properties Sat Aug 7 03:20:37 2004 @@ -0,0 +1,3 @@ +project.name = avalon-facilities-console-commands +project.home = ../.. +project.system = ../../../../central/system Added: avalon/trunk/planet/facilities/console/commands/build.xml ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/commands/build.xml Sat Aug 7 03:20:37 2004 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<project name="avalon-facilities-console-commands" default="install" basedir="."> + <property file="build.properties"/> + <import file="${project.system}/build/standard.xml"/> +</project> Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/DummyCmd.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/DummyCmd.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,63 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.commands; + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; + +/** + * @avalon.component name="console-dummy" lifestyle="singleton" + * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand" + */ +public class DummyCmd + implements ConsoleCommand, Serviceable +{ + public String getName() + { + return "dummy"; + } + + public String getDescription() + { + String str = "usage: dummy\n\nDoes absolutely nothing."; + return str; + } + + /** + * @avalon.dependency type="org.apache.avalon.facilities.console.Console" + * key="console" + */ + public void service( ServiceManager man ) + throws ServiceException + { + Console console = (Console) man.lookup( "console" ); + console.addCommand( this ); + } + + public void execute( BufferedReader input, BufferedWriter output, String[] arguments ) + throws Exception + { + output.newLine(); + output.flush(); + } +} Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/EchoCmd.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/EchoCmd.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,70 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.commands; + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; + +/** + * @avalon.component name="console-echo" lifestyle="singleton" + * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand" + */ +public class EchoCmd + implements ConsoleCommand, Serviceable +{ + public String getName() + { + return "echo"; + } + + public String getDescription() + { + String str = "usage: echo (string)*\n\nSends each of the string arguments back separate by a space."; + return str; + } + + /** + * @avalon.dependency type="org.apache.avalon.facilities.console.Console" + * key="console" + */ + public void service( ServiceManager man ) + throws ServiceException + { + Console console = (Console) man.lookup( "console" ); + console.addCommand( this ); + } + + public void execute( BufferedReader input, BufferedWriter output, String[] arguments ) + throws Exception + { + output.newLine(); + output.write( "echo: " ); + for( int i=0 ; i < arguments.length ; i++ ) + { + output.write( arguments[i] ); + output.write( " " ); + } + output.newLine(); + output.flush(); + } +} Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ExitCmd.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ExitCmd.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,65 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.commands; + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; + +/** + * @avalon.component name="console-exit" lifestyle="singleton" + * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand" + */ +public class ExitCmd + implements ConsoleCommand, Serviceable +{ + public String getName() + { + return "exit"; + } + + public String getDescription() + { + String str = "usage: exit\n\nTerminates the session."; + return str; + } + + /** + * @avalon.dependency type="org.apache.avalon.facilities.console.Console" + * key="console" + */ + public void service( ServiceManager man ) + throws ServiceException + { + Console console = (Console) man.lookup( "console" ); + console.addCommand( this ); + } + + public void execute( BufferedReader input, BufferedWriter output, String[] arguments ) + throws Exception + { + output.write( "Logging out..." ); + output.newLine(); + output.flush(); + throw new InterruptedException( "Exit the session." ); + } +} Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/HelpCmd.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/HelpCmd.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,94 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.commands; + + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +import java.util.Iterator; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; + +/** + * @avalon.component name="console-help" lifestyle="singleton" + * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand" + */ +public class HelpCmd + implements ConsoleCommand, Serviceable +{ + private Console m_Console; + + public String getName() + { + return "help"; + } + + public String getDescription() + { + String str = "usage: help (command)*\n\nGives a short description of each command.\nIf no command is given, then a list of available commands are printed."; + return str; + } + + /** + * @avalon.dependency type="org.apache.avalon.facilities.console.Console" + * key="console" + */ + public void service( ServiceManager man ) + throws ServiceException + { + m_Console = (Console) man.lookup( "console" ); + m_Console.addCommand( this ); + } + + public void execute( BufferedReader input, BufferedWriter output, String[] arguments ) + throws Exception + { + output.newLine(); + if( arguments.length == 0 ) + { + output.write( "Available commands:" ); + output.newLine(); + output.write( "===================" ); + output.newLine(); + Iterator list = m_Console.getCommandNames().iterator(); + while( list.hasNext() ) + { + output.write( list.next().toString() ); + output.newLine(); + } + } else + { + for( int i=0 ; i < arguments.length ; i++ ) + { + ConsoleCommand cmd = m_Console.getCommand( arguments[i] ); + if( cmd != null ) + { + String descr = cmd.getDescription(); + output.write( descr ); + output.newLine(); + } + } + } + output.newLine(); + output.flush(); + } +} Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ThreadCmd.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ThreadCmd.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,77 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.commands; + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; + +/** + * @avalon.component name="console-thread" lifestyle="singleton" + * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand" + */ +public class ThreadCmd + implements ConsoleCommand, Serviceable +{ + public String getName() + { + return "thread"; + } + + public String getDescription() + { + String str = "usage: thread\n\nLists all current threads in the JVM."; + return str; + } + + /** + * @avalon.dependency type="org.apache.avalon.facilities.console.Console" + * key="console" + */ + public void service( ServiceManager man ) + throws ServiceException + { + Console console = (Console) man.lookup( "console" ); + console.addCommand( this ); + } + + public void execute( BufferedReader input, BufferedWriter output, String[] arguments ) + throws Exception + { + ThreadGroup tg = Thread.currentThread().getThreadGroup(); + ThreadGroup root = tg; + while( tg != null ) + { + root = tg; + tg = tg.getParent(); + } + int size = root.activeCount(); + Thread[] threads = new Thread[size+10]; + int created = root.enumerate( threads, true ); + for( int i=0 ; i < created ; i++ ) + { + output.write( threads[i].toString() ); + output.newLine(); + } + output.flush(); + } +} Added: avalon/trunk/planet/facilities/console/impl/build.properties ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/impl/build.properties Sat Aug 7 03:20:37 2004 @@ -0,0 +1,3 @@ +project.name = avalon-facilities-console-impl +project.home = ../.. +project.system = ../../../../central/system Added: avalon/trunk/planet/facilities/console/impl/build.xml ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/impl/build.xml Sat Aug 7 03:20:37 2004 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<project name="avalon-facilities-console-impl" default="install" basedir="."> + <property file="build.properties"/> + <import file="${project.system}/build/standard.xml"/> +</project> Added: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreter.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreter.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.impl; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +import java.net.Socket; + +import java.util.TreeMap; +import java.util.Map; +import java.util.StringTokenizer; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +class CommandInterpreter extends Thread +{ + private Socket m_Socket; + private boolean m_Login; + private BufferedWriter m_Output; + private BufferedReader m_Input; + private Console m_Console; + + CommandInterpreter( Socket socket, String welcome, Console console ) + throws IOException + { + m_Socket = socket; + m_Console = console; + welcomeMessage( welcome ); + } + + public void run() + { + boolean running = true; + while( running ) + { + try + { + if( ! m_Login ) + execute( "login" ); + m_Login = true; //LoginCmd throws an exception if login fails. + execute( waitForCommandLine() ); + } catch( InterruptedException e ) + { + running = false; + } catch( Exception e ) + { + String mess = e.getMessage(); + if( mess == null ) + mess = "<null>"; + errorMessage( mess ); + e.printStackTrace(); + } + } + try + { + m_Socket.close(); + } catch( IOException e ) + { + } + } + + private void execute( String cmdline ) + throws Exception + { + String command = parseCommand( cmdline ); + ConsoleCommand cmd = m_Console.getCommand( command ); + if( cmd != null ) + { + String[] args = parseArguments( cmdline ); + cmd.execute( getInput(), getOutput(), args ); + } + else + errorMessage( "Unknown command. 'help' for available commands." ); + + } + + private String waitForCommandLine() + throws IOException + { + String cmdline = m_Input.readLine().trim(); + return cmdline; + } + + private String parseCommand( String cmdline ) + { + StringTokenizer st = new StringTokenizer( cmdline, " ", false ); + if( st.hasMoreTokens() ) + return st.nextToken(); + else + return ""; + } + + private String[] parseArguments( String cmdline ) + { + StringTokenizer st = new StringTokenizer( cmdline, " ", false ); + if( st.hasMoreTokens() ) + st.nextToken(); // remove Command portion; + String[] args = new String[ st.countTokens() ]; + for( int i=0 ; st.hasMoreTokens() ; i++ ) + args[i] = st.nextToken(); + return args; + } + + private void welcomeMessage( String message ) + { + try + { + getOutput().write( message ); + getOutput().newLine(); + getOutput().flush(); + } catch( IOException e ) + { + e.printStackTrace( System.out ); + } + } + + private void errorMessage( String message ) + { + try + { + getOutput().write( message ); + getOutput().newLine(); + getOutput().flush(); + } catch( IOException e ) + { + e.printStackTrace( System.out ); + } + } + + private BufferedWriter getOutput() + throws IOException + { + if( m_Output == null ) + openOut(); + return m_Output; + } + + private BufferedReader getInput() + throws IOException + { + if( m_Input == null ) + openIn(); + return m_Input; + } + + private void openOut() + throws IOException + { + m_Output = new BufferedWriter( new OutputStreamWriter( m_Socket.getOutputStream() ) ); + } + + private void openIn() + throws IOException + { + m_Input = new BufferedReader( new InputStreamReader( m_Socket.getInputStream() ) ); + } + +} + Added: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ConsoleImpl.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ConsoleImpl.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,153 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.impl; + +import java.io.IOException; + +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Hashtable; +import java.util.Iterator; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.activity.Startable; + +import org.apache.avalon.framework.logger.AbstractLogEnabled; + +import org.apache.avalon.framework.parameters.ParameterException; +import org.apache.avalon.framework.parameters.Parameterizable; +import org.apache.avalon.framework.parameters.Parameters; + + +/** + * @avalon.component name="console-impl" lifestyle="singleton" + * @avalon.service type="org.apache.avalon.facilities.console.Console" + */ +public class ConsoleImpl extends AbstractLogEnabled + implements Console, Runnable, Startable, Parameterizable, Initializable +{ + private int m_Port; + private ServerSocket m_ServerSocket; + private Thread m_Thread; + private Hashtable m_Commands; + private ArrayList m_Interpreters; + private String m_Welcome; + + public void parameterize( Parameters params ) + throws ParameterException + { + m_Port = params.getParameterAsInteger( "port", 3333 ); + m_Welcome = params.getParameter( "welcome-text", "type 'help' form more info." ); + } + + public void initialize() + throws Exception + { + m_Interpreters = new ArrayList(); + m_Commands = new Hashtable(); + m_ServerSocket = new ServerSocket( m_Port ); + } + + public void start() + { + /* start new thread for monitoring and updating. */ + getLogger().info( "Console started." ); + m_Thread = new Thread( this ); + m_Thread.start(); + } + + public void stop() + { + try + { + m_Thread.interrupt(); + m_ServerSocket.close(); + } catch( IOException e ) + {} + } + + public void dispose() + { + getLogger().info("Console disposed."); + } + + public void addCommand( ConsoleCommand cmd ) + { + getLogger().info( "Added " + cmd.getName() + " command." ); + m_Commands.put( cmd.getName(), cmd ); + } + + public void removeCommand( ConsoleCommand cmd ) + { + m_Commands.remove( cmd.getName() ); + } + + public void removeCommand( String commandname ) + { + m_Commands.remove( commandname ); + } + + public ConsoleCommand getCommand( String name ) + { + return (ConsoleCommand) m_Commands.get( name ); + } + + public Collection getCommandNames() + { + return m_Commands.keySet(); + } + + public void run() + { + boolean running = true; + while( running ) + { + try + { + Socket socket = m_ServerSocket.accept(); + CommandInterpreter intp = new CommandInterpreter( socket, m_Welcome, this ); + m_Interpreters.add( intp ); + intp.start(); + } catch( IOException e ) + { + running = false; + } catch( Exception e ) + { + getLogger().warn( "", e ); + try + { + Thread.sleep( 60000 ); + } catch( InterruptedException f ) + { + running = false; + } + } + } + Iterator list = m_Interpreters.iterator(); + while( list.hasNext() ) + { + CommandInterpreter intp = (CommandInterpreter) list.next(); + intp.interrupt(); + } + } +} Added: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginCmd.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginCmd.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,87 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.impl; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; + +import org.apache.avalon.facilities.console.Console; +import org.apache.avalon.facilities.console.ConsoleCommand; + +import org.apache.avalon.framework.parameters.ParameterException; +import org.apache.avalon.framework.parameters.Parameterizable; +import org.apache.avalon.framework.parameters.Parameters; + +import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; + +/** + * @avalon.component name="console-login" lifestyle="singleton" + * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand" + */ +public class LoginCmd + implements ConsoleCommand, Parameterizable, Serviceable +{ + private String m_Password; + + public String getName() + { + return "login"; + } + + public String getDescription() + { + String str = "usage: login\n\nLogins to the system. This command is executed automatically."; + return str; + } + + public void parameterize( Parameters params ) + throws ParameterException + { + m_Password = params.getParameter( "root-password" ); + } + + /** + * @avalon.dependency type="org.apache.avalon.facilities.console.Console" + * key="console" + */ + public void service( ServiceManager man ) + throws ServiceException + { + Console console = (Console) man.lookup( "console" ); + console.addCommand( this ); + } + + public void execute( BufferedReader input, BufferedWriter output, String[] arguments ) + throws Exception + { + output.write( "Password:" ); + output.flush(); + String password = input.readLine(); + if( password != null ) + { + if( ! password.trim().equals( m_Password ) ) + throw new LoginException(); + } + output.newLine(); + output.write( "Login successful." ); + output.newLine(); + output.newLine(); + output.flush(); + } +} Added: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginException.java ============================================================================== --- (empty file) +++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginException.java Sat Aug 7 03:20:37 2004 @@ -0,0 +1,23 @@ +/* + * Copyright 1997-2004 Apache Software Foundation + * + * Licensed 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.avalon.facilities.console.impl; + + +public class LoginException extends Exception +{ + +} + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]