You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by sg...@apache.org on 2005/05/10 12:58:32 UTC

cvs commit: jakarta-turbine-fulcrum/yaafi/xdocs todo.xml

sgoeschl    2005/05/10 03:58:32

  Modified:    yaafi/tutorial/src/java/tutorial/running Application.java
                        Factory.java
               yaafi/xdocs/tutorial index.xml step3.xml step5.xml
               yaafi/xdocs/services servicemanagerservice.xml
               yaafi/tutorial/src/java/tutorial/service
                        SystemPropertyService.java
                        SystemPropertyServiceImpl.java
               yaafi/src/test TestComponentConfig.xml
               yaafi/xdocs todo.xml
  Log:
  Updated tutorial
  
  Revision  Changes    Path
  1.2       +6 -2      jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/running/Application.java
  
  Index: Application.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/running/Application.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Application.java	9 May 2005 17:52:01 -0000	1.1
  +++ Application.java	10 May 2005 10:58:32 -0000	1.2
  @@ -1,7 +1,7 @@
   package tutorial.running;
   
   /*
  - * Copyright 2001-2004 The Apache Software Foundation.
  + * Copyright 2005 The 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.
  @@ -31,6 +31,10 @@
       /** the YAAFI command line interface */
       private Main cli;
   
  +    /**
  +     * Main routine
  +     * @param args the command line arguments
  +     */
       public static void main( String[] args )
       {
           try
  @@ -76,7 +80,7 @@
           // 1.4) install a JVM shutdown hook to dispose the YAAFI container
           this.cli.setHasShutdownHook(true);
   
  -        // 2) initialize the logger
  +        // 2) initialize the console logger
   
           ConsoleLogger consoleLogger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
           this.cli.setLogger( consoleLogger );
  
  
  
  1.2       +6 -3      jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/running/Factory.java
  
  Index: Factory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/running/Factory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Factory.java	9 May 2005 17:52:01 -0000	1.1
  +++ Factory.java	10 May 2005 10:58:32 -0000	1.2
  @@ -1,7 +1,7 @@
   package tutorial.running;
   
   /*
  - * Copyright 2001-2004 The Apache Software Foundation.
  + * Copyright 2005 The 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.
  @@ -29,6 +29,10 @@
   
   public class Factory
   {
  +    /**
  +     * Main routine
  +     * @param args the command line arguments
  +     */
       public static void main( String[] args )
       {
           try
  @@ -41,11 +45,10 @@
               container = ServiceContainerFactory.create( config );
   
               container.dispose();
  -
           }
           catch( Throwable t )
           {
  -            String msg = "Execution of the server failed : " + t.getMessage();
  +            String msg = "Execution failed : " + t.getMessage();
               System.err.println(msg);
           }
       }
  
  
  
  1.2       +1 -0      jakarta-turbine-fulcrum/yaafi/xdocs/tutorial/index.xml
  
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/xdocs/tutorial/index.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- index.xml	9 May 2005 17:52:50 -0000	1.1
  +++ index.xml	10 May 2005 10:58:32 -0000	1.2
  @@ -23,6 +23,7 @@
              <li>read the system properties to be set from the component configuration file</li>
              <li>write some diagnostic output to the logfile</li>
              <li>be reconfigurable without restarting the container</li>
  +           <li>dump the updated system properties into the temporary directory</li>
            </ul>       
          </p>       
        </subsection>
  
  
  
  1.2       +88 -15    jakarta-turbine-fulcrum/yaafi/xdocs/tutorial/step3.xml
  
  Index: step3.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/xdocs/tutorial/step3.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- step3.xml	9 May 2005 17:52:50 -0000	1.1
  +++ step3.xml	10 May 2005 10:58:32 -0000	1.2
  @@ -37,30 +37,56 @@
   
         <subsection name="Chasing the Interfaces to Implement">        
           <p>
  -          The Avalon Service Container interacts with an Avalon service through a bunch
  -          of interfaces and finding the right one's might be challenge in the beginning. Our
  -          service needs access to the logging infrastructure, to the component configuration
  -          and needs to tell the Avalon Service Container that it is reconfigurable:
  +          The Avalon Service Container interacts with an Avalon service 
  +          through a bunch of interfaces also known as 
  +          <a href="../lifecycle/index.html">Avalon Lifecycle 
  +          Management Specification</a>. Finding the right interface might be 
  +          challenge in the beginning but it is not an unsurmountable task. 
  +          Our service needs access to the logging infrastructure, to the 
  +          component configuration and needs to tell the Avalon Service 
  +          Container that it is reconfigurable. To make things more 
  +          interesting we want to dump the updated system properties into 
  +          the temp directory of the application during service initialization.        
             <source><![CDATA[            
   public class SystemPropertyServiceImpl
       extends AbstractLogEnabled
  -    implements SystemPropertyService, Reconfigurable
  +    implements SystemPropertyService, Reconfigurable, Contextualizable, Initializable
   {
       // here comes the implementation ...
   }
             ]]></source>                  
           </p>        
           <p>
  -          Our service is deriving from "AbstractLogEnabled" which takes care of getting
  -          access to the logger. The implementation class also implements the "Reconfigurable"
  -          interface which tells the Avalon Service Container that the service implements
  +          Our service derives from "AbstractLogEnabled" which takes 
  +          care of getting access to the logger. The implementation 
  +          class also implements the "Reconfigurable" interface which 
  +          tells the Avalon Service Container that the service implements
             <ul>
               <li>public void configure(Configuration configuration)</li>
               <li>public void reconfigure(Configuration configuration)</li>
             </ul>                    
           </p>
  +        <p>
  +          The information about the application context is provided by 
  +          the "Contextualizable" interface while the service initialization
  +          needs the "Initializable" interface.
  +        </p>
         </subsection>
   
  +      <subsection name="Accessing the Avalon Context">        
  +        <p>
  +          The <a href="../specification/context.html">Avalon Context </a>contains 
  +          environment settings such as the current working directory, the 
  +          temporary directory or the name of the service.
  +            <source><![CDATA[            
  +public void contextualize(Context context) throws ContextException
  +{        
  +    this.tempDir = (File) context.get("urn:avalon:temp");
  +}
  +            ]]></source>        
  +        </p>
  +      </subsection>
  +      
         <subsection name="Accessing the Component Configuration">        
           <p>
             In the Role Configuration file we defined "SystemPropertyService" as shorthand for accessing
  @@ -92,6 +118,23 @@
               ]]></source>                  
           </p>                      
         </subsection>
  +
  +      <subsection name="Service Initialization ">        
  +        <p>
  +          Since we have done most of our work already we use the 
  +          service initialization to dump the current system properties
  +          into the temporary directory. 
  +            <source><![CDATA[            
  +public void initialize() throws Exception
  +{
  +    FileOutputStream fos = new FileOutputStream( new File(this.tempDir,"system.properties") );
  +    System.getProperties().store( fos, "system.properties" );
  +    fos.flush();
  +    fos.close();
  +}
  +            ]]></source>        
  +        </p>
  +      </subsection>
                    
         <subsection name="Implementing the Reconfiguration">        
           <p>
  @@ -109,7 +152,7 @@
   
         <subsection name="Putting it all together">                
           <p>
  -          Here is our complete and fully functional Avalon service
  +          Below you find your first complete and fully functional Avalon service.
             <source><![CDATA[            
   public interface SystemPropertyService
   {
  @@ -118,25 +161,55 @@
   
   public class SystemPropertyServiceImpl
       extends AbstractLogEnabled
  -    implements SystemPropertyService, Reconfigurable
  +    implements SystemPropertyService, Reconfigurable, Contextualizable, Initializable
   {
  +    /** the Avalon temp directory */
  +    private File tempDir;
  +        
  +    /**
  +     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
  +     */
  +    public void contextualize(Context context) throws ContextException
  +    {        
  +        this.tempDir = (File) context.get("urn:avalon:temp");
  +    }
  +    
  +    /**
  +     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
  +     */
       public void configure(Configuration configuration) throws ConfigurationException
       {
           Configuration[] systemProperties = configuration.getChildren("property");
  -        
  +
           for( int i=0; i<systemProperties.length; i++ )
           {
               String key = systemProperties[i].getAttribute("name");
               String value = systemProperties[i].getValue();
               this.getLogger().debug( "Setting the value of " + key + " to " + value );
  -            System.setProperty( key, value );           
  -        }
  +            System.setProperty( key, value );
  +        }        
       }
   
  -    public void reconfigure(Configuration configuration) throws ConfigurationException
  +    /**
  +     * @see org.apache.avalon.framework.activity.Initializable#initialize()
  +     */
  +    public void initialize() throws Exception
  +    {
  +        FileOutputStream fos = new FileOutputStream( new File(this.tempDir,"system.properties") );
  +        System.getProperties().store( fos, "system.properties" );
  +        fos.flush();
  +        fos.close();
  +    }
  +    
  +    /**
  +     * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration)
  +     */
  +    public void reconfigure(Configuration configuration)
  +        throws ConfigurationException
       {
           this.configure(configuration);
  -    }                    
  +    }
  +}
             ]]></source>                  
           </p>
         </subsection>
  
  
  
  1.2       +39 -4     jakarta-turbine-fulcrum/yaafi/xdocs/tutorial/step5.xml
  
  Index: step5.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/xdocs/tutorial/step5.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- step5.xml	9 May 2005 17:52:50 -0000	1.1
  +++ step5.xml	10 May 2005 10:58:32 -0000	1.2
  @@ -26,17 +26,52 @@
           </p>   
           
           <p>
  -          The following examples shows how to use a Log4J logger
  +          The following examples shows how to use a Log4J logger assuming that
  +          the configuration is located in the "conf" directory and tells Log4J
  +          to monitor the configuration file to detect changes of the trace level.
             <source><![CDATA[   
   Main cli = new Main(args)
   String log4jConfig = cli.makeAbsolutePath( System.getProperty("log4j.configuration", "./conf/log4j.properties") );        
   PropertyConfigurator.configureAndWatch( log4jConfig, 2000 );
   cli.setLogger( new Log4JLogger( Logger.getLogger("main") ) );	    
             ]]></source>                                   
  -        </p>
  -                     
  +        </p>                     
         </subsection>
  -              
  +
  +      <subsection name="Looking up a Service">
  +        <p>    
  +          Using an Avalon container requires your application to lookup
  +          services during runtime. This functionality is exposed through
  +          the "ServiceManager" interface. The real question is how to get
  +          hold of a "ServiceManager" interface without polluting the whole
  +          application with Avalon dependencies. Unfortunately there is no 
  +          simple answer to that
  +          <ul>
  +            <li>
  +              You can keep a "ServiceManager" instance from initializing
  +              the YAAFI container.
  +           </li>
  +            <li>
  +              Your service can implement the "Servicable" interface to get
  +              an instance of a "ServiceManager".
  +           </li>
  +            <li>
  +              Your can lookup the services using the 
  +              <a href="../services/servicemanagerservice.html">ServiceManagerService</a>
  +           </li>           
  +          </ul>
  +        </p>                     
  +      </subsection>
  +
  +      <subsection name="Dynamic Reconfiguration">
  +        <p>    
  +          A reconfiguration can be triggered by your application code
  +          or by the 
  +          <a href="../services/reconfigurationservice.html">ReconfigurationService</a>
  +          which monitors the component configuration file.
  +        </p>                     
  +      </subsection>
  +          
       </section>
   
     </body>
  
  
  
  1.3       +36 -36    jakarta-turbine-fulcrum/yaafi/xdocs/services/servicemanagerservice.xml
  
  Index: servicemanagerservice.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/xdocs/services/servicemanagerservice.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- servicemanagerservice.xml	2 Mar 2005 09:42:05 -0000	1.2
  +++ servicemanagerservice.xml	10 May 2005 10:58:32 -0000	1.3
  @@ -1,45 +1,45 @@
   <?xml version="1.0"?>
   <document>
   
  -    <properties>
  -        <title>ServiceManagerService</title>
  -        <author email="siegfried.goeschl@it20one.at">Siegfried Goeschl</author>
  -    </properties>
  +  <properties>
  +    <title>ServiceManagerService</title>
  +    <author email="siegfried.goeschl@it20one.at">Siegfried Goeschl</author>
  +  </properties>
   
  -    <body>
  +  <body>
   
  -        <section name="Overview">
  -            <p>
  -                This service keeps an YAAFI instance.
  -            </p>
  -            <p>
  -            </p>            
  -        </section>
  +    <section name="Overview">
  +      <p>
  +        This service keeps a ServiceManager instance and other Avalon artificats
  +        to simplify access through your application code.
  +      </p>
  +    </section>
   
  -        <section name="Configuration">
  -            <subsection name="Role Configuration">
  -                <source>
  -                    <![CDATA[
  -<role
  -    default-class="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService"
  -    early-init="true"
  -/>                       ]]>
  -                </source>
  -            </subsection>
  -        </section>
  +    <section name="Configuration">
  +      <subsection name="Role Configuration">
  +        <source><![CDATA[
  +  <role
  +    name="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService"
  +    default-class="org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerServiceImpl"
  +  />    
  +            ]]></source>
  +      </subsection>
  +    </section>
   
  -        <section name="Usage">
  -            <p>
  -                ServiceManagerServiceImpl.getInstance() returns you an instance of
  -                ServiceManager which allows to lookup other services.
  -            </p>
  -            
  -            <source>
  -ServiceManagerServiceImpl.getInstance().hasService("FOO");
  -FOO foo = (FOO) ServiceManagerServiceImpl.getInstance().lookup("FOO");
  -            </source>
  -        </section>
  -        
  -    </body>
  +    <section name="Usage">
  +      <p>
  +        ServiceManagerServiceImpl.getInstance() returns you an instance of
  +        ServiceManager which allows to lookup other services.
  +      </p>
  +      <source><![CDATA[
  +ServiceManagerService serviceManagerService = ServiceManagerServiceImpl.getInstance();
  +
  +Logger logger = serviceManagerService.getAvalonLogger();
  +boolean hasFoo = serviceManagerService.hasService("Foo");
  +Foo foo = (Foo) serviceManagerService.lookup("Foo");
  +File home = (File) serviceManagerService.getContext().get("urn:avalon:home")
  +      ]]></source>
  +    </section>
       
  +  </body>
   </document>
  
  
  
  1.2       +1 -1      jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service/SystemPropertyService.java
  
  Index: SystemPropertyService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service/SystemPropertyService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SystemPropertyService.java	9 May 2005 17:52:01 -0000	1.1
  +++ SystemPropertyService.java	10 May 2005 10:58:32 -0000	1.2
  @@ -1,7 +1,7 @@
   package tutorial.service;
   
   /*
  - * Copyright 2004 Apache Software Foundation
  + * Copyright 2005 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
  
  
  
  1.2       +1 -1      jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service/SystemPropertyServiceImpl.java
  
  Index: SystemPropertyServiceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/tutorial/src/java/tutorial/service/SystemPropertyServiceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SystemPropertyServiceImpl.java	9 May 2005 17:52:01 -0000	1.1
  +++ SystemPropertyServiceImpl.java	10 May 2005 10:58:32 -0000	1.2
  @@ -1,7 +1,7 @@
   package tutorial.service;
   
   /*
  - * Copyright 2004 Apache Software Foundation
  + * Copyright 2005 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
  
  
  
  1.5       +16 -17    jakarta-turbine-fulcrum/yaafi/src/test/TestComponentConfig.xml
  
  Index: TestComponentConfig.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/src/test/TestComponentConfig.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestComponentConfig.xml	7 Apr 2005 11:39:09 -0000	1.4
  +++ TestComponentConfig.xml	10 May 2005 10:58:32 -0000	1.5
  @@ -1,37 +1,36 @@
   <?xml version="1.0" encoding="UTF-8"?>
  -
   <componentConfig>
  -
  - <test>
  +  
  +  <test>
       <FOO>FOO</FOO>
     </test>
  - 
  - <SystemPropertyService>
  +
  +  <SystemPropertyService>
       <property name="FOO">BAR</property>
     </SystemPropertyService>
  -  
  +
     <ReconfigurationService interval="5000">
       <entry>
  -      <location>./src/test/TestComponentConfig.xml</location> 
  +      <location>./src/test/TestComponentConfig.xml</location>
       </entry>
       <entry>
         <location>./src/test/TestParameters.properties</location>
         <services>
           <service name="org.apache.fulcrum.yaafi.TestComponent"/>
           <service name="org.apache.fulcrum.yaafi.service.systemproperty.SystemPropertyService"/>
  -      </services> 
  -    </entry>    
  +      </services>
  +    </entry>
       <shutdown>
  -      <location>./src/test/shutdown.txt</location> 
  -      <useSystemExit>false</useSystemExit> 
  -    </shutdown>    
  +      <location>./src/test/shutdown.txt</location>
  +      <useSystemExit>false</useSystemExit>
  +    </shutdown>
     </ReconfigurationService>
   
     <ShutdownService interval="5000">
       <entry>
  -      <location>./src/test/shutdown.txt</location> 
  -      <useSystemExit>true</useSystemExit> 
  -    </entry>    
  +      <location>./src/test/shutdown.txt</location>
  +      <useSystemExit>true</useSystemExit>
  +    </entry>
     </ShutdownService>
  -  
  -</componentConfig>
  \ No newline at end of file
  +
  +</componentConfig>
  
  
  
  1.5       +10 -1     jakarta-turbine-fulcrum/yaafi/xdocs/todo.xml
  
  Index: todo.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/yaafi/xdocs/todo.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- todo.xml	2 Mar 2005 09:42:05 -0000	1.4
  +++ todo.xml	10 May 2005 10:58:32 -0000	1.5
  @@ -11,13 +11,22 @@
   
       <section name="TODO">
   
  +      <subsection name="Using a Proxy">            
  +        <p>
  +          Currently the caller of a service uses the instance
  +          implementing the service interface directly. It would
  +          be useful to hand out a proxy object to delegate the 
  +          service invocation similiar to EJB and HiveMind.
  +        </p>
  +      </subsection>
  +
         <subsection name="Long-term Compatibilty with Fortress">            
           <p>
             Since Fortress is the only other remaining Avalon container
             within Jakarta we try to achieve compatibility with Fortress
             regarding configuration files. The problem is that there is no
             specification available how the Fortress configuration files
  -          look loke ... :-(
  +          look like ... :-(
           </p>
         </subsection>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org