avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing AbstractPublisher.java
Date Sat, 26 Jan 2002 14:26:29 GMT
hammant     02/01/26 06:26:28

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/transport/autopublishing
                        AutoPublisher.java
               src/java/org/apache/avalon/cornerstone/blocks/transport/publishing
                        AbstractPublisher.java
  Log:
  autopublisher uses application listener now.
  
  Revision  Changes    Path
  1.6       +90 -35    jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/autopublishing/AutoPublisher.java
  
  Index: AutoPublisher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/autopublishing/AutoPublisher.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AutoPublisher.java	21 Jan 2002 15:48:08 -0000	1.5
  +++ AutoPublisher.java	26 Jan 2002 14:26:28 -0000	1.6
  @@ -10,39 +10,38 @@
   
   
   
  -import java.util.ArrayList;
  -import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.List;
  -import java.util.Map;
  -
  -import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.phoenix.Block;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.CascadingRuntimeException;
  +import org.apache.avalon.phoenix.ApplicationListener;
   import org.apache.avalon.phoenix.BlockEvent;
  -import org.apache.avalon.phoenix.BlockListener;
  +import org.apache.avalon.phoenix.Block;
  +import org.apache.avalon.phoenix.ApplicationEvent;
   import org.apache.commons.altrmi.server.AltrmiPublisher;
   import org.apache.commons.altrmi.server.PublicationException;
   
  +import java.util.Map;
  +import java.util.HashMap;
  +import java.util.Vector;
  +
   
   /**
    * Class AutoPublisher
    *
  - * This is inprogress.  The order of block being added is not guaranteed.
  + * Publishes so configured services automatically after block start().
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
  -public class AutoPublisher implements Configurable, BlockListener
  +public class AutoPublisher implements Configurable, ApplicationListener
   {
   
       private String m_publisherName;
       private AltrmiPublisher m_altrmiPublisher;
       private Map m_publications;
  -    private List m_queue;
  +    private Vector m_events = new Vector();
   
       /**
        * Method configure
  @@ -70,8 +69,6 @@
   
               m_publications.put(blockName, new PublicationInfo(publishAsName, interfaceToPublish));
           }
  -
  -        m_queue = new ArrayList();
       }
   
       /**
  @@ -84,8 +81,6 @@
       public void blockAdded(final BlockEvent event)
       {
   
  -        System.out.println("Block " + event.getName() + " added");
  -
           if (m_publisherName.equals(event.getName()))
           {
               m_altrmiPublisher = (AltrmiPublisher) event.getBlock();
  @@ -93,6 +88,45 @@
   
           if (m_publications.containsKey(event.getName()))
           {
  +            m_events.add(event);
  +        }
  +    }
  +
  +    /**
  +     * Method blockRemoved
  +     *
  +     *
  +     * @param event
  +     *
  +     */
  +    public void blockRemoved(final BlockEvent event)
  +    {
  +    }
  +
  +    /**
  +     * Method applicationStarting
  +     *
  +     *
  +     * @param event
  +     *
  +     * @throws Exception
  +     *
  +     */
  +    public void applicationStarting(ApplicationEvent event) throws Exception
  +    {
  +    }
  +
  +    /**
  +     * Method applicationStarted
  +     *
  +     *
  +     */
  +    public void applicationStarted()
  +    {
  +
  +        for (int i = 0; i < m_events.size(); i++)
  +        {
  +            final BlockEvent event = (BlockEvent) m_events.elementAt(i);
               final Block block = event.getBlock();
               final String blockName = event.getName();
               PublicationInfo pi = (PublicationInfo) m_publications.get(event.getName());
  @@ -109,38 +143,59 @@
               catch (ClassNotFoundException e)
               {
                   throw new CascadingRuntimeException(
  -                    "Interface specifies in config.xml ('interfaceToPublish' attribte)
not found",
  +                    "Interface specified in config.xml ('interfaceToPublish' attribte)
not found",
                       e);
               }
           }
       }
   
       /**
  -     * Method blockRemoved
  +     * Method applicationStopping
        *
        *
  -     * @param event
  -     *
        */
  -    public void blockRemoved(final BlockEvent event)
  +    public void applicationStopping()
       {
   
  -        System.out.println("Block " + event.getName() + " removed");
  -
  -        if (m_publications.containsKey(event.getName()))
  +        for (int i = 0; i < m_events.size(); i++)
           {
  -            final Block block = event.getBlock();
  -            final String blockName = event.getName();
  -            PublicationInfo pi = (PublicationInfo) m_publications.get(event.getName());
  +            BlockEvent event = (BlockEvent) m_events.elementAt(i);
   
  -            try
  +            if (m_publications.containsKey(event.getName()))
               {
  -                m_altrmiPublisher.unPublish(block, pi.getPublishAsName());
  -            }
  -            catch (PublicationException e)
  -            {
  -                throw new CascadingRuntimeException("Some problem un-auto-publishing",
e);
  +                final Block block = event.getBlock();
  +                final String blockName = event.getName();
  +                PublicationInfo pi = (PublicationInfo) m_publications.get(event.getName());
  +
  +                try
  +                {
  +                    m_altrmiPublisher.unPublish(block, pi.getPublishAsName());
  +                }
  +                catch (PublicationException e)
  +                {
  +                    throw new CascadingRuntimeException("Some problem un-auto-publishing",
e);
  +                }
               }
           }
  +    }
  +
  +    /**
  +     * Method applicationStopped
  +     *
  +     *
  +     */
  +    public void applicationStopped()
  +    {
  +    }
  +
  +    /**
  +     * Method applicationFailure
  +     *
  +     *
  +     * @param e
  +     *
  +     */
  +    public void applicationFailure(Exception e)
  +    {
       }
   }
  
  
  
  1.8       +33 -14    jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing/AbstractPublisher.java
  
  Index: AbstractPublisher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing/AbstractPublisher.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractPublisher.java	26 Jan 2002 08:30:47 -0000	1.7
  +++ AbstractPublisher.java	26 Jan 2002 14:26:28 -0000	1.8
  @@ -26,13 +26,18 @@
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.phoenix.Block;
  +import org.apache.avalon.phoenix.BlockContext;
   import org.apache.avalon.cornerstone.services.sockets.SocketManager;
   
   import java.util.StringTokenizer;
   import java.util.Vector;
   
   import java.net.MalformedURLException;
  +import java.io.File;
  +import java.net.URL;
   
   
   /**
  @@ -40,15 +45,17 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public abstract class AbstractPublisher extends AbstractLogEnabled
  -        implements AltrmiPublisher, Startable, Composable, Configurable, Initializable,
Block
  +        implements AltrmiPublisher, Startable, Composable, Contextualizable,
  +                   Configurable, Initializable, Block
   {
   
       protected AltrmiServer m_AltrmiServer;
       private ClassRetriever m_ClassRetriever;
       protected AltrmiAuthenticator m_AltrmiAuthenticator;
  +    protected File mBaseDirectory;
   
       /**
        * Pass the <code>Configuration</code> to the <code>Configurable</code>
  @@ -71,21 +78,22 @@
   
               while (st.hasMoreTokens())
               {
  -                vector.add(st.nextToken());
  +                try {
  +                    String url = st.nextToken();
  +                    if (url.startsWith("./")) {
  +                        File file = new File(mBaseDirectory, url.substring(2,url.length()));
  +                        vector.add(file.toURL());
  +                    } else {
  +                         vector.add(new URL(url));
  +                    }
  +                } catch (MalformedURLException e) {
  +                    getLogger().debug("Can't create URL from config element 'gerneratedClassJarURLs'",e);
  +                }
               }
   
  -            String[] urls = new String[vector.size()];
  -
  +            URL[] urls = new URL[vector.size()];
               vector.copyInto(urls);
  -
  -            try
  -            {
  -                m_ClassRetriever = new JarFileClassRetriever(urls);
  -            }
  -            catch (MalformedURLException mufe)
  -            {
  -                throw new ConfigurationException("URL Invalid", mufe);
  -            }
  +            m_ClassRetriever = new JarFileClassRetriever(urls);
           }
           else if (classRetrieverType.equals("none"))
           {
  @@ -96,6 +104,17 @@
               throw new ConfigurationException(
                   "classRetrieverType must be 'baseMobileClass', 'jarFile' or 'none'");
           }
  +    }
  +
  +    /**
  +     * Method contextualize
  +     *
  +     *
  +     * @param mContext
  +     *
  +     */
  +    public void contextualize(final Context context) {
  +        mBaseDirectory = ((BlockContext) context).getBaseDirectory();
       }
   
       /**
  
  
  

--
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