You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by as...@apache.org on 2002/02/20 06:30:51 UTC

cvs commit: jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/behavior IXMLRPCConstants.java ILateralCacheXMLRPCListener.java

asmuts      02/02/19 21:30:51

  Added:       src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/utils
                        XMLRPCSocketOpener.java
               src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc
                        LateralXMLRPCService.java LateralXMLRPCSender.java
                        LateralXMLRPCReceiverConnection.java
                        LateralXMLRPCReceiver.java
                        LateralGroupCacheXMLRPCListener.java
                        LateralCacheXMLRPCListener.java
               src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/behavior
                        IXMLRPCConstants.java
                        ILateralCacheXMLRPCListener.java
  Log:
  getting some code around a possbile xml-rpc lateral
  doesn't work yet
  need to convert Led to some other type for argument?
  
  lateral cache framework needs some refactoring,  the lateral caches
  are hard coded in the LateralCacheManger.  This should be more dynamic or the individual laterals should be more independent.  Also, the lateralCacheAtributes has variable for all types.  This is ugly too.
  
  The lateral cache was never the highest priority.
  
  xml-rpc familiar folk can build apon this, change the led method type to a method name, etc.
  
  Add startup testing of the webserver, make sure it is not intialized more than once, etc.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/utils/XMLRPCSocketOpener.java
  
  Index: XMLRPCSocketOpener.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.utils;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import java.io.IOException;
  import java.io.InterruptedIOException;
  import org.apache.xmlrpc.XmlRpcClientLite;
  import org.apache.xmlrpc.XmlRpcClient;
  
  /**
   * Socket openere that will timeout on the initial connect rather than block
   * forever. Technique from core java II.
   *
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @created January 15, 2002
   * @version $Id: XMLRPCSocketOpener.java,v 1.1 2002/02/20 05:30:51 asmuts Exp $
   */
  public class XMLRPCSocketOpener implements Runnable
  {
  
      private String host;
      private int port;
      //private Socket socket;
      private XmlRpcClientLite xmlrpc;
  
      /** Constructor for the SocketOpener object */
      public static XmlRpcClientLite openSocket( String host, int port, int timeOut )
      {
          XMLRPCSocketOpener opener = new XMLRPCSocketOpener( host, port );
          Thread t = new Thread( opener );
          t.start();
          try
          {
              t.join( timeOut );
          }
          catch ( InterruptedException ire )
          {
  
          }
          return opener.getSocket();
      }
  
  
      /**
       * Constructor for the SocketOpener object
       *
       * @param host
       * @param port
       */
      public XMLRPCSocketOpener( String host, int port )
      {
          this.xmlrpc = null;
          this.host = host;
          this.port = port;
      }
  
  
      /** Main processing method for the SocketOpener object */
      public void run()
      {
          try
          {
              //socket = new Socket( host, port );
              xmlrpc = new XmlRpcClientLite ( "http://" + host + ":" + port + "/RPC2" );
          }
          catch ( IOException ioe )
          {
          }
      }
  
      /** Gets the socket attribute of the SocketOpener object */
      public XmlRpcClientLite getSocket()
      {
          return xmlrpc;
      }
  }
  
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCService.java
  
  Index: LateralXMLRPCService.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import java.io.*;
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.IOException;
  import java.io.Reader;
  import java.io.Serializable;
  
  import org.apache.stratum.jcs.auxiliary.lateral.LateralCacheAttributes;
  import org.apache.stratum.jcs.auxiliary.lateral.LateralCacheInfo;
  import org.apache.stratum.jcs.auxiliary.lateral.LateralElementDescriptor;
  
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheObserver;
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheService;
  
  import org.apache.stratum.jcs.engine.CacheElement;
  
  import org.apache.stratum.jcs.engine.behavior.ICacheElement;
  import org.apache.stratum.jcs.engine.behavior.ICacheListener;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  /**
   * A lateral cache service implementation.
   *
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @created February 19, 2002
   * @version $Id: LateralXMLRPCService.java,v 1.8 2002/02/17 07:16:24 asmuts Exp
   *      $
   */
  public class LateralXMLRPCService
       implements ILateralCacheService, ILateralCacheObserver
  {
      private final static Log log =
          LogSource.getInstance( LateralXMLRPCService.class );
  
      private ILateralCacheAttributes ilca;
      private LateralXMLRPCSender sender;
  
      /**
       * Constructor for the LateralXMLRPCService object
       *
       * @param lca
       * @exception IOException
       */
      public LateralXMLRPCService( ILateralCacheAttributes lca )
          throws IOException
      {
          this.ilca = lca;
          try
          {
              log.debug( "creating sender" );
  
              sender = new LateralXMLRPCSender( lca );
  
              log.debug( "created sender" );
          }
          catch ( IOException e )
          {
              //log.error( "Could not create sender", e );
              // This gets thrown over and over in recovery mode.
              // The stack trace isn't useful here.
              log.error( "Could not create sender to [" + lca.getTcpServer() + "] -- " + e.getMessage() );
  
              throw e;
          }
      }
  
      // -------------------------------------------------------- Service Methods
  
      /**
       * @param item
       * @exception IOException
       */
      public void update( ICacheElement item )
          throws IOException
      {
          update( item, LateralCacheInfo.listenerId );
      }
  
      /**
       * @param item
       * @param requesterId
       * @exception IOException
       */
      public void update( ICacheElement item, byte requesterId )
          throws IOException
      {
          LateralElementDescriptor led = new LateralElementDescriptor( item );
          led.requesterId = requesterId;
          led.command = led.UPDATE;
          sender.send( led );
      }
  
      /**
       * @param cacheName
       * @param key
       * @exception IOException
       */
      public void remove( String cacheName, Serializable key )
          throws IOException
      {
          remove( cacheName, key, LateralCacheInfo.listenerId );
      }
  
      /**
       * @param cacheName
       * @param key
       * @param requesterId
       * @exception IOException
       */
      public void remove( String cacheName, Serializable key, byte requesterId )
          throws IOException
      {
          CacheElement ce = new CacheElement( cacheName, key, null );
          LateralElementDescriptor led = new LateralElementDescriptor( ce );
          led.requesterId = requesterId;
          led.command = led.REMOVE;
          sender.send( led );
      }
  
      /**
       * @exception IOException
       */
      public void release()
          throws IOException
      {
          // nothing needs to be done
      }
  
      /**
       * Will close the connection.
       *
       * @param cache
       * @exception IOException
       */
      public void dispose( String cache )
          throws IOException
      {
          sender.dispose( cache );
      }
  
      /**
       * @return
       * @param key
       * @exception IOException
       */
      public Serializable get( String key )
          throws IOException
      {
          //p( "junk get" );
          //return get( cattr.cacheName, key, true );
          return null;
          // nothing needs to be done
      }
  
      /**
       * @return
       * @param cacheName
       * @param key
       * @exception IOException
       */
      public Serializable get( String cacheName, Serializable key )
          throws IOException
      {
          //p( "get(cacheName,key)" );
          return get( cacheName, key, true );
          // nothing needs to be done
      }
  
      /**
       * An expiremental get implementation. By default it should be off.
       *
       * @return
       * @param cacheName
       * @param key
       * @param container
       * @exception IOException
       */
      public Serializable get( String cacheName, Serializable key, boolean container )
          throws IOException
      {
          //p( "get(cacheName,key,container)" );
          CacheElement ce = new CacheElement( cacheName, key, null );
          LateralElementDescriptor led = new LateralElementDescriptor( ce );
          //led.requesterId = requesterId; // later
          led.command = led.GET;
          return sender.sendAndReceive( led );
          //return null;
          // nothing needs to be done
      }
  
      /**
       * @param cacheName
       * @exception IOException
       */
      public void removeAll( String cacheName )
          throws IOException
      {
          removeAll( cacheName, LateralCacheInfo.listenerId );
      }
  
      /**
       * @param cacheName
       * @param requesterId
       * @exception IOException
       */
      public void removeAll( String cacheName, byte requesterId )
          throws IOException
      {
          CacheElement ce = new CacheElement( cacheName, "ALL", null );
          LateralElementDescriptor led = new LateralElementDescriptor( ce );
          led.requesterId = requesterId;
          led.command = led.REMOVEALL;
          sender.send( led );
      }
  
      /**
       * @param args
       */
      public static void main( String args[] )
      {
          try
          {
              LateralXMLRPCSender sender =
                  new LateralXMLRPCSender( new LateralCacheAttributes() );
  
              // process user input till done
              boolean notDone = true;
              String message = null;
              // wait to dispose
              BufferedReader br =
                  new BufferedReader( new InputStreamReader( System.in ) );
  
              while ( notDone )
              {
                  System.out.println( "enter mesage:" );
                  message = br.readLine();
                  CacheElement ce = new CacheElement( "test", "test", message );
                  LateralElementDescriptor led = new LateralElementDescriptor( ce );
                  sender.send( led );
              }
          }
          catch ( Exception e )
          {
              System.out.println( e.toString() );
          }
      }
  
      // ILateralCacheObserver methods, do nothing here since
      // the connection is not registered, the udp service is
      // is not registered.
  
      /**
       * @param cacheName The feature to be added to the CacheListener attribute
       * @param obj The feature to be added to the CacheListener attribute
       * @exception IOException
       */
      public void addCacheListener( String cacheName, ICacheListener obj )
          throws IOException
      {
          // Empty
      }
  
      /**
       * @param obj The feature to be added to the CacheListener attribute
       * @exception IOException
       */
      public void addCacheListener( ICacheListener obj )
          throws IOException
      {
          // Empty
      }
  
  
      /**
       * @param cacheName
       * @param obj
       * @exception IOException
       */
      public void removeCacheListener( String cacheName, ICacheListener obj )
          throws IOException
      {
          // Empty
      }
  
      /**
       * @param obj
       * @exception IOException
       */
      public void removeCacheListener( ICacheListener obj )
          throws IOException
      {
          // Empty
      }
  
  }
  
  
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCSender.java
  
  Index: LateralXMLRPCSender.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc;
  
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.OutputStream;
  import java.io.Reader;
  import java.io.Serializable;
  
  import java.util.Vector;
  
  import java.net.InetAddress;
  import java.net.Socket;
  
  import org.apache.stratum.jcs.auxiliary.lateral.LateralCacheInfo;
  import org.apache.stratum.jcs.auxiliary.lateral.LateralElementDescriptor;
  
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
  import org.apache.stratum.jcs.auxiliary.lateral.LateralCacheAttributes;
  
  import org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.utils.XMLRPCSocketOpener;
  import org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior.IXMLRPCConstants;
  
  import org.apache.xmlrpc.XmlRpcClientLite;
  import org.apache.xmlrpc.XmlRpcClient;
  
  import org.apache.stratum.jcs.engine.CacheElement;
  
  import org.apache.stratum.jcs.engine.behavior.ICacheElement;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  /**
   * This class is based on the log4j SocketAppender class. I'm using a differnet
   * repair structure, so it is significant;y different.
   *
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @created January 15, 2002
   * @version $Id: LateralXMLRPCSender.java,v 1.1 2002/02/20 05:30:51 asmuts Exp $
   */
  public class LateralXMLRPCSender implements IXMLRPCConstants
  {
      private final static Log log =
          LogSource.getInstance( LateralXMLRPCSender.class );
  
      private ILateralCacheAttributes ilca;
  
      private String remoteHost;
      private InetAddress address;
      int port = 1111;
  
      private XmlRpcClientLite xmlrpc;
      //private ObjectOutputStream oos;
      //private Socket socket;
      int counter = 0;
  
  //    // reset the ObjectOutputStream every 70 calls
  //    //private static final int RESET_FREQUENCY = 70;
  //    private final static int RESET_FREQUENCY = 70;
  //
  //    /**
  //     * Only block for 10 seconds before timing out on a read. TODO: make
  //     * configurable. The default 10 it way too long.
  //     */
  //    private final static int timeOut = 10000;
  //
      /** Only block for 5 seconds before timing out on startup. */
      private final static int openTimeOut = 5000;
  
  
      /**
       * Constructor for the LateralXMLRPCSender object
       *
       * @param lca
       * @exception IOException
       */
      public LateralXMLRPCSender( ILateralCacheAttributes lca )
          throws IOException
      {
          String p1 = lca.getHttpServer();
          String h2 = p1.substring( 0, p1.indexOf( ":" ) );
          int po = Integer.parseInt( p1.substring( p1.indexOf( ":" ) + 1 ) );
          log.debug( "h2 = " + h2 );
          init( h2, po );
          this.ilca = lca;
      }
  
  
      /** Description of the Method */
      protected void init( String host, int port )
          throws IOException
      {
          this.port = port;
          this.address = getAddressByName( host );
          this.remoteHost = host;
  
          try
          {
              log.debug( "Attempting connection to " + address.getHostName() );
              //socket = new Socket( address, port );
  
              xmlrpc = XMLRPCSocketOpener.openSocket( host, port, openTimeOut );
              //xmlrpc = new XmlRpcClientLite ( "http://" + host + ":" + port + "/RPC2" );
              //  have time out socket open do this for us
              //socket = SocketOpener.openSocket( host, port, openTimeOut );
  
              if ( xmlrpc == null )
              {
                  throw new IOException( "xmlrpc is null" );
              }
  
  //            socket.setSoTimeout( this.timeOut );
  //            synchronized ( this )
  //            {
  //                oos = new ObjectOutputStream( socket.getOutputStream() );
  //            }
          }
          catch ( java.net.ConnectException e )
          {
              log.debug( "Remote host " + address.getHostName() + " refused connection." );
              throw e;
          }
          catch ( IOException e )
          {
              log.debug( "Could not connect to " + address.getHostName() +
                  ". Exception is " + e );
              throw e;
          }
  
      }
      // end constructor
  
      /**
       * Gets the addressByName attribute of the LateralXMLRPCSender object
       *
       * @return The addressByName value
       */
      private InetAddress getAddressByName( String host )
      {
          try
          {
              return InetAddress.getByName( host );
          }
          catch ( Exception e )
          {
              log.error( "Could not find address of [" + host + "]", e );
              return null;
          }
      }
  
  
      /** Sends commands to the lateral cache listener. */
      public void send( LateralElementDescriptor led )
          throws IOException
      {
          log.debug( "sending LateralElementDescriptor" );
  
          if ( led == null )
          {
              return;
          }
  
          if ( address == null )
          {
              throw new IOException( "No remote host is set for LateralXMLRPCSender." );
              //return;
          }
  
  //        if ( oos != null )
  //        {
              try
              {
                  Vector params = new Vector();
                  params.add((Serializable)led);
                  xmlrpc.execute( this.HANDLERNAME, params );
  
  //                oos.writeObject( led );
  //                oos.flush();
  //                if ( ++counter >= RESET_FREQUENCY )
  //                {
  //                    counter = 0;
  //                    // Failing to reset the object output stream every now and
  //                    // then creates a serious memory leak.
  //                    log.info( "Doing oos.reset()" );
  //                    oos.reset();
  //                }
              }
              catch ( IOException e )
              {
                  //oos = null;
                  log.error( "Detected problem with connection: " + e );
                  throw e;
              }
              catch ( Exception e )
              {
                  log.error( "Detected problem with connection: " + e );
                  throw new IOException( e.getMessage() );
              }
  //        }
      }
  
  
      /**
       * Sends commands to the lateral cache listener and gets a response. I'm
       * afraid that we could get into a pretty bad blocking situation here. This
       * needs work. I just wanted to get some form of get working. Will need some
       * sort of timeout.
       */
      public Serializable sendAndReceive( LateralElementDescriptor led )
          throws IOException
      {
          ICacheElement ice = null;
  
          log.debug( "sendAndReceive led" );
  
          if ( led == null )
          {
              return null;
          }
  
          if ( address == null )
          {
              throw new IOException( "No remote host is set for LateralXMLRPCSender." );
              //return;
          }
  
  //        if ( oos != null )
  //        {
              try
              {
  //                oos.writeObject( led );
  //                oos.flush();
  
                  try
                  {
  //                    ObjectInputStream ois = new ObjectInputStream( socket.getInputStream() );
  //                    Object obj = ois.readObject();
  
                      Vector params = new Vector();
                      params.add(led);
                      Object obj = xmlrpc.execute( this.HANDLERNAME, params );
                      ice = ( ICacheElement ) obj;
                      if ( ice == null )
                      {
                          //p( "ice is null" );
                          // TODO: coutn misses
                      }
  
                  }
                  catch ( IOException ioe )
                  {
                      log.error( "Could not xmlrpc exceute " + xmlrpc, ioe );
                  }
                  catch ( Exception e )
                  {
                      log.error( e );
                  }
  
  //                if ( ++counter >= RESET_FREQUENCY )
  //                {
  //                    counter = 0;
  //                    // Failing to reset the object output stream every now and
  //                    // then creates a serious memory leak.
  //                    log.info( "Doing oos.reset()" );
  //                    oos.reset();
  //                }
              }
  //            catch ( IOException e )
  //            {
  //                //oos = null;
  //                log.error( "Detected problem with connection: " + e );
  //                throw e;
  //            }
              catch ( Exception e )
              {
                  log.error( "Detected problem with connection: " + e );
                  throw new IOException( e.getMessage() );
              }
  //        }
          return ice;
      }// end sendAndReceive
  
      // Service Methods //
      /** Description of the Method */
      public void update( ICacheElement item, byte requesterId )
          throws IOException
      {
          LateralElementDescriptor led = new LateralElementDescriptor( item );
          led.requesterId = requesterId;
          led.command = led.UPDATE;
          send( led );
      }
  
  
      /** Description of the Method */
      public void remove( String cacheName, Serializable key )
          throws IOException
      {
          remove( cacheName, key, LateralCacheInfo.listenerId );
      }
  
  
      /** Description of the Method */
      public void remove( String cacheName, Serializable key, byte requesterId )
          throws IOException
      {
          CacheElement ce = new CacheElement( cacheName, key, null );
          LateralElementDescriptor led = new LateralElementDescriptor( ce );
          led.requesterId = requesterId;
          led.command = led.REMOVE;
          send( led );
      }
  
  
      /** Description of the Method */
      public void release()
          throws IOException
      {
          // nothing needs to be done
      }
  
  
      /**
       * Closes connection used by all LateralXMLRPCSenders for this lateral
       * conneciton. Dispose request should come into the facade and be sent to
       * all lateral cache sevices. The lateral cache service will then call this
       * method.
       */
      public void dispose( String cache )
          throws IOException
      {
          // WILL CLOSE CONNECTION USED BY ALL
          //oos.close();
          //xmlrpc.
      }
  
  
      /** Description of the Method */
      public void removeAll( String cacheName )
          throws IOException
      {
          removeAll( cacheName, LateralCacheInfo.listenerId );
      }
  
  
      /** Description of the Method */
      public void removeAll( String cacheName, byte requesterId )
          throws IOException
      {
          CacheElement ce = new CacheElement( cacheName, "ALL", null );
          LateralElementDescriptor led = new LateralElementDescriptor( ce );
          led.requesterId = requesterId;
          led.command = led.REMOVEALL;
          send( led );
      }
  
  
      /** Description of the Method */
      public static void main( String args[] )
      {
          try
          {
              LateralXMLRPCSender lur = null;
              LateralCacheAttributes lca = new LateralCacheAttributes();
              lca.setHttpServer("localhost:8181");
              lur = new LateralXMLRPCSender( lca );
  
              // process user input till done
              boolean notDone = true;
              String message = null;
              // wait to dispose
              BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
  
              while ( notDone )
              {
                  System.out.println( "enter mesage:" );
                  message = br.readLine();
                  CacheElement ce = new CacheElement( "test", "test", message );
                  LateralElementDescriptor led = new LateralElementDescriptor( ce );
                  lur.send( led );
              }
          }
          catch ( Exception e )
          {
              System.out.println( e.toString() );
          }
      }
  
  }
  // end class
  
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCReceiverConnection.java
  
  Index: LateralXMLRPCReceiverConnection.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.Serializable;
  import java.net.Socket;
  import java.util.Vector;
  
  import org.apache.stratum.jcs.auxiliary.lateral.LateralCacheInfo;
  import org.apache.stratum.jcs.auxiliary.lateral.LateralElementDescriptor;
  
  import org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior.ILateralCacheXMLRPCListener;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  import org.apache.xmlrpc.XmlRpcHandler;
  
  /**
   * Separate thread run when a command comes into the LateralXMLRPCReceiver.
   *
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @version $Id: LateralXMLRPCReceiverConnection.java,v 1.7 2002/02/15 04:33:37
   *      jtaylor Exp $
   */
  public class LateralXMLRPCReceiverConnection implements XmlRpcHandler
  {//implements Runnable
  
      private final static Log log =
          LogSource.getInstance( LateralXMLRPCReceiverConnection.class );
  
  //    private Socket socket;
  //    private ObjectInputStream ois;
  
      private ILateralCacheXMLRPCListener ilcl;
  //
  //    private LateralElementDescriptor led;
  
      private int puts = 0;
  
  //    /**
  //     * Constructor for the LateralXMLRPCReceiverConnection object
  //     *
  //     * @param socket
  //     * @param ilcl
  //     */
      /**
       * Constructor for the LateralXMLRPCReceiverConnection object
       *
       * @param ilcl
       */
      public LateralXMLRPCReceiverConnection( ILateralCacheXMLRPCListener ilcl )
      {
          this.ilcl = ilcl;
  
      }
      //        this.socket = socket;
  //        this.led = led;
  //
  //        try
  //        {
  //            ois = new ObjectInputStream( socket.getInputStream() );
  //        }
  //        catch ( Exception e )
  //        {
  //            log.error( "Could not open ObjectInputStream to " + socket, e );
  //        }
  //    }
  
      /**
       * Description of the Method
       *
       * @return
       * @param method
       * @param params
       */
      public Object execute( String method, Vector params )
      {
          // do nothing with method name for now, later the action code can be
          // the method name
  
          // get the LED out of the params
          LateralElementDescriptor led = ( LateralElementDescriptor ) params.firstElement();
          return executeImpl( led );
      }
  
  
      /**
       * Main processing method for the LateralXMLRPCReceiverConnection object
       *
       * @return
       * @param led
       */
      public Serializable executeImpl( LateralElementDescriptor led )
      {
          Serializable obj = null;
  //        Object obj;
  
          try
          {
              while ( true )
              {
  //                obj = ois.readObject();
  //                LateralElementDescriptor led = ( LateralElementDescriptor ) obj;
                  if ( led == null )
                  {
                      log.debug( "LateralElementDescriptor is null" );
                      continue;
                  }
                  if ( led.requesterId == LateralCacheInfo.listenerId )
                  {
                      log.debug( "from self" );
                  }
                  else
                  {
                      if ( log.isDebugEnabled() )
                      {
                          log.debug( "receiving LateralElementDescriptor from another, led = "
                               + ", led = " + led
                               + ", led.command = " + led.command
                               + ", led.ce = " + led.ce
                               + ", ilcl = " + ilcl );
                      }
                      if ( led.command == led.UPDATE )
                      {
                          puts++;
                          if ( log.isDebugEnabled() )
                          {
                              if ( puts % 100 == 0 )
                              {
                                  log.debug( "puts = " + puts );
                              }
                          }
                          ilcl.handlePut( led.ce );
                      }
                      else
                          if ( led.command == led.REMOVE )
                      {
                          ilcl.handleRemove( led.ce.getCacheName(), led.ce.getKey() );
                      }
                      else
                          if ( led.command == led.GET )
                      {
                          obj = getAndRespond( led.ce.getCacheName(), led.ce.getKey() );
                          //ilcl.handleGet( led.ce.getCacheName(), led.ce.getKey() );
                      }
                  }
              }
          }
          catch ( java.io.EOFException e )
          {
              log.info( "Caught java.io.EOFException closing conneciton." );
          }
          catch ( java.net.SocketException e )
          {
              log.info( "Caught java.net.SocketException closing conneciton." );
          }
          catch ( Exception e )
          {
              log.error( "Unexpected exception. Closing conneciton", e );
          }
  
  //        try
  //        {
  //            ois.close();
  //        }
  //        catch ( Exception e )
  //        {
  //            log.error( "Could not close connection", e );
  //        }
          return obj;
      }
  
  
      /**
       * Send back the object if found.
       *
       * @return The {3} value
       * @param cacheName
       * @param key
       * @exception Exception
       */
      private Serializable getAndRespond( String cacheName, Serializable key )
          throws Exception
      {
          Serializable obj = ilcl.handleGet( cacheName, key );
  
          if ( log.isDebugEnabled() )
          {
              log.debug( "obj = " + obj );
          }
  
  //        ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream() );
  //
  //        if ( oos != null )
  //        {
  //            try
  //            {
  //                oos.writeObject( obj );
  //                oos.flush();
  //            }
  //            catch ( IOException e )
  //            {
  //                oos = null;
  //                log.error( "Detected problem with connection", e );
  //                throw e;
  //            }
  //        }
          return obj;
      }
  }
  
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCReceiver.java
  
  Index: LateralXMLRPCReceiver.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import java.net.InetAddress;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.io.IOException;
  
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
  import org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior.ILateralCacheXMLRPCListener;
  import org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior.IXMLRPCConstants;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  import org.apache.xmlrpc.WebServer;
  
  /**
   * Processes commands from the server socket.
   *
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @created January 15, 2002
   * @version $Id: LateralXMLRPCReceiver.java,v 1.8 2002/02/16 02:37:19 jtaylor
   *      Exp $
   */
  public class LateralXMLRPCReceiver implements IXMLRPCConstants
  {
      private final static Log log =
          LogSource.getInstance( LateralXMLRPCReceiver.class );
  
      private int port;
  
      private ILateralCacheXMLRPCListener ilcl;
  
      /**
       * How long the server will block on an accept(). 0 is infinte.
       */
      private final static int sTimeOut = 0;
  
  
      /**
       * Main processing method for the LateralXMLRPCReceiver object
       */
      public void init()
      {
          try
          {
              if ( log.isDebugEnabled() )
              {
                  log.debug( "Listening on port " + port );
              }
              log.info( "Listening on port " + port );
  
  //            ServerSocket serverSocket = new ServerSocket( port );
  //            serverSocket.setSoTimeout( this.sTimeOut );
  //            while ( true )
  //            {
                  if ( log.isDebugEnabled() )
                  {
                      log.debug( "Waiting for clients to connect " );
                  }
                  log.info( "Waiting for clients to client " );
  
                  LateralXMLRPCReceiverConnection handler = new LateralXMLRPCReceiverConnection( ilcl );
                  try
                  {
                      WebServer server = new WebServer( port );
                      server.addHandler( this.HANDLERNAME, handler );
                      server.setParanoid( false );
                  }
                  catch ( IOException ioe )
                  {
                      log.error( ioe );
                  }
  
  //                Socket socket = serverSocket.accept();
  //                InetAddress inetAddress = socket.getInetAddress();
  //                if ( log.isDebugEnabled() )
  //                {
  //                    log.debug( "Connected to client at " + inetAddress );
  //                }
  //                log.info( "Connected to client at " + inetAddress );
  //                log.info( "Starting new socket node." );
  //                new Thread( new LateralXMLRPCReceiverConnection( socket, ilcl ) ).start();
  //            }
          }
          catch ( Exception e )
          {
              e.printStackTrace();
          }
      }
  
  
      /**
       * Constructor for the LateralXMLRPCReceiver object
       *
       * @param lca
       * @param ilcl
       */
      public LateralXMLRPCReceiver( ILateralCacheAttributes lca, ILateralCacheXMLRPCListener ilcl )
      {
          this.port = lca.getTcpListenerPort();
          this.ilcl = ilcl;
          if ( log.isDebugEnabled() )
          {
              log.debug( "ilcl = " + ilcl );
          }
          init();
      }
  }
  
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/LateralGroupCacheXMLRPCListener.java
  
  Index: LateralGroupCacheXMLRPCListener.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
  import org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior.ILateralCacheXMLRPCListener;
  
  import org.apache.stratum.jcs.engine.behavior.ICompositeCacheManager;
  import org.apache.stratum.jcs.engine.behavior.ICacheType;
  
  import org.apache.stratum.jcs.engine.control.group.GroupCacheManager;
  import org.apache.stratum.jcs.engine.control.group.GroupCacheManager;
  import org.apache.stratum.jcs.engine.control.group.GroupCacheManager;
  import org.apache.stratum.jcs.engine.control.group.GroupCacheManagerFactory;
  import org.apache.stratum.jcs.engine.control.group.GroupCacheManagerFactory;
  import org.apache.stratum.jcs.engine.control.group.GroupCacheManagerFactory;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  /**
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @created January 15, 2002
   * @version $Id: LateralGroupCacheXMLRPCListener.java,v 1.6 2002/02/15 04:33:37
   *      jtaylor Exp $
   */
  public class LateralGroupCacheXMLRPCListener
       extends LateralCacheXMLRPCListener
       implements ILateralCacheXMLRPCListener
  {
      private final static Log log =
          LogSource.getInstance( LateralGroupCacheXMLRPCListener.class );
  
      /**
       * Constructor for the LateralGroupCacheXMLRPCListener object
       *
       * @param ilca
       */
      protected LateralGroupCacheXMLRPCListener( ILateralCacheAttributes ilca )
      {
          super( ilca );
          log.debug( "creating LateralGroupCacheXMLRPCListener" );
      }
  
  
      /**
       * Gets the instance attribute of the LateralGroupCacheXMLRPCListener class
       *
       * @return The instance value
       */
      public static ILateralCacheListener getInstance( ILateralCacheAttributes ilca )
      {
          //throws IOException, NotBoundException
          ILateralCacheListener ins = ( ILateralCacheListener ) instances.get( String.valueOf( ilca.getTcpListenerPort() ) );
          if ( ins == null )
          {
              synchronized ( LateralGroupCacheXMLRPCListener.class )
              {
                  if ( ins == null )
                  {
                      ins = new LateralGroupCacheXMLRPCListener( ilca );
                      ins.init();
                  }
                  if ( log.isDebugEnabled() )
                  {
                      log.debug( "created new listener " + ilca.getTcpListenerPort() );
                  }
                  instances.put( String.valueOf( ilca.getTcpListenerPort() ), ins );
              }
          }
          return ins;
      }
  
  
      // override for new funcitonality
      // lazy init is too slow, find a better way
      /**
       * Gets the cacheManager attribute of the LateralGroupCacheXMLRPCListener
       * object
       */
      protected void getCacheManager()
      {
          try
          {
              if ( cacheMgr == null )
              {
                  cacheMgr = ( ICompositeCacheManager ) GroupCacheManagerFactory.getInstance();
                  if ( log.isDebugEnabled() )
                  {
                      log.debug( " groupcache cacheMgr = " + cacheMgr );
                  }
              }
              else
              {
                  if ( log.isDebugEnabled() )
                  {
                      log.debug( "already got groupcache cacheMgr = " + cacheMgr );
                  }
              }
          }
          catch ( Exception e )
          {
              log.error( e );
          }
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/LateralCacheXMLRPCListener.java
  
  Index: LateralCacheXMLRPCListener.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import java.io.IOException;
  import java.io.Serializable;
  
  import java.util.HashMap;
  
  import org.apache.stratum.jcs.auxiliary.lateral.LateralCacheInfo;
  
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
  import org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior.ILateralCacheXMLRPCListener;
  
  import org.apache.stratum.jcs.engine.behavior.ICache;
  import org.apache.stratum.jcs.engine.behavior.ICacheElement;
  import org.apache.stratum.jcs.engine.behavior.ICompositeCache;
  import org.apache.stratum.jcs.engine.behavior.ICompositeCacheManager;
  
  import org.apache.stratum.jcs.engine.control.CacheManagerFactory;
  import org.apache.stratum.jcs.engine.control.CompositeCacheManager;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  /**
   * Description of the Class
   *
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @created January 15, 2002
   * @version $Id: LateralCacheXMLRPCListener.java,v 1.8 2002/02/15 04:33:37 jtaylor
   *      Exp $
   */
  public class LateralCacheXMLRPCListener implements ILateralCacheXMLRPCListener, Serializable
  {
      private final static Log log =
          LogSource.getInstance( LateralCacheXMLRPCListener.class );
  
      /** Description of the Field */
      protected static transient ICompositeCacheManager cacheMgr;
      /** Description of the Field */
      protected final static HashMap instances = new HashMap();
  
      // instance vars
      private LateralXMLRPCReceiver receiver;
      private ILateralCacheAttributes ilca;
      private boolean inited = false;
  
  
      /**
       * Only need one since it does work for all regions, just reference by
       * multiple region names.
       *
       * @param ilca
       */
      protected LateralCacheXMLRPCListener( ILateralCacheAttributes ilca )
      {
          this.ilca = ilca;
      }
  
  
      /** Description of the Method */
      public void init()
      {
          try
          {
              // need to connect based on type
              //ILateralCacheListener ilcl = this;
              //p( "in init, ilcl = " + ilcl );
              receiver = new LateralXMLRPCReceiver( ilca, this );
              //Thread t = new Thread( receiver );
              //t.start();
          }
          catch ( Exception ex )
          {
              log.error( ex );
              throw new IllegalStateException( ex.getMessage() );
          }
          inited = true;
      }
  
  
      /**
       * let the lateral cache set a listener_id. Since there is only one
       * listerenr for all the regions and every region gets registered? the id
       * shouldn't be set if it isn't zero. If it is we assume that it is a
       * reconnect.
       *
       * @param id The new listenerId value
       */
      public void setListenerId( byte id )
          throws IOException
      {
          LateralCacheInfo.listenerId = id;
          if ( log.isDebugEnabled() )
          {
              log.debug( "set listenerId = " + id );
          }
      }
  
  
      /**
       * Gets the listenerId attribute of the LateralCacheXMLRPCListener object
       *
       * @return The listenerId value
       */
      public byte getListenerId()
          throws IOException
      {
  
          // set the manager since we are in use
          //getCacheManager();
  
          //p( "get listenerId" );
          if ( log.isDebugEnabled() )
          {
              log.debug( "get listenerId = " + LateralCacheInfo.listenerId );
          }
          return LateralCacheInfo.listenerId;
      }
  
  
      /**
       * Gets the instance attribute of the LateralCacheXMLRPCListener class
       *
       * @return The instance value
       */
      public static ILateralCacheListener getInstance( ILateralCacheAttributes ilca )
      {
          //throws IOException, NotBoundException
          ILateralCacheListener ins = ( ILateralCacheListener ) instances.get( String.valueOf( ilca.getTcpListenerPort() ) );
          if ( ins == null )
          {
              synchronized ( LateralCacheXMLRPCListener.class )
              {
                  if ( ins == null )
                  {
                      ins = new LateralCacheXMLRPCListener( ilca );
                      ins.init();
                  }
                  if ( log.isDebugEnabled() )
                  {
                      log.debug( "created new listener " + ilca.getTcpListenerPort() );
                  }
                  instances.put( String.valueOf( ilca.getTcpListenerPort() ), ins );
              }
          }
          return ins;
      }
  
  
      //////////////////////////// implements the ILateralCacheListener interface. //////////////
      /** */
      public void handlePut( ICacheElement cb )
          throws IOException
      {
          if ( log.isDebugEnabled() )
          {
              log.debug( "PUTTING ELEMENT FROM LATERAL" );
          }
          getCacheManager();
          ICompositeCache cache = ( ICompositeCache ) cacheMgr.getCache( cb.getCacheName() );
          cache.update( cb, ICache.REMOTE_INVOKATION );
          //handleRemove(cb.getCacheName(), cb.getKey());
      }
  
  
      /** Description of the Method */
      public void handleRemove( String cacheName, Serializable key )
          throws IOException
      {
          if ( log.isDebugEnabled() )
          {
              log.debug( "handleRemove> cacheName=" + cacheName + ", key=" + key );
          }
  
          getCacheManager();
          // interface limitation here
  
          ICompositeCache cache = ( ICompositeCache ) cacheMgr.getCache( cacheName );
          cache.remove( key, ICache.REMOTE_INVOKATION );
      }
  
  
      /** Description of the Method */
      public void handleRemoveAll( String cacheName )
          throws IOException
      {
          if ( log.isDebugEnabled() )
          {
              log.debug( "handleRemoveAll> cacheName=" + cacheName );
          }
          getCacheManager();
          ICache cache = cacheMgr.getCache( cacheName );
          cache.removeAll();
      }
  
      /** Test get implementation. */
      public Serializable handleGet( String cacheName, Serializable key )
          throws IOException
      {
          if ( log.isDebugEnabled() )
          {
              log.debug( "handleGet> cacheName=" + cacheName + ", key = " + key );
          }
          getCacheManager();
          ICompositeCache cache = ( ICompositeCache ) cacheMgr.getCache( cacheName );
          // get container
          return cache.get( key, true, ICache.REMOTE_INVOKATION );
      }
  
      /** Description of the Method */
      public void handleDispose( String cacheName )
          throws IOException
      {
          if ( log.isDebugEnabled() )
          {
              log.debug( "handleDispose> cacheName=" + cacheName );
          }
          CompositeCacheManager cm = ( CompositeCacheManager ) cacheMgr;
          cm.freeCache( cacheName, ICache.REMOTE_INVOKATION );
      }
  
  
      // override for new funcitonality
      /**
       * Gets the cacheManager attribute of the LateralCacheXMLRPCListener object
       */
      protected void getCacheManager()
      {
          if ( cacheMgr == null )
          {
              cacheMgr = ( ICompositeCacheManager ) CacheManagerFactory.getInstance();
              if ( log.isDebugEnabled() )
              {
                  log.debug( "cacheMgr = " + cacheMgr );
              }
          }
          else
          {
              if ( log.isDebugEnabled() )
              {
                  log.debug( "already got cacheMgr = " + cacheMgr );
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/behavior/IXMLRPCConstants.java
  
  Index: IXMLRPCConstants.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior;
  
  public interface IXMLRPCConstants {
  
      public static final String HANDLERNAME = "LATERAL_XMLRPC_CACHE";
  
  }
  
  
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/xmlrpc/behavior/ILateralCacheXMLRPCListener.java
  
  Index: ILateralCacheXMLRPCListener.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.lateral.xmlrpc.behavior;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import java.io.Serializable;
  import java.io.IOException;
  
  import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
  
  /**
   * Listens for lateral cache event notification.
   *
   * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
   * @created February 19, 2002
   * @version $Id:   asmuts
   *      Exp $
   */
  public interface ILateralCacheXMLRPCListener extends ILateralCacheListener
  {
  
      /** Description of the Method */
      public void init();
  
      /** Tries to get a requested item from the cache. */
      public Serializable handleGet( String cacheName, Serializable key )
          throws IOException;
  
  }
  
  
  

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