ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test DefaultTypeManagerTestCase.java
Date Thu, 23 May 2002 04:26:26 GMT
adammurdoch    02/05/22 21:26:26

  Modified:    container/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java
               container/src/java/org/apache/myrmidon/components/type
                        DefaultTypeManager.java
               container/src/java/org/apache/myrmidon/components/workspace
                        DefaultWorkspace.java
               container/src/java/org/apache/myrmidon/interfaces/deployer
                        Deployer.java
               container/src/java/org/apache/myrmidon/interfaces/type
                        TypeManager.java
               container/src/test/org/apache/myrmidon/components/type/test
                        DefaultTypeManagerTestCase.java
  Added:       container/src/java/org/apache/myrmidon/interfaces/service
                        ScopedService.java
  Log:
  * Added ScopedService interface, which is used to create children of
    scoped services when setting up a partitioned execution frame.
  
  * Removed TypeManager.createChildTypeManager() and Deployer.createChildDeployer().
  
  * Changed DefaultTypeManager and DefaultDeployer to implement ScopedService.
  
  * Handle ScopedService in DefaultWorkspace.createExecutionFrame(), for now.
  
  Revision  Changes    Path
  1.44      +5 -8      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- DefaultDeployer.java	23 May 2002 01:50:25 -0000	1.43
  +++ DefaultDeployer.java	23 May 2002 04:26:26 -0000	1.44
  @@ -21,17 +21,18 @@
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
   import org.apache.myrmidon.interfaces.library.Library;
   import org.apache.myrmidon.interfaces.role.RoleRegistry;
  +import org.apache.myrmidon.interfaces.service.ScopedService;
   
   /**
    * This class deploys roles, types and services from a typelib.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.43 $ $Date: 2002/05/23 01:50:25 $
  + * @version $Revision: 1.44 $ $Date: 2002/05/23 04:26:26 $
    */
   public class DefaultDeployer
       extends AbstractLogEnabled
  -    implements Deployer, Serviceable
  +    implements Deployer, ScopedService, Serviceable
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultDeployer.class );
  @@ -66,13 +67,9 @@
       /**
        * Creates a child deployer.
        */
  -    public Deployer createChildDeployer( final ServiceManager serviceManager )
  -        throws ServiceException
  +    public Object createChildService() throws Exception
       {
  -        final DefaultDeployer child = new DefaultDeployer();
  -        ContainerUtil.enableLogging( child, getLogger() );
  -        ContainerUtil.service( child, serviceManager );
  -        return child;
  +        return new DefaultDeployer();
       }
   
       /**
  
  
  
  1.24      +13 -7     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java
  
  Index: DefaultTypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- DefaultTypeManager.java	23 May 2002 01:50:25 -0000	1.23
  +++ DefaultTypeManager.java	23 May 2002 04:26:26 -0000	1.24
  @@ -18,16 +18,17 @@
   import org.apache.myrmidon.interfaces.type.TypeException;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  +import org.apache.myrmidon.interfaces.service.ScopedService;
   
   /**
    * The interface that is used to manage types.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.23 $ $Date: 2002/05/23 01:50:25 $
  + * @version $Revision: 1.24 $ $Date: 2002/05/23 04:26:26 $
    */
   public class DefaultTypeManager
  -    implements TypeManager, Serviceable
  +    implements TypeManager, Serviceable, ScopedService
   {
       private static final Resources REZ
           = ResourceManager.getPackageResources( DefaultTypeManager.class );
  @@ -64,11 +65,16 @@
       public void service( final ServiceManager serviceManager )
           throws ServiceException
       {
  -        m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE );
  +        // TODO - probably should always use the role manager from the current
  +        // scope, rather than the parent's.  Need to fix createFactory() to
  +        // deal with the fact that the role name might be different in parent.
  +        // Better yet, change lookup from role name to a Class object.
  +        if( m_roleManager == null )
  +        {
  +            m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE );
  +        }
       }
   
  -
  -
       /**
        * @see TypeManager#registerTypes( String, TypeFactory )
        */
  @@ -124,9 +130,9 @@
       }
   
       /**
  -     * @see TypeManager#createChildTypeManager()
  +     * Creates a child of this service.
        */
  -    public TypeManager createChildTypeManager()
  +    public Object createChildService() throws Exception
       {
           return new DefaultTypeManager( this );
       }
  
  
  
  1.67      +67 -15    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  
  Index: DefaultWorkspace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- DefaultWorkspace.java	21 May 2002 07:57:13 -0000	1.66
  +++ DefaultWorkspace.java	23 May 2002 04:26:26 -0000	1.67
  @@ -8,11 +8,16 @@
   package org.apache.myrmidon.components.workspace;
   
   import java.util.HashMap;
  +import java.util.Map;
  +import java.util.Collection;
  +import java.util.Iterator;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  @@ -23,6 +28,7 @@
   import org.apache.myrmidon.interfaces.oldmodel.Project;
   import org.apache.myrmidon.interfaces.oldmodel.ProjectRef;
   import org.apache.myrmidon.interfaces.oldmodel.Target;
  +import org.apache.myrmidon.interfaces.service.ScopedService;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
   
  @@ -30,7 +36,7 @@
    * This is the default implementation of Workspace.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.66 $ $Date: 2002/05/21 07:57:13 $
  + * @version $Revision: 1.67 $ $Date: 2002/05/23 04:26:26 $
    * @todo Merge m_entries and m_projects
    */
   public class DefaultWorkspace
  @@ -75,27 +81,21 @@
                                                    final ExecutionFrame frame )
           throws Exception
       {
  -        // TODO - move all this stuff to ExecutionFrame.createChildFrame( ..., true ).
  +        // TODO - move all this stuff to a customised ServiceManager, and call
  +        // from ExecutionFrame.createChildFrame( ..., true ).
   
           final DefaultServiceManager serviceManager =
               new DefaultServiceManager( frame.getServiceManager() );
   
  -        final TypeManager parentTypeManager =
  -            (TypeManager)serviceManager.lookup( TypeManager.ROLE );
  -        //Add in child type manager so each frame can register different
  -        //sets of tasks etc
  -        final TypeManager typeManager = parentTypeManager.createChildTypeManager();
  -        serviceManager.put( TypeManager.ROLE, typeManager );
  +        // Add child services, for the scoped services.
  +        final Map scopedServices = new HashMap();
  +        addChildService( TypeManager.ROLE, serviceManager, scopedServices );
  +        addChildService( Deployer.ROLE, serviceManager, scopedServices );
  +        setupServices( scopedServices.values(), serviceManager );
   
           // TODO - Add child role manager and configurer
   
  -        //We need to create a new deployer so that it deploys
  -        //to project specific TypeManager
  -        final Deployer parentDeployer =
  -            (Deployer)frame.getServiceManager().lookup( Deployer.ROLE );
  -        final Deployer deployer =
  -            parentDeployer.createChildDeployer( serviceManager );
  -        serviceManager.put( Deployer.ROLE, deployer );
  +        // TODO - we never dispose of these services.  That's bad
   
           //We need to place projects and ProjectManager
           //in ServiceManager so as to support project-local call()
  @@ -107,6 +107,58 @@
                                          project.getBaseDirectory(),
                                          serviceManager,
                                          true );
  +    }
  +
  +    /**
  +     * Initialises a set of services
  +     * @param services The services
  +     */
  +    private void setupServices( final Collection services,
  +                                final ServiceManager serviceManager )
  +        throws Exception
  +    {
  +        for( Iterator iterator = services.iterator(); iterator.hasNext(); )
  +        {
  +            final Object object = iterator.next();
  +            ContainerUtil.enableLogging( object, getLogger() );
  +            // TODO - need to contextualise services
  +            //ContainerUtil.contextualize( object, m_context );
  +            ContainerUtil.service( object, serviceManager );
  +            ContainerUtil.initialize( object );
  +        }
  +    }
  +
  +    /**
  +     * Creates a child service for a service, if the specified service is a
  +     * scoped service.
  +     * @param role The service to create a child for.
  +     * @param serviceManager The service manager to add the child to.
  +     * @param scopedServices A map tracking the services for which a child
  +     *        service has already been created.  This is to deal with service
  +     *        object which provide more than one service.
  +     */
  +    private void addChildService( final String role,
  +                                  final DefaultServiceManager serviceManager,
  +                                  final Map scopedServices ) throws Exception
  +    {
  +        // Lookup the service, and skip it if it is not a scoped service
  +        final Object service = serviceManager.lookup( role );
  +        if( !( service instanceof ScopedService ) )
  +        {
  +            return;
  +        }
  +
  +        // Check if a child has already been created for the service, and
  +        // use that instead of creating a new one.  Otherwise create the child.
  +        Object childService = scopedServices.get( service );
  +        if( childService == null )
  +        {
  +            childService = ( (ScopedService)service ).createChildService();
  +            scopedServices.put( service, childService );
  +        }
  +
  +        // Add child to the service manager
  +        serviceManager.put( role, childService );
       }
   
       private ProjectEntry getProjectEntry( final Project project,
  
  
  
  1.13      +1 -10     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/deployer/Deployer.java
  
  Index: Deployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/deployer/Deployer.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Deployer.java	23 May 2002 01:50:26 -0000	1.12
  +++ Deployer.java	23 May 2002 04:26:26 -0000	1.13
  @@ -16,7 +16,7 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.12 $ $Date: 2002/05/23 01:50:26 $
  + * @version $Revision: 1.13 $ $Date: 2002/05/23 04:26:26 $
    */
   public interface Deployer
   {
  @@ -34,13 +34,4 @@
        */
       TypeLibraryDeployer createDeployer( Library library, String namespace )
           throws DeploymentException;
  -
  -    /**
  -     * Creates a deployer which is a child of this deployer.
  -     * @param componentManager the ServiceManager for the child deployer to use.
  -     * @return a child deployer.
  -     * @throws ServiceException if an error occurs.
  -     */
  -    Deployer createChildDeployer( ServiceManager componentManager )
  -        throws ServiceException;
   }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/service/ScopedService.java
  
  Index: ScopedService.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.myrmidon.interfaces.service;
  
  /**
   * A lifecycle interface which is used to create child services of scoped
   * services.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/23 04:26:26 $
   */
  public interface ScopedService
  {
      /**
       * Creates an uninitialised child of this service.  The caller of this
       * method (ie the container) is responsible for managing the lifecycle
       * of the child service.  That is, the caller must initialise the child
       * service (ie service, contextualise, initialise, etc the child) and to
       * dispose of the child service.  The caller must also ensure that all
       * child services are disposed before the parent service is disposed.
       */
      Object createChildService() throws Exception;
  }
  
  
  
  1.13      +1 -9      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeManager.java
  
  Index: TypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeManager.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TypeManager.java	10 May 2002 01:44:48 -0000	1.12
  +++ TypeManager.java	23 May 2002 04:26:26 -0000	1.13
  @@ -12,7 +12,7 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.12 $ $Date: 2002/05/10 01:44:48 $
  + * @version $Revision: 1.13 $ $Date: 2002/05/23 04:26:26 $
    */
   public interface TypeManager
   {
  @@ -77,12 +77,4 @@
        */
       TypeFactory getFactory( String roleName )
           throws TypeException;
  -
  -    /**
  -     * Creates a child type manager.  The child inherits the type factories
  -     * from this type manager.  Additional type factories may be added to the
  -     * child, without affecting this type manager.
  -     * @return A TypeManager with this as it's parent.
  -     */
  -    TypeManager createChildTypeManager();
   }
  
  
  
  1.5       +4 -3      jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test/DefaultTypeManagerTestCase.java
  
  Index: DefaultTypeManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test/DefaultTypeManagerTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultTypeManagerTestCase.java	22 May 2002 07:36:23 -0000	1.4
  +++ DefaultTypeManagerTestCase.java	23 May 2002 04:26:26 -0000	1.5
  @@ -20,7 +20,7 @@
    * Test cases for the DefaultTypeManager
    *
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.4 $ $Date: 2002/05/22 07:36:23 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/23 04:26:26 $
    */
   public class DefaultTypeManagerTestCase
       extends AbstractComponentTest
  @@ -400,9 +400,10 @@
           }
       }
   
  -    private DefaultTypeManager createChild( DefaultTypeManager parent )
  +    private DefaultTypeManager createChild( final DefaultTypeManager parent )
  +        throws Exception
       {
  -        return (DefaultTypeManager)parent.createChildTypeManager();
  +        return (DefaultTypeManager)parent.createChildService();
       }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message