avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry ServiceRegistry.java
Date Wed, 03 Jul 2002 00:54:43 GMT
mcconnell    2002/07/02 17:54:43

  Modified:    assembly/src/java/org/apache/excalibur/merlin/registry
                        ServiceRegistry.java
  Log:
  improvements to service installation approach and general clenliness of profile management
  
  Revision  Changes    Path
  1.2       +98 -55    jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/ServiceRegistry.java
  
  Index: ServiceRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/ServiceRegistry.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceRegistry.java	1 Jul 2002 04:27:15 -0000	1.1
  +++ ServiceRegistry.java	3 Jul 2002 00:54:43 -0000	1.2
  @@ -48,9 +48,9 @@
       private DefaultRegistry m_registry;
   
      /**
  -    * Component type lists keyed by service designator.
  +    * List of ServiceTable instances.
       */
  -    private Hashtable m_services = new Hashtable();
  +    private List m_services = new LinkedList();
   
      /**
       * Component types keyed by classname.
  @@ -117,7 +117,10 @@
       }
   
      /**
  -    * Install a provider and return the profile.
  +    * Install a provider and return the profile.  The side effect of this operation
  +    * is the resolution of profiles for the runtime application context based on dependecies
  +    * declared by the compoent identified by the classname. 
  +    *
       * @param classname the classname of the provider to install
       * @param name the component profile to use for the provider
       */
  @@ -133,6 +136,8 @@
       */
       public Profile install( Profile profile )
       {
  +        if( m_installed.get( profile.getName() ) != null )
  +          return profile;
           m_installed.put( profile.getName(), profile ); 
           return profile;  
       }
  @@ -147,6 +152,16 @@
       }
   
      /**
  +    * Returns a named profile.
  +    * @return the named profile
  +    */
  +    public Profile getInstalledProfile( String name )
  +    {
  +        return (Profile) m_installed.get( name );
  +    }
  +
  +
  +   /**
       * Returns the set of component types know to the registry.
       * @return the set of component types registered with the registry
       */
  @@ -162,7 +177,7 @@
       */
       public ComponentType[] getComponentTypes( ServiceDesignator service )
       {
  -        return (ComponentType[]) getList( service ).toArray( new ComponentType[0] );
  +        return getTable( service ).getTypes();
       }
   
      /**
  @@ -177,16 +192,47 @@
   
       public Profile[] getProfiles( ServiceDesignator service )
       {
  +        //
  +        // before argregating profiles, make sure that all of the components
  +        // getProfiles() operation has been invoked - which ensures that 
  +        // the type has been properly initialized (yes - it sucks but it works).
  +        //
  +
  +        ServiceTable table = getTable( service );
  +        ComponentType[] types = table.getTypes();
  +        for( int i=0; i<types.length; i++ )
  +        {
  +            try
  +            {
  +                types[i].getProfiles();
  +            }
  +            catch( Throwable e )
  +            {
  +                getLogger().warn("skipping type: " + types[i], e  );
  +            }
  +        }
  +
  +        //
  +        // with the pre-init of profiles complete, we can go ahead and get the 
  +        // set of available profiles in the knowlege that everything is behaving 
  +        // consitently
  +        //
  +
  +        getLogger().debug("getting profiles for service: " + service );
           Vector vector = new Vector();
  -        ComponentType[] components = getComponentTypes( service );
  +        ComponentType[] components = table.getTypes();
  +        getLogger().debug("located table: = " 
  +          + table + ", size: " + ", " + components.length );
           for( int i=0; i<components.length; i++ )
           {
               try
               {
                   Profile[] profiles = components[i].getProfiles();
  +                getLogger().debug("  located provider: " + components[i] + ", profile:
" + profiles.length);
                   for( int j=0; j<profiles.length; j++ )
                   {
                       vector.add( profiles[j] );
  +                    getLogger().debug("    profile: " + profiles[j].getComponentType()
);
                   }
               }
               catch( Throwable e )
  @@ -230,64 +276,28 @@
           }
       }
   
  -    private Selector getSelector( DependencyDescriptor dependency )
  -    {
  -
  -        // if the dependency declares a selector class then use that, 
  -        // otherwise, look for a default service type selector
  -
  -        String selectorName = dependency.getAttribute("avalon.service.selector");
  -        if( selectorName == null )
  -          selectorName = dependency.getService().getClassname() + "Selector";
  -
  -        try
  -        {
  -            Class clazz = m_classloader.loadClass( selectorName );
  -            Selector selector = (Selector) clazz.newInstance();
  -            if( selector instanceof LogEnabled ) 
  -            {
  -                ((LogEnabled)selector).enableLogging( getLogger().getChildLogger("selector")
);
  -            }
  -            return selector;
  -        }
  -        catch( Throwable e )
  -        {
  -            return null;
  -        }
  -    }
  -
  -
       private void register( ServiceDesignator service, ComponentType type )
       {
  -        List list = getList( service );
  -        list.add( type );
  +        ServiceTable table = getTable( service );
  +        table.add( type );
       }
   
  -    private List getList( ServiceDesignator service )
  +    private ServiceTable getTable( ServiceDesignator service )
       {
  -        List list = null;
  -        Iterator iterator = m_services.keySet().iterator();
  +        ServiceTable table = null;
  +        Iterator iterator = m_services.iterator();
           while( iterator.hasNext() )
           {
  -            ServiceDesignator singleton = (ServiceDesignator) iterator.next();
  -            if( singleton.matches( service ) )
  -            {
  -                list = (List) m_services.get( singleton );
  -            }
  -        }
  -        if( list == null ) 
  -        {
  -            getLogger().debug("registering service type: " + service );
  -            list = new LinkedList();
  -            m_services.put( service, list );
  +            table = (ServiceTable) iterator.next();
  +            if( table.matches( service ) )
  +              return table;
           }
  -        return list;
  -    }
   
  -    private String getImplementationKey( ComponentType type )
  -    {
  -        return type.getComponentInfo().getComponentDescriptor().getImplementationKey();
  -    }
  +        // otherwise create a new table
  +        table = new ServiceTable( service, getLogger().getChildLogger("table")  );
  +        m_services.add( table );
  +        return table;
  +    }  
   
      /**
       * Create a new ComponentDefintion instance.
  @@ -321,5 +331,38 @@
               throw new RegistryException( error, e );
           }
       }
  +
  +    private Selector getSelector( DependencyDescriptor dependency )
  +    {
  +
  +        // if the dependency declares a selector class then use that, 
  +        // otherwise, look for a default service type selector
  +
  +        String selectorName = dependency.getAttribute("avalon.service.selector");
  +
  +        if( selectorName == null )
  +          selectorName = dependency.getService().getClassname() + "Selector";
  +
  +        try
  +        {
  +            Class clazz = m_classloader.loadClass( selectorName );
  +            Selector selector = (Selector) clazz.newInstance();
  +            if( selector instanceof LogEnabled ) 
  +            {
  +                ((LogEnabled)selector).enableLogging( getLogger().getChildLogger("selector")
);
  +            }
  +            return selector;
  +        }
  +        catch( Throwable e )
  +        {
  +            return null;
  +        }
  +    }
  +
  +    private String getImplementationKey( ComponentType type )
  +    {
  +        return type.getComponentInfo().getComponentDescriptor().getImplementationKey();
  +    }
  +
   }
   
  
  
  

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


Mime
View raw message