Dominique,

Anton did an excellent job in answering your question #3.  I just wanted to add
some other points:

--- Dominique Paquin <[EMAIL PROTECTED]> wrote:
> 
> By looking at the Main of the Swing example I see that I have to :
> 1) build my 4 XML documents and load them in a FortressConfig instance. 

As Berin pointed out to me recently, the logger and instrumentation
configuration files are _optional_.  Fortress will run without them by using
default settings.  In fact, if you also use the meta format for your roles, you
don't need a roles file either.

> 2) run the setContainerConfiguration(), setLoggerManagerConfiguration(),
> setRoleManagerConfiguration() and setInstrumentManagerConfiguration()
> 3) Then a ContainerManager is instantiated with a
> DefaultContainerManager and after that
> ContainerUtil.initialize(ContainerManager) is executed with the
> ContainerManager, previously instantiated, in parameter.
> 4) finally run() is called after a getContainer() is done to get the
> container.

Ah, yes, container.run().

This isn't always needed.  As stated in the example, it works well for Swing
applications, but it's not necessary for many other server-based applications. 

The confusion generally comes from how to access components.  For example,
another way to do your test would be to extend the default container and add a
startable interface to it.  Then in the start() method access your two services
via the ServiceManager.  In this case, you wouldn't need to get the container
at all and there would be no run() method:

ExtendedContainer.java:
---------------------------------------------
public class ExtendedContainer
    extends DefaultContainer
    implements Startable {

  public ExtendedContainer() {
  }

  public void start(){
    try {

      ServiceOne s1 = (ServiceOne) m_serviceManager.lookup(ServiceOne.ROLE);
      ServiceTwo s2 = (ServiceTwo) m_serviceManager.lookup(ServiceTwo.ROLE);

      if(getLogger().isInfoEnabled()){
        getLogger().info(s1.getA());
        getLogger().info(s2.getB());
      }

      m_serviceManager.release(s1);
      m_serviceManager.release(s2);

    }
    catch (ServiceException ex) {
      if( getLogger().isErrorEnabled() )
        getLogger().error("error accessing services",ex);
    }
  }

  public void stop(){
    if(getLogger().isInfoEnabled())
      getLogger().info("stopping extended container");
  }

}
--------------------------------------------------------

Your "Main" class would then look like this:
----------------------------------------------
    public static void main( String[] args )
        throws Exception
    {

        String res = "resource://org/apache/avalon/fortress/examples/access";

        // Set up all the preferences for Fortress
        final FortressConfig config = new FortressConfig();

        config.setContainerClass(
          "org.apache.avalon.fortress.examples.access.ExtendedContainer" );
        config.setContainerConfiguration( res+"/ExtendedContainer.xconf" );
        config.setRoleManagerConfiguration( res+"/ExtendedContainer.roles" );


        // Get the root container initialized
        ContainerManager cm = new DefaultContainerManager(config.getContext());
        ContainerUtil.initialize( cm );

        // notice, we don't access the container at all here.

        // Properly clean up when we are done
        org.apache.avalon.framework.container.ContainerUtil.dispose( cm );
    }



> b) Am I mistaken in calling my service a service, should it be called a
> container?
> 

Service is correct.

jaaron

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to