avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/role ServiceMetaManager.java
Date Thu, 15 May 2003 20:13:33 GMT
bloritsch    2003/05/15 13:13:33

  Modified:    fortress/src/java/org/apache/avalon/fortress/impl
                        AbstractContainer.java
               fortress/src/java/org/apache/avalon/fortress/impl/role
                        ServiceMetaManager.java
  Log:
  add initial cut at determining shutdown order.  Now I need to add support for it.
  
  Revision  Changes    Path
  1.26      +50 -13    avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- AbstractContainer.java	8 May 2003 21:24:46 -0000	1.25
  +++ AbstractContainer.java	15 May 2003 20:13:32 -0000	1.26
  @@ -61,11 +61,11 @@
   import org.apache.avalon.fortress.impl.role.FortressRoleManager;
   import org.apache.avalon.fortress.impl.role.Role2MetaInfoManager;
   import org.apache.avalon.fortress.impl.role.ServiceMetaManager;
  -import org.apache.avalon.fortress.impl.factory.ProxyObjectFactory;
   import org.apache.avalon.fortress.impl.factory.ProxyManager;
   import org.apache.avalon.fortress.impl.handler.ComponentFactory;
   import org.apache.avalon.fortress.util.CompositeException;
   import org.apache.avalon.fortress.util.LifecycleExtensionManager;
  +import org.apache.avalon.fortress.util.dag.*;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -86,10 +86,7 @@
   import org.apache.excalibur.mpool.ObjectFactory;
   import org.apache.excalibur.mpool.PoolManager;
   
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.List;
  -import java.util.Map;
  +import java.util.*;
   
   /**
    * This abstract implementation provides basic functionality for building
  @@ -135,6 +132,8 @@
       /** Contains an entry for each ComponentHandler */
       protected List m_components = new ArrayList( 10 );
   
  +    protected List m_shutDownOrder;
  +
       private ProxyManager m_proxyManager = new ProxyManager(true);
   
       /**
  @@ -328,12 +327,12 @@
           }
   
           Iterator it = metaEntry.getRoles();
  +        // create a handler for the combo of Role+MetaData
  +        final ComponentHandler handler =
  +            getComponentHandler( metaEntry, metaData );
  +
           while ( it.hasNext() )
           {
  -            // create a handler for the combo of Role+MetaData
  -            final ComponentHandler handler =
  -                getComponentHandler( metaEntry, metaData );
  -
               final String role = (String) it.next();
   
               // put the role into our role mapper. If the role doesn't exist
  @@ -615,6 +614,8 @@
           final Iterator i = m_components.iterator();
           final BoundedFifoBuffer buffer = new BoundedFifoBuffer( Math.max( m_components.size(),
1 ) );
   
  +        verifyComponents();
  +
           ComponentHandlerEntry entry;
           while ( i.hasNext() )
           {
  @@ -697,16 +698,52 @@
           }
       }
   
  +    private void verifyComponents() throws CyclicDependencyException
  +    {
  +        List verteces = new ArrayList(m_components.size());
  +        Iterator it = m_components.iterator();
  +
  +        while(it.hasNext())
  +        {
  +            ComponentHandlerEntry entry = (ComponentHandlerEntry) it.next();
  +            Vertex v = new Vertex(entry.getHandler());
  +            MetaInfoEntry meta = m_metaManager.getMetaInfoForClassname(entry.getMetaData().getClassname());
  +
  +            Iterator dit = meta.getDependencies().iterator();
  +            while(dit.hasNext())
  +            {
  +                Map deps = (Map)m_mapper.get(dit.next());
  +                Iterator mdit = deps.entrySet().iterator();
  +                while(mdit.hasNext())
  +                {
  +                    Map.Entry depEntry = (Map.Entry)mdit.next();
  +
  +                    if ( ! depEntry.getKey().equals(DEFAULT_ENTRY) ||
  +                         ! depEntry.getKey().equals(SELECTOR_ENTRY))
  +                    {
  +                        v.addDependency(new Vertex(depEntry.getValue()));
  +                    }
  +                }
  +            }
  +
  +            verteces.add(v);
  +        }
  +
  +        DirectedAcyclicGraphVerifier.topologicalSort(verteces);
  +        Collections.reverse(verteces);
  +        m_shutDownOrder = verteces;
  +    }
  +
       /**
        * Disposes of all components and frees resources that they consume.
        */
       public void dispose()
       {
  -        final Iterator i = m_components.iterator();
  +        final Iterator i = m_shutDownOrder.iterator();
           while ( i.hasNext() )
           {
  -            final ComponentHandlerEntry entry = (ComponentHandlerEntry) i.next();
  -            final ComponentHandler handler = entry.getHandler();
  +            final Vertex entry = (Vertex) i.next();
  +            final ComponentHandler handler = (ComponentHandler)entry.getNode();
   
               if ( getLogger().isDebugEnabled() ) getLogger().debug( "Shutting down: " +
handler );
               ContainerUtil.dispose( handler );
  
  
  
  1.5       +1 -3      avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java
  
  Index: ServiceMetaManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServiceMetaManager.java	15 May 2003 18:56:28 -0000	1.4
  +++ ServiceMetaManager.java	15 May 2003 20:13:32 -0000	1.5
  @@ -57,7 +57,6 @@
   import java.io.BufferedReader;
   import java.io.IOException;
   import java.io.InputStreamReader;
  -import java.io.InputStream;
   import java.net.URL;
   import java.util.*;
   
  @@ -216,7 +215,6 @@
       {
           final Properties meta = new Properties();
           final List deps = new ArrayList();
  -        BufferedReader reader = null;
   
           try
           {
  
  
  

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


Mime
View raw message