You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2002/01/14 14:11:38 UTC

cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/autopublishing PublicationInfo.java AutoPublisher.java

hammant     02/01/14 05:11:37

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/transport/autopublishing
                        AutoPublisher.java
  Added:       src/java/org/apache/avalon/cornerstone/blocks/transport/autopublishing
                        PublicationInfo.java
  Log:
  Autopublishing over altrmi that works.
  TODO - don't assume order of blocks
  
  Revision  Changes    Path
  1.3       +100 -72   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AutoPublisher.java	10 Jan 2002 19:12:52 -0000	1.2
  +++ AutoPublisher.java	14 Jan 2002 13:11:37 -0000	1.3
  @@ -3,130 +3,158 @@
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
    * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included  with this distribution in
  + * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    */
   package org.apache.avalon.cornerstone.blocks.transport.autopublishing;
   
  -import org.apache.commons.altrmi.server.AltrmiPublisher;
  -import org.apache.commons.altrmi.server.AltrmiPublicationException;
  -import org.apache.avalon.phoenix.BlockListener;
  -import org.apache.avalon.phoenix.BlockEvent;
  -import org.apache.avalon.phoenix.Block;
  -import org.apache.avalon.phoenix.metainfo.BlockInfo;
  -import org.apache.avalon.phoenix.metainfo.ServiceDescriptor;
  +
  +
  +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.phoenix.BlockEvent;
  +import org.apache.avalon.phoenix.BlockListener;
  +import org.apache.commons.altrmi.server.AltrmiPublisher;
  +import org.apache.commons.altrmi.server.AltrmiPublicationException;
   
  -import java.util.Vector;
   
   /**
    * Class AutoPublisher
    *
  + * This is inprogress.  The order of block being added is not guaranteed.
  + *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
  +
   public class AutoPublisher
  -   implements BlockListener, Configurable
  +   implements Configurable, BlockListener
   {
  -   private AltrmiPublisher mAltrmiPublisher;
  -   private Vector          mServicesToPublish = new Vector();
  -   private Vector          mPublishAsNames    = new Vector();
  +   private String          m_publisherName;
  +   private AltrmiPublisher m_altrmiPublisher;
  +   private Map             m_publications;
  +   private List            m_queue;
   
      /**
  +    * Method configure
       *
       *
  -    *      IN PROGRESS & UNFINISHED - PAUL H
  +    * @param configuration
       *
  +    * @throws ConfigurationException
       *
       */
   
  -
  -   /**
  -    * Pass the <code>Configuration</code> to the <code>Configurable</code>
  -    * class. This method must always be called after the constructor
  -    * and before any other method.
  -    *
  -    * @param configuration the class configurations.
  -    */
      public void configure (final Configuration configuration)
         throws ConfigurationException
      {
  -      System.out.println("AutoPublisher.configure() called!");
  +      m_publisherName =
  +         configuration.getChild("publisher").getValue("altrmification");
  +      m_publications  = new HashMap();
   
  -      Configuration[] publications =
  -         configuration.getChildren("publications");
  +      final Configuration[] confs = configuration.getChildren("publish");
   
  -      for (int i = 0; i < publications.length; i++)
  +      for (int i = 0; i < confs.length; i++)
         {
  -         Configuration publication = publications [i];
  -
  -         System.out.println("publications " + publication);
  +         final Configuration conf               = confs [i];
  +         final String        blockName          = conf.getAttribute("block");
  +         final String        publishAsName      =
  +            conf.getAttribute("publishAsName");
  +         final String        interfaceToPublish =
  +            conf.getAttribute("interfaceToPublish");
  +
  +         m_publications.put(blockName,
  +                            new PublicationInfo(publishAsName,
  +                                                interfaceToPublish));
         }
  +
  +      m_queue = new ArrayList();
      }
   
      /**
  -    * Notification that a block has just been added
  -    * to Server Application.
  +    * Method blockAdded
  +    *
  +    *
  +    * @param event
       *
  -    * @param event the BlockEvent
       */
   
      public void blockAdded (final BlockEvent event)
      {
  -      try
  +      System.out.println("Block " + event.getName() + " added");
  +
  +      if (m_publisherName.equals(event.getName()))
         {
  -         if (mServicesToPublish.contains(event.getName()))
  -         {
  -            int                 ix         =
  -               mServicesToPublish.indexOf(event.getName());
  -            Block               block      = event.getBlock();
  -            BlockInfo           bi         = event.getBlockInfo();
  -            ServiceDescriptor[] sd         = bi.getServices();
  -            Vector              classNames = new Vector();
  -
  -            for (int i = 0; i < sd.length; i++)
  -            {
  -               ServiceDescriptor descriptor = sd [i];
  -               Class             clazz      =
  -                  Class.forName(descriptor.getName());
  -
  -               classNames.add(clazz);
  -            }
  -
  -            Class[] classes = new Class [classNames.size()];
  -
  -            classNames.copyInto(classes);
  -            //mAltrmiPublisher.publish(block,
  -            //                         ( String ) mPublishAsNames.elementAt(ix),
  -            //                         classes);
  -         }
  +         m_altrmiPublisher = ( AltrmiPublisher ) event.getBlock();
         }
  -      catch (ClassNotFoundException cnfe)
  +
  +      if (m_publications.containsKey(event.getName()))
         {
  -         cnfe.printStackTrace();
  +         final Block     block     = event.getBlock();
  +         final String    blockName = event.getName();
  +         PublicationInfo pi        =
  +            ( PublicationInfo ) m_publications.get(event.getName());
   
  -         // TODO ?
  +         try
  +         {
  +            m_altrmiPublisher.publish(
  +               block, pi.getPublishAsName(),
  +               Class.forName(pi.getInterfaceToPublish()));
  +         }
  +         catch (AltrmiPublicationException e)
  +         {
  +            throw new CascadingRuntimeException(
  +               "Some problem auto-publishing", e);
  +         }
  +         catch (ClassNotFoundException e)
  +         {
  +            throw new CascadingRuntimeException(
  +               "Interface specifies in config.xml ('interfaceToPublish' attribte) not found",
  +               e);
  +         }
         }
  -      //catch (AltrmiPublicationException ape)
  -      //{
  -      //   ape.printStackTrace();
  -      //
  -      //   // TODO ?
  -      //}
      }
   
      /**
  -    * Notification that a block is just about to be
  -    * removed from Server Application.
  +    * Method blockRemoved
  +    *
  +    *
  +    * @param event
       *
  -    * @param event the BlockEvent
       */
   
      public void blockRemoved (final BlockEvent event)
      {
  -      System.out.println("Removed block '" + event.getName() + "'");
  +      System.out.println("Block " + event.getName() + " removed");
  +
  +      if (m_publications.containsKey(event.getName()))
  +      {
  +         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 (AltrmiPublicationException e)
  +         {
  +            throw new CascadingRuntimeException(
  +               "Some problem un-auto-publishing", e);
  +         }
  +      }
      }
   }
  +
  +
  +/*------ Formatted by Jindent 3.24 Basic 1.0 --- http://www.jindent.de ------*/
  
  
  
  1.1                  jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/autopublishing/PublicationInfo.java
  
  Index: PublicationInfo.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.cornerstone.blocks.transport.autopublishing;
  
  
  
  public class PublicationInfo
  {
     private final String mPublishAsName;
     private final String mInterfaceToPublish;
  
     public PublicationInfo (String publishAsName, String interfaceToPublish)
     {
        mPublishAsName      = publishAsName;
        mInterfaceToPublish = interfaceToPublish;
     }
  
     public String getPublishAsName ()
     {
        return mPublishAsName;
     }
  
     public String getInterfaceToPublish ()
     {
        return mInterfaceToPublish;
     }
  }
  
  
  /*------ Formatted by Jindent 3.24 Basic 1.0 --- http://www.jindent.de ------*/
  
  
  

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