You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/07/07 21:49:48 UTC
cvs commit: jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/demos ChirpWorld.java
leosimons 2002/07/07 12:49:48
Modified: tweety/src/java/org/apache/avalon/excalibur/tweety
Tweety.java
tweety/src/java/org/apache/avalon/excalibur/tweety/demos
ChirpWorld.java
Added: tweety/src/java/org/apache/avalon/excalibur/tweety Main.java
Log:
last commit went bad a bit; this completes the separation of main() into a separate class
Revision Changes Path
1.5 +1 -82 jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/Tweety.java
Index: Tweety.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/Tweety.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Tweety.java 3 Jul 2002 20:21:03 -0000 1.4
+++ Tweety.java 7 Jul 2002 19:49:48 -0000 1.5
@@ -36,7 +36,7 @@
*@author <a href="mailto:nicolaken@krysalis.org">Nicola Ken Barozzi</a>
*@author <a href="mailto:leosimons@apache.org">Leo Simons</a>
*@created June 20, 2002
- *@version 1.1
+ *@version 1.2
*/
public class Tweety implements LogEnabled, Contextualizable, Configurable, Initializable,
Parameterizable, Startable
@@ -106,87 +106,6 @@
*/
public Tweety()
{
- }
-
- //// METHOD TO HANDLE RUNNING FROM COMMAND LINE ////
- /**
- * This method is called to invoke tweety from the command line; It instantiates
- * a new <code>Tweety</code> instance, provides the parameters to configure
- * tweety by loading them from a file, and then runs tweety itself through its
- * lifecycle.
- *
- * <p><b>Note:</b> we should improve this method to create a sensible context and
- * configuration for hosted components.</p>
- *
- * @param args the command line arguments. We don't use them.
- */
- public static void main( String[] args )
- {
- // create logger
- ConsoleLogger logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
-
- try
- {
- /** @todo: this is stupid. Figure out what to do about contexts */
- // create dummy context
- Context context = new DefaultContext();
-
- /** @todo: this is stupid. Figure out what to do about configurations */
- // create dummy configuration
- Configuration config = new DefaultConfiguration( "empty config", "nowhere" );
-
- // load properties
- Properties properties = new Properties();
- properties.load(new FileInputStream("tweety.properties"));
-
- // create parameters from properties
- Parameters params = Parameters.fromProperties( properties );
-
- // debug: show the stuff we feed into tweety
-
- // create tweety instance
- Tweety tweety = new Tweety();
-
- logger.debug("Tweety: Providing tweety with a console logger.");
- tweety.enableLogging( logger );
-
- logger.debug("Tweety: Providing tweety with an empty context.");
- tweety.contextualize( context );
-
- logger.debug("Tweety: Providing tweety with an empty configuration");
- tweety.configure( config );
-
- String[] paramNames = params.getNames();
- logger.debug("Tweety: Configuring tweety with the following parameters:");
- for( int i = 0; i < paramNames.length; i++ )
- {
- logger.debug(" parameter: " + paramNames[i] +
- " = " + params.getParameter(paramNames[i]) );
- }
- tweety.parameterize( params );
-
- logger.debug("Tweety: Initializing tweety.");
- tweety.initialize();
-
- logger.debug("Tweety: Starting tweety");
- tweety.start();
-
- //
- // Here hosted components that create threads continue operation till they wish
- //
-
- tweety.stop();
- }
- catch( java.io.IOException ioe )
- {
- logger.error( "Tweety: Error reading configuration file.\nProgram Terminated", ioe );
- System.exit(-4);
- }
- catch( Exception e )
- {
- logger.error( "Tweety: Error starting up.\nProgram Terminated", e );
- System.exit(-2);
- }
}
//// AVALON FRAMEWORK LIFECYCLE METHODS ////
1.1 jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/Main.java
Index: Main.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.tweety;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.avalon.framework.activity.*;
import org.apache.avalon.framework.component.*;
import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.framework.context.*;
import org.apache.avalon.framework.logger.*;
import org.apache.avalon.framework.parameters.*;
import org.apache.avalon.framework.service.*;
import org.apache.avalon.framework.container.*;
/**
* This is the tweety 'bootstrapper'. It is used to run Tweety from the
* commandline. The single main() method calls all of Tweety's lifecycle
* methods.
*
*
*@author <a href="mailto:nicolaken@krysalis.org">Nicola Ken Barozzi</a>
*@author <a href="mailto:leosimons@apache.org">Leo Simons</a>
*@created July 4, 2002
*@version 1.0
*/
public class Main {
/**
* We've marked the constructor as protected to prevent instantiation.
* Main is not a real 'object' or 'component', but rather a container
* for some procedural code (inside the main() method). There is no
* need to create an instance of it.
*/
protected Main() {
}
//// COMMANDLINE ENTRY POINT ////
/**
* This method is called to invoke Tweety from the command line; It instantiates
* a new <code>Tweety</code> instance, provides the parameters to configure
* tweety by loading them from a file, and then runs tweety itself through its
* lifecycle.
*
* <p><b>Note:</b> we should improve this method to create a sensible context and
* configuration for hosted components.</p>
*
* @param args the command line arguments. We don't use them.
*/
public static void main( String[] args )
{
// create logger
ConsoleLogger logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
try
{
/** @todo: this is stupid. Figure out what to do about contexts */
// create dummy context
Context context = new DefaultContext();
/** @todo: this is stupid. Figure out what to do about configurations */
// create dummy configuration
Configuration config = new DefaultConfiguration( "empty config", "nowhere" );
// load properties
Properties properties = new Properties();
properties.load(new FileInputStream("tweety.properties"));
// create parameters from properties
Parameters params = Parameters.fromProperties( properties );
// debug: show the stuff we feed into tweety
// create tweety instance
Tweety tweety = new Tweety();
logger.debug("tweety.Main: Providing tweety with a console logger.");
tweety.enableLogging( logger );
logger.debug("tweety.Main: Providing tweety with an empty context.");
tweety.contextualize( context );
logger.debug("tweety.Main: Providing tweety with an empty configuration");
tweety.configure( config );
String[] paramNames = params.getNames();
logger.debug("tweety.Main: Configuring tweety with the following parameters:");
for( int i = 0; i < paramNames.length; i++ )
{
logger.debug(" parameter: " + paramNames[i] +
" = " + params.getParameter(paramNames[i]) );
}
tweety.parameterize( params );
logger.debug("tweety.Main: Initializing tweety.");
tweety.initialize();
logger.debug("tweety.Main: Starting tweety");
tweety.start();
//
// Here hosted components that create threads continue operation as
// long as they wish.
//
tweety.stop();
}
catch( java.io.IOException ioe )
{
logger.error( "tweety.Main: Error reading configuration file.\nProgram Terminated", ioe );
System.exit(-4);
}
catch( Exception e )
{
logger.error( "tweety.Main: Error starting up.\nProgram Terminated", e );
System.exit(-2);
}
}
}
1.5 +9 -9 jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/demos/ChirpWorld.java
Index: ChirpWorld.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/tweety/src/java/org/apache/avalon/excalibur/tweety/demos/ChirpWorld.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ChirpWorld.java 3 Jul 2002 20:21:03 -0000 1.4
+++ ChirpWorld.java 7 Jul 2002 19:49:48 -0000 1.5
@@ -38,47 +38,47 @@
public void enableLogging( Logger logger )
{
this.logger = logger;
- logger.debug("ChirpWorld: enableLogging() called, Logger gotten");
+ logger.debug("tweety.demos.ChirpWorld: enableLogging() called, Logger gotten");
}
public void contextualize( Context context )
{
this.context = context;
- logger.debug("ChirpWorld: contextualize() called, Context gotten");
+ logger.debug("tweety.demos.ChirpWorld: contextualize() called, Context gotten");
}
public void compose( ComponentManager cm )
{
this.cm = cm;
- logger.debug("ChirpWorld: compose() called, ComponentManager gotten");
+ logger.debug("tweety.demos.ChirpWorld: compose() called, ComponentManager gotten");
}
public void service( ServiceManager cm )
{
this.sm = sm;
- logger.debug("ChirpWorld: service() called, ServiceManager gotten");
+ logger.debug("tweety.demos.ChirpWorld: service() called, ServiceManager gotten");
}
public void initialize()
{
- logger.debug("ChirpWorld: initialize() called");
+ logger.debug("tweety.demos.ChirpWorld: initialize() called");
}
public void start()
{
- logger.debug("ChirpWorld: start() called");
+ logger.debug("tweety.demos.ChirpWorld: start() called");
- logger.info( "ChirpWorld: I thawgt I saw a pussycat!" );
+ logger.info( "tweety.demos.ChirpWorld: I thawgt I saw a pussycat!" );
}
public void stop()
{
- logger.debug("ChirpWorld: stop() called");
+ logger.debug("tweety.demos.ChirpWorld: stop() called");
}
public void dispose()
{
- logger.debug("ChirpWorld: dispose called");
+ logger.debug("tweety.demos.ChirpWorld: dispose called");
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>