CVS: plexus-container-new/src/java/org/apache/plexus/service/repository ComponentManager.java,1.1,1.2 ComponentRepository.java,1.1,1.2 DefaultComponentRepository.java,1.3,1.4

[email protected] Mon, 12 May 2003 13:57:30 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/service/repository
In directory eng.werken.com:/tmp/cvs-serv16424/src/java/org/apache/plexus/service/repository

Modified Files:
	ComponentManager.java ComponentRepository.java 
	DefaultComponentRepository.java 
Log Message:
o The handling of the lifecycle is now the responsibility of the instance
  manager and not the component repository. The hierarchy may change a little on
  the inside but won't affect usage. When there was only one type of component
  instance this could be dealt with easily from the Component Repository but
  obviously when you get into dealing with different types of instantiation
  strategies the lifecycle must be handled in the entity where the strategy
  resides. I'm sure I'm just discovering what every other container writer
  has discovered along the way.
  
  I found this working on a webapp and I was playing with RunData using a
  poolabel and per-lookup instance manager and after the first lookup the
  component wasn't being run through the lifecycle. So that's been fixed.
  Now the instance manager inside the component manager is responsible
  for this and this will cause a little bit of the internals to be
  shuffled as the component repository still has the method to start
  the lifecycle which it probably doesn't need.




Index: ComponentManager.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/service/repository/ComponentManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ComponentManager.java	1 May 2003 19:35:36 -0000	1.1
+++ ComponentManager.java	12 May 2003 18:57:22 -0000	1.2
@@ -16,13 +16,17 @@
     private InstanceManager instanceManager;
     /** ClassLoader */
     private ClassLoader classLoader;
+    /** Component Repository. */
+    private ComponentRepository componentRespository;
 
     /** Constuctor. */
     public ComponentManager( ComponentDescriptor componentDescriptor,
+                             ComponentRepository componentRepository,
                              ComponentDescriptor instanceManagerDescriptor,
                              ClassLoader classLoader )
     {
         this.componentDescriptor = componentDescriptor;
+        this.componentRespository = componentRepository;
         this.instanceManagerDescriptor = instanceManagerDescriptor;
         this.classLoader = classLoader;
     }
@@ -68,6 +72,24 @@
      *
      * @return
      */
+    public ComponentRepository getComponentRespository()
+    {
+        return componentRespository;
+    }
+
+    /**
+     *
+     * @param componentRespository
+     */
+    public void setComponentRespository( ComponentRepository componentRespository )
+    {
+        this.componentRespository = componentRespository;
+    }
+
+    /**
+     *
+     * @return
+     */
     public ComponentHousing getComponentHousing()
         throws ServiceException
     {
@@ -77,7 +99,7 @@
         }
         catch ( Exception e )
         {
-            throw new ServiceException( e.getMessage(), e );
+            throw new ServiceException( "instance-manager", e.getMessage(), e );
         }
     }
 

Index: ComponentRepository.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/service/repository/ComponentRepository.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ComponentRepository.java	1 May 2003 19:35:36 -0000	1.1
+++ ComponentRepository.java	12 May 2003 18:57:22 -0000	1.2
@@ -37,4 +37,6 @@
     ClassLoader getClassLoader();
 
     void enableLogging( Logger logger );
+
+    void startComponentLifecycle( ComponentHousing housing );
 }

Index: DefaultComponentRepository.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/service/repository/DefaultComponentRepository.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- DefaultComponentRepository.java	10 May 2003 16:39:30 -0000	1.3
+++ DefaultComponentRepository.java	12 May 2003 18:57:22 -0000	1.4
@@ -210,10 +210,13 @@
     ComponentManager instantiateComponentManager( ComponentDescriptor descriptor )
         throws Exception
     {
-        ComponentDescriptor imd = (ComponentDescriptor)
+        ComponentDescriptor instantiationManagerDescriptor = (ComponentDescriptor)
             getComponentDescriptors().get( InstanceManager.ROLE + descriptor.getInstantiationStrategy() );
 
-        ComponentManager componentManager = new ComponentManager( descriptor, imd, getClassLoader() );
+        ComponentManager componentManager = new ComponentManager( descriptor,
+                                                                  this,
+                                                                  instantiationManagerDescriptor,
+                                                                  getClassLoader() );
         componentManager.initialize();
 
         getComponentManagers().put( descriptor.getComponentKey(), componentManager );
@@ -308,9 +311,6 @@
             }
 
             getComponentHousings().put( component, housing );
-
-            // Start the component lifecycle
-            startComponentLifecycle( housing );
         }
         else
         {
@@ -412,10 +412,16 @@
         return getPlexusContainer().getLifecycleHandler();
     }
 
+
+    // I have made the lifecycle handlers public because the instance manager is now responsible for running
+    // a component it deals with through its lifecyle. I was running the component through its lifecycle
+    // in this class but that is not appropriate as we want the instanace manager to control the
+    // component. These are public for now but we need a little restructuring.
+
     /** Start a component's lifecycle.
      *
      */
-    protected void startComponentLifecycle( ComponentHousing housing )
+    public void startComponentLifecycle( ComponentHousing housing )
     {
         try
         {
@@ -432,7 +438,7 @@
     /** End a component's lifecycle.
      *
      */
-    protected void endComponentLifecycle( ComponentHousing housing )
+    public void endComponentLifecycle( ComponentHousing housing )
     {
         try
         {