asmuts      02/01/18 13:53:35

  Modified:    src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp
                        LateralTCPSender.java
                        LateralTCPReceiverConnection.java
                        LateralTCPReceiver.java
                        LateralCacheTCPListener.java
  Log:
  put in some rough safe guards against blocking on reads.
  
  Allowed for get operations in the TCP Lateral cache, can an easy way
  to turn off this functionality in the configuration files.  You can specify
  that putOnlyMode=true.
  
  Revision  Changes    Path
  1.5       +35 -4     
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java
  
  Index: LateralTCPSender.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LateralTCPSender.java     18 Jan 2002 06:45:27 -0000      1.4
  +++ LateralTCPSender.java     18 Jan 2002 21:53:34 -0000      1.5
  @@ -18,6 +18,8 @@
   
   import org.apache.stratum.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
   
  +import org.apache.stratum.jcs.auxiliary.lateral.socket.tcp.utils.SocketOpener;
  +
   import org.apache.stratum.jcs.engine.CacheElement;
   
   import org.apache.stratum.jcs.engine.behavior.ICacheElement;
  @@ -52,6 +54,17 @@
       //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;
  +
   
       /////////////////////////////////////////////////////////////////
       /**
  @@ -90,7 +103,16 @@
           try
           {
               log.debug( "Attempting connection to " + address.getHostName() );
  -            socket = new Socket( address, port );
  +            //socket = new Socket( address, port );
  +
  +            //  have time out socket open do this for us
  +            socket = SocketOpener.openSocket( host, port, openTimeOut );
  +
  +            if ( socket == null ) {
  +              throw new IOException( "Socket is null" );
  +            }
  +
  +            socket.setSoTimeout(this.timeOut);
               synchronized ( this )
               {
                   oos = new ObjectOutputStream( socket.getOutputStream() );
  @@ -186,7 +208,11 @@
   
       ///////////////////////////////////////////////////////
       /**
  -     *  Sends commands to the lateral cache listener.
  +     *  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.
        *
        *@param  led              Description of the Parameter
        *@return                  Description of the Return Value
  @@ -227,13 +253,18 @@
                       ice = ( ICacheElement ) obj;
                       if ( ice == null )
                       {
  -                        p( "ice is null" );
  +                        //p( "ice is null" );
  +                        // TODO: coutn misses
                       }
   
                   }
  +                catch ( IOException ioe )
  +                {
  +                    log.error( ioe, "Could not open ObjectInputStream to " + socket 
);
  +                }
                   catch ( Exception e )
                   {
  -                    log.error( e, "Could not open ObjectInputStream to " + socket );
  +                    log.error( e );
                   }
   
                   if ( ++counter >= RESET_FREQUENCY )
  
  
  
  1.5       +29 -23    
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralTCPReceiverConnection.java
  
  Index: LateralTCPReceiverConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralTCPReceiverConnection.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LateralTCPReceiverConnection.java 18 Jan 2002 06:45:27 -0000      1.4
  +++ LateralTCPReceiverConnection.java 18 Jan 2002 21:53:34 -0000      1.5
  @@ -26,11 +26,11 @@
   {
   
       /**
  -     *  Description of the Field
  +     *  Development debugging.
        */
       protected final static boolean debug = false;
       /**
  -     *  Description of the Field
  +     *  Print every 100 puts.
        */
       protected final static boolean debugput = true;
   
  @@ -121,12 +121,12 @@
                       {
                           ilcl.handleRemove( led.ce.getCacheName(), led.ce.getKey() );
                       }
  -//                    else
  -//                        if ( led.command == led.GET )
  -//                    {
  -//                        // getAndRespond( led.ce.getCacheName(), led.ce.getKey() 
);
  -//                        //ilcl.handleGet( led.ce.getCacheName(), led.ce.getKey() 
);
  -//                    }
  +                    else
  +                        if ( led.command == led.GET )
  +                    {
  +                        getAndRespond( led.ce.getCacheName(), led.ce.getKey() );
  +                        //ilcl.handleGet( led.ce.getCacheName(), led.ce.getKey() );
  +                    }
                   }
               }
           }
  @@ -161,21 +161,27 @@
       {
           Serializable obj = ilcl.handleGet( cacheName, key );
   
  -//        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;
  -//            }
  -//        }
  +
  +        if ( debug )
  +        {
  +            p( "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.5       +6 -1      
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralTCPReceiver.java
  
  Index: LateralTCPReceiver.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralTCPReceiver.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LateralTCPReceiver.java   18 Jan 2002 06:45:27 -0000      1.4
  +++ LateralTCPReceiver.java   18 Jan 2002 21:53:34 -0000      1.5
  @@ -27,6 +27,11 @@
       private final static Logger log = LoggerManager.getLogger( 
"lateral_lateralcachemanager" );
       private ILateralCacheTCPListener ilcl;
   
  +    /**
  +     * How long the server will block on an accept().  0 is infinte.
  +     */
  +    private final static int sTimeOut = 0;
  +
   
       ////////////////////////////////////////////////
       /**
  @@ -42,7 +47,7 @@
               }
               log.info( "Listening on port " + port );
               ServerSocket serverSocket = new ServerSocket( port );
  -
  +            serverSocket.setSoTimeout(this.sTimeOut);
               while ( true )
               {
                   if ( debug )
  
  
  
  1.6       +57 -3     
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralCacheTCPListener.java
  
  Index: LateralCacheTCPListener.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/socket/tcp/LateralCacheTCPListener.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LateralCacheTCPListener.java      18 Jan 2002 06:45:27 -0000      1.5
  +++ LateralCacheTCPListener.java      18 Jan 2002 21:53:34 -0000      1.6
  @@ -1,6 +1,59 @@
   package org.apache.stratum.jcs.auxiliary.lateral.socket.tcp;
   
  -//////////////////////////////////
  +/*
  + * 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 [EMAIL PROTECTED]
  + *
  + * 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;
   
  @@ -262,8 +315,9 @@
               log.debug( "handleGet> cacheName=" + cacheName + ", key = " + key );
           }
           getCacheManager();
  -        ICache cache = cacheMgr.getCache( cacheName );
  -        return cache.get( key, ICache.REMOTE_INVOKATION );
  +        ICompositeCache cache = ( ICompositeCache ) cacheMgr.getCache( cacheName );
  +        // get container
  +        return cache.get( key, true, ICache.REMOTE_INVOKATION );
       }
   
       ///////////////////////////////////////////////////
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to