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/08/18 16:40:23 UTC

cvs commit: jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component ComponentHandler.java DefaultComponentFactory.java ExcaliburComponentManager.java ExcaliburComponentSelector.java

leif        2002/08/18 07:40:23

  Modified:    component/src/java/org/apache/avalon/excalibur/component
                        ComponentHandler.java DefaultComponentFactory.java
                        ExcaliburComponentManager.java
                        ExcaliburComponentSelector.java
  Log:
  Refactor the way that Handlers and Instrumentable components are registerd with
  the Instrument Manager.  They are now grouped in a much more logical way.  All
  handlers are registered as children of the component manager.  While components
  them selves are registered as top level instrumentables.  Instrumentables inside
  of selectors are registered as children of the selector.  Nested selectors also
  works correctly.
  
  Revision  Changes    Path
  1.5       +5 -3      jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentHandler.java
  
  Index: ComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ComponentHandler.java	6 Aug 2002 16:28:37 -0000	1.4
  +++ ComponentHandler.java	18 Aug 2002 14:40:22 -0000	1.5
  @@ -101,7 +101,8 @@
        * @param roleManager The current RoleManager.
        * @param loggerManager The current LogKitLoggerManager.
        * @param instrumentManager The current InstrumentManager (May be null).
  -     * @param instrumentableName The name of the handler.
  +     * @param instrumentableName The instrumentable name to assign to
  +     *                           components created by the handler.
        *
        * @throws Exception If there were any problems obtaining a ComponentHandler
        */
  @@ -163,7 +164,8 @@
           }
   
           // Set the instrumentable name of the handler.
  -        ((Instrumentable)handler).setInstrumentableName( instrumentableName );
  +        ((Instrumentable)handler).setInstrumentableName(
  +            ExcaliburComponentManager.INSTRUMENTABLE_NAME + "." + instrumentableName );
   
           return handler;
       }
  
  
  
  1.8       +11 -5     jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/DefaultComponentFactory.java
  
  Index: DefaultComponentFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/DefaultComponentFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultComponentFactory.java	6 Aug 2002 16:28:37 -0000	1.7
  +++ DefaultComponentFactory.java	18 Aug 2002 14:40:22 -0000	1.8
  @@ -132,7 +132,7 @@
        * @param instrumentManager the <code>InstrumentManager</code> to register the component
        *                          with if it is a Instrumentable (May be null).
        * @param instrumentableName The instrument name to assign the component if
  -     *                           it is Initializable.
  +     *                           it is Instrumentable.
        */
       public DefaultComponentFactory( final Class componentClass,
                                       final Configuration configuration,
  @@ -211,6 +211,13 @@
                   }
               }
           }
  +        
  +        // Set the name of the instrumentable before initialization.
  +        if( component instanceof Instrumentable )
  +        {
  +            Instrumentable instrumentable = (Instrumentable)component;
  +            instrumentable.setInstrumentableName( m_instrumentableName );
  +        }
   
           if( ( component instanceof InstrumentManageable ) && ( m_instrumentManager != null ) )
           {
  @@ -268,11 +275,10 @@
               ( (Initializable)component ).initialize();
           }
   
  +        // Register the component as an instrumentable now that it has been initialized.
           if( component instanceof Instrumentable )
           {
  -            Instrumentable instrumentable = (Instrumentable)component;
  -
  -            instrumentable.setInstrumentableName( m_instrumentableName );
  +            // Instrumentable Name is set above.
               if ( m_instrumentManager != null )
               {
                   m_instrumentManager.registerInstrumentable(
  
  
  
  1.13      +31 -9     jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentManager.java
  
  Index: ExcaliburComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentManager.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ExcaliburComponentManager.java	18 Aug 2002 12:06:12 -0000	1.12
  +++ ExcaliburComponentManager.java	18 Aug 2002 14:40:22 -0000	1.13
  @@ -56,6 +56,11 @@
       InstrumentManageable,
       Instrumentable
   {
  +    /** Instrumentable name used to represent the component-manager.
  +     *  Handlers reference this name to register themselves at the correct
  +     *  location under the ECM. */
  +    public static final String INSTRUMENTABLE_NAME = "component-manager"; 
  +        
       /** The parent ComponentLocator */
       private final ComponentManager m_parentManager;
   
  @@ -92,7 +97,7 @@
       private InstrumentManager m_instrumentManager;
   
       /** Instrumentable Name assigned to this Instrumentable */
  -    private String m_instrumentableName = "component-manager";
  +    private String m_instrumentableName = INSTRUMENTABLE_NAME;
   
       /*---------------------------------------------------------------
        * Constructors
  @@ -500,6 +505,16 @@
                   try
                   {
                       handler.initialize();
  +                    
  +                    // Manually register the handler so that it will be located under the
  +                    //  instrument manager, seperate from the actual instrumentable data of the
  +                    //  components
  +                    if ( ( m_instrumentManager != null ) &&
  +                        ( handler instanceof Instrumentable ) )
  +                    {
  +                        String handleInstName = ((Instrumentable)handler).getInstrumentableName();
  +                        m_instrumentManager.registerInstrumentable( handler, handleInstName );
  +                    }
                   }
                   catch( Exception e )
                   {
  @@ -524,6 +539,17 @@
                       try
                       {
                           handler.initialize();
  +                        
  +                        // Manually register the handler so that it will be located under the
  +                        //  instrument manager, seperate from the actual instrumentable data of the
  +                        //  components
  +                        if ( ( m_instrumentManager != null ) &&
  +                            ( handler instanceof Instrumentable ) )
  +                        {
  +                            String handleInstName = 
  +                                ((Instrumentable)handler).getInstrumentableName();
  +                            m_instrumentManager.registerInstrumentable( handler, handleInstName );
  +                        }
                       }
                       catch( Exception e )
                       {
  @@ -650,7 +676,7 @@
        */
       public void setInstrumentableName( String name )
       {
  -        m_instrumentableName = name;
  +        // Ignored.  The ECM name is fixed.
       }
   
       /**
  @@ -690,12 +716,8 @@
        */
       public Instrumentable[] getChildInstrumentables()
       {
  -        // Get the values. This set is created for this call and thus thread safe.
  -        Collection values = m_componentHandlers.values();
  -        Instrumentable[] children = new Instrumentable[ values.size() ];
  -        values.toArray( children );
  -
  -        return children;
  +        // Child instrumentables register themselves as they are discovered.
  +        return EMPTY_INSTRUMENTABLE_ARRAY;
       }
       
       /*---------------------------------------------------------------
  
  
  
  1.13      +16 -10    jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentSelector.java
  
  Index: ExcaliburComponentSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentSelector.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ExcaliburComponentSelector.java	18 Aug 2002 12:06:12 -0000	1.12
  +++ ExcaliburComponentSelector.java	18 Aug 2002 14:40:22 -0000	1.13
  @@ -419,6 +419,16 @@
                   try
                   {
                       handler.initialize();
  +                    
  +                    // Manually register the handler so that it will be located under the
  +                    //  instrument manager, seperate from the actual instrumentable data of the
  +                    //  components
  +                    if ( ( m_instrumentManager != null ) &&
  +                        ( handler instanceof Instrumentable ) )
  +                    {
  +                        String handleInstName = ((Instrumentable)handler).getInstrumentableName();
  +                        m_instrumentManager.registerInstrumentable( handler, handleInstName );
  +                    }
                   }
                   catch( Exception e )
                   {
  @@ -575,12 +585,8 @@
        */
       public Instrumentable[] getChildInstrumentables()
       {
  -        // Get the values. This set is created for this call and thus thread safe.
  -        Collection values = getComponentHandlers().values();
  -        Instrumentable[] children = new Instrumentable[ values.size() ];
  -        values.toArray( children );
  -
  -        return children;
  +        // Child instrumentables register themselves as they are discovered.
  +        return EMPTY_INSTRUMENTABLE_ARRAY;
       }
   
       /*---------------------------------------------------------------
  @@ -624,9 +630,9 @@
           // The instrumentable name will be set by first looking for a name set using
           //  the instrumentable attribute.  If missing, the name attribute is used.
           //  Finally, the name of the configuration element is used.
  -        String instrumentableName =
  -            configuration.getAttribute( "instrumentable",
  -            configuration.getAttribute( "name", configuration.getName() ) );
  +        String instrumentableName = m_instrumentableName + "."
  +            + configuration.getAttribute( "instrumentable",
  +                configuration.getAttribute( "name", configuration.getName() ) );
   
           return ComponentHandler.getComponentHandler( componentClass,
                                                        configuration,
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>