jtaylor     02/04/11 18:39:57

  Modified:    .        project.xml
               src/java/org/apache/jcs JCS.java
               src/java/org/apache/jcs/engine CacheConstants.java
                        CacheEventQueue.java
               src/java/org/apache/jcs/engine/control CacheHub.java
               src/java/org/apache/jcs/engine/control/group GroupCache.java
                        GroupCacheHub.java
  Log:
  - Implemented an internal queue for CacheEventQueue instead of the one from
    util.concurrent. Looking at the unit tests this gets us a performance
    increase from 25% ( for TestSimpleLoad ) to 75% ( The other two tests,
    yes three times faster! ) More room for improvement I hope, but this
    gets us back to where we were (it's actually a little faster then it
    was when we were using JGL, but lots of other things have changed since
    then. A big chunk of change came from moving the object creation for the
    new node outside of the synchronized block -- who knew!
  
  - Big changes to the way configuration works, trying to make things more
    flexible, you can now get an unconfigured cache and configure it in a
    couple different ways, possibly even more then once (that part is not
    yet tested)
  
  - Component wrapper for JCS! Still unsure about getting the properties
    from the configuration, may just scrap it and move JCS to using the
    configuration interfaces internally.
  
  Revision  Changes    Path
  1.3       +10 -1     jakarta-turbine-jcs/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml       8 Apr 2002 14:27:36 -0000       1.2
  +++ project.xml       12 Apr 2002 01:39:57 -0000      1.3
  @@ -4,7 +4,7 @@
     <version>2</version>
     <name>jakarta-turbine-jcs</name>
     <id>jcs</id>
  -  <currentVersion>1.0-b2-dev</currentVersion>
  +  <currentVersion>1.0-dev</currentVersion>
     <organization>Apache Software Foundation</organization>
     <inceptionYear>2002</inceptionYear>
     <package>org.apache.jcs</package>
  @@ -119,6 +119,15 @@
         <version>1.1</version>
         <jar>xmlrpc.jar</jar>
       </dependency>
  +
  +    <!-- For Configurable / Initializable -->
  +    <dependency>
  +      <name>jakarta-turbine-stratum</name>
  +      <type>required</type>
  +      <version>1.0-b2-dev</version>
  +      <jar>stratum-1.0-b2-dev.jar</jar>
  +    </dependency>
  +
     </dependencies>
     <build>
       <sourceDirectories>
  
  
  
  1.4       +10 -15    jakarta-turbine-jcs/src/java/org/apache/jcs/JCS.java
  
  Index: JCS.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/JCS.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JCS.java  8 Apr 2002 22:58:14 -0000       1.3
  +++ JCS.java  12 Apr 2002 01:39:57 -0000      1.4
  @@ -71,7 +71,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Aaron Smuts</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>James Taylor</a>
  - * @version $Id: JCS.java,v 1.3 2002/04/08 22:58:14 jtaylor Exp $
  + * @version $Id: JCS.java,v 1.4 2002/04/12 01:39:57 jtaylor Exp $
    */
   public class JCS extends GroupCacheAccess
   {
  @@ -127,24 +127,19 @@
        * CacheAccess, the cache manager is a GroupCacheHub. NOTE: This can
        * will be moved up into GroupCacheAccess.
        */
  -    protected static void ensureCacheManager()
  +    protected static synchronized void ensureCacheManager()
       {
           if ( cacheMgr == null )
           {
  -            synchronized ( JCS.class )
  +            if ( configFilename == null )
               {
  -                if ( cacheMgr == null )
  -                {
  -                    if ( configFilename == null )
  -                    {
  -                        cacheMgr = GroupCacheHub.getInstance();
  -                    }
  -                    else
  -                    {
  -                        cacheMgr = GroupCacheHub
  -                            .getInstance( configFilename );
  -                    }
  -                }
  +                cacheMgr = GroupCacheHub.getInstance();
  +            }
  +            else
  +            {
  +                cacheMgr = GroupCacheHub.getUnconfiguredInstance();
  +
  +                cacheMgr.configure( configFilename );
               }
           }
       }
  
  
  
  1.3       +3 -1      
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheConstants.java
  
  Index: CacheConstants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheConstants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CacheConstants.java       10 Apr 2002 22:53:31 -0000      1.2
  +++ CacheConstants.java       12 Apr 2002 01:39:57 -0000      1.3
  @@ -4,10 +4,12 @@
    * Constants used throughout the JCS cache engine
    *
    * @author jtaylor
  - * @version $Id: CacheConstants.java,v 1.2 2002/04/10 22:53:31 dlr Exp $
  + * @version $Id: CacheConstants.java,v 1.3 2002/04/12 01:39:57 jtaylor Exp $
    */
   public interface CacheConstants
   {
  +    public static final String DEFAULT_CONFIG = "/cache.ccf";
  +
       /**
        * Where the current activity came from. This effects whether the remote
        * will be included. Prevents remote-local loops.
  
  
  
  1.2       +54 -32    
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheEventQueue.java
  
  Index: CacheEventQueue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheEventQueue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CacheEventQueue.java      7 Apr 2002 16:55:26 -0000       1.1
  +++ CacheEventQueue.java      12 Apr 2002 01:39:57 -0000      1.2
  @@ -3,15 +3,12 @@
   import java.io.IOException;
   import java.io.Serializable;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.jcs.engine.behavior.ICacheElement;
   import org.apache.jcs.engine.behavior.ICacheEventQueue;
   import org.apache.jcs.engine.behavior.ICacheListener;
   
  -import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
  -
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
   /**
    * An event queue is used to propagate ordered cache events to one and only one
    * target listener.
  @@ -22,7 +19,7 @@
   
       private static int processorInstanceCount = 0;
   
  -    private LinkedQueue queue = new LinkedQueue();
  +    // private LinkedQueue queue = new LinkedQueue();
   
       private ICacheListener listener;
       private byte listenerId;
  @@ -37,6 +34,14 @@
       private boolean destroyed;
       private Thread t;
   
  +    // Internal queue implementation
  +
  +    private Object queueLock = new Object();
  +
  +    // Dummy node
  +
  +    private Node head = new Node();
  +    private Node tail = head;
   
       /**
        * Constructs with the specified listener and the cache name.
  @@ -99,7 +104,7 @@
               // sychronize on queue so the thread will not wait forever,
               // and then interrupt the QueueProcessor
   
  -            synchronized ( queue )
  +            synchronized ( queueLock )
               {
                   t.interrupt();
               }
  @@ -191,25 +196,53 @@
        */
       private void put( AbstractCacheEvent event )
       {
  -        try
  +        Node newNode = new Node();
  +
  +        newNode.event = event;
  +
  +        synchronized ( queueLock )
           {
  -            queue.put( event );
  +            tail.next = newNode;
  +            tail = newNode;
  +
  +            queueLock.notify();
           }
  -        catch ( InterruptedException e )
  +    }
  +
  +    private AbstractCacheEvent take() throws InterruptedException
  +    {
  +        synchronized ( queueLock )
           {
  -            // We should handle terminated gracefully here, however the
  -            // LinkedQueue implementation of Channel shouldn't throw
  -            // this since puts are non blocking. For now I will ignore
  -            // it. [[EMAIL PROTECTED]]
  +            // wait until there is something to read
  +
  +            while ( head == tail )
  +            {
  +                queueLock.wait();
  +            }
  +
  +            // we have the lock, and the list is not empty
  +
  +            Node node = head.next;
   
  -            // Options:
  -            //   - destory self
  -            //   - destory and rethrow
  +            AbstractCacheEvent value = head.event;
  +
  +            // Node becomes the new head (head is always empty)
  +
  +            node.event = null;
  +            head = node;
  +
  +            return value;
           }
       }
   
  -
       ///////////////////////////// Inner classes /////////////////////////////
  +
  +    private static class Node
  +    {
  +        Node next = null;
  +        AbstractCacheEvent event = null;
  +    }
  +
       /**
        * @author asmuts
        * @created January 15, 2002
  @@ -226,19 +259,18 @@
               setDaemon( true );
           }
   
  -
           /**
            * Main processing method for the QProcessor object
            */
           public void run()
           {
  -            Runnable r = null;
  +            AbstractCacheEvent r = null;
   
               while ( !destroyed )
               {
                   try
                   {
  -                    r = ( Runnable ) queue.take();
  +                    r = take();
                   }
                   catch ( InterruptedException e )
                   {
  @@ -253,7 +285,7 @@
                   }
               }
               // declare failure as listener is permanently unreachable.
  -            queue = null;
  +            // queue = null;
               listener = null;
               // The listener failure logging more the problem of the user
               // of the q.
  @@ -261,7 +293,6 @@
           }
       }
   
  -
       /**
        * Retries before declaring failure.
        *
  @@ -316,7 +347,6 @@
               return;
           }
   
  -
           /**
            * Description of the Method
            *
  @@ -326,7 +356,6 @@
               throws IOException;
       }
   
  -
       /**
        * @author asmuts
        * @created January 15, 2002
  @@ -336,7 +365,6 @@
   
           private ICacheElement ice;
   
  -
           /**
            * Constructor for the PutEvent object
            *
  @@ -355,7 +383,6 @@
                */
           }
   
  -
           /**
            * Description of the Method
            *
  @@ -373,7 +400,6 @@
           }
       }
   
  -
       /**
        * Description of the Class
        *
  @@ -384,7 +410,6 @@
       {
           private Serializable key;
   
  -
           /**
            * Constructor for the RemoveEvent object
            *
  @@ -397,7 +422,6 @@
               this.key = key;
           }
   
  -
           /**
            * Description of the Method
            *
  @@ -410,7 +434,6 @@
           }
       }
   
  -
       /**
        * Description of the Class
        *
  @@ -430,7 +453,6 @@
               listener.handleRemoveAll( cacheName );
           }
       }
  -
   
       /**
        * Description of the Class
  
  
  
  1.5       +71 -45    
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CacheHub.java
  
  Index: CacheHub.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CacheHub.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CacheHub.java     10 Apr 2002 15:01:02 -0000      1.4
  +++ CacheHub.java     12 Apr 2002 01:39:57 -0000      1.5
  @@ -60,27 +60,38 @@
       /** The Singleton Instance */
       protected static CacheHub instance;
   
  -    /** Gets the instance of CacheHub */
  -    public static CacheHub getInstance()
  +    /**
  +     * Gets the CacheHub instance. For backward compatibility, if this creates
  +     * the instance it will attempt to configure it with the default
  +     * configuration. If you want to configure from your own source, use
  +     * {@link #getUnconfiguredInstance} and then call {@link #configure}
  +     */
  +    public static synchronized CacheHub getInstance()
       {
  -        return getInstance( null );
  +        if ( instance == null )
  +        {
  +            log.debug( "Instance is null, creating with default config" );
  +
  +            instance = createInstance();
  +
  +            instance.configure();
  +        }
  +
  +        instance.incrementClients();
  +
  +        return instance;
       }
   
  -    /** Gets the CacheHub instance */
  -    public static synchronized CacheHub getInstance( String propFile )
  +    /**
  +     * Get a CacheHub instance which is not configured.
  +     */
  +    public static synchronized CacheHub getUnconfiguredInstance()
       {
           if ( instance == null )
           {
  -            log.debug( "Instance is null, creating" );
  +            log.debug( "Instance is null, creating with provided config" );
   
  -            if ( propFile == null )
  -            {
  -                instance = new CacheHub();
  -            }
  -            else
  -            {
  -                instance = new CacheHub( propFile );
  -            }
  +            instance = createInstance();
           }
   
           instance.incrementClients();
  @@ -88,23 +99,36 @@
           return instance;
       }
   
  -    /** Constructor for the CacheHub object */
  -    protected CacheHub()
  +    /**
  +     * Simple factory method, must override in subclasses so getInstance
  +     * creates / returns the correct object.
  +     */
  +    protected static CacheHub createInstance()
       {
  -        this( "/cache.ccf" );
  +        return new CacheHub();
       }
   
       /**
  -     * Constructor for the CacheHub object
  +     * Configure with default properties file
  +     */
  +    public void configure()
  +    {
  +        configure( CacheConstants.DEFAULT_CONFIG );
  +    }
  +
  +    /**
  +     * Configure from specific properties file
        *
  -     * @param propFile
  +     * @param propFile Path <u>within classpath</u> to load configuration from
        */
  -    protected CacheHub( String propFile )
  +    public void configure( String propFile )
       {
           log.debug( "Creating cache manager from config file: " + propFile );
   
           Properties props = new Properties();
  +
           InputStream is = getClass().getResourceAsStream( propFile );
  +
           try
           {
               props.load( is );
  @@ -131,26 +155,38 @@
               }
           }
   
  +        configure( props );
  +    }
  +
  +    /**
  +     * Configure from properties object
  +     *
  +     * @param props
  +     */
  +    public void configure( Properties props )
  +    {
           // FIXME: need to do something for defaults
           // create a default entry in the propsfile
           // setDefaults( props );
   
  -        // Create caches
  +        CompositeCacheConfigurator configurator =
  +            new CompositeCacheConfigurator( this );
   
  -        try
  -        {
  -            createCaches( props );
  -        }
  -        catch ( IOException ex )
  -        {
  -            log.error( "Failed to create caches", ex );
  -            throw new IllegalStateException( ex.getMessage() );
  -        }
  -        catch ( NotBoundException ex )
  -        {
  -            log.error( "Failed to create caches", ex );
  -            throw new IllegalStateException( ex.getMessage() );
  -        }
  +        configurator.doConfigure( props );
  +
  +        // FIXME: Supposedly neither of these can be thrown from the above code,
  +        //        are they safe to remove? Or should the go elsewhere?
  +        //
  +        // catch ( IOException ex )
  +        // {
  +        //     log.error( "Failed to create caches", ex );
  +        //     throw new IllegalStateException( ex.getMessage() );
  +        // }
  +        // catch ( NotBoundException ex )
  +        // {
  +        //     log.error( "Failed to create caches", ex );
  +        //     throw new IllegalStateException( ex.getMessage() );
  +        // }
       }
   
       /**
  @@ -195,16 +231,6 @@
       public IElementAttributes getDefaultElementAttributes()
       {
           return this.defaultElementAttr.copy();
  -    }
  -
  -    /** */
  -    private void createCaches( Properties props )
  -        throws IOException, NotBoundException
  -    {
  -        CompositeCacheConfigurator configurator =
  -            new CompositeCacheConfigurator( this );
  -
  -        configurator.doConfigure( props );
       }
   
       /** Creates internal system cache */
  
  
  
  1.5       +0 -1      
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/group/GroupCache.java
  
  Index: GroupCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/group/GroupCache.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GroupCache.java   10 Apr 2002 15:01:02 -0000      1.4
  +++ GroupCache.java   12 Apr 2002 01:39:57 -0000      1.5
  @@ -160,7 +160,6 @@
        * Gets an element fromt he cache
        *
        * @param key The key for the element
  -     * @param container Should it return the CacheElement wrapper
        * @param invocation Is the originating method call from a local source
        * @return Returns element from the cache if found, else null
        */
  
  
  
  1.2       +14 -49    
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/group/GroupCacheHub.java
  
  Index: GroupCacheHub.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/group/GroupCacheHub.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GroupCacheHub.java        8 Apr 2002 18:27:49 -0000       1.1
  +++ GroupCacheHub.java        12 Apr 2002 01:39:57 -0000      1.2
  @@ -2,68 +2,31 @@
   
   import java.io.Serializable;
   
  -import org.apache.jcs.engine.behavior.IElementAttributes;
  -
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.jcs.engine.behavior.ICache;
   import org.apache.jcs.engine.behavior.ICompositeCache;
   import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
  -
  +import org.apache.jcs.engine.behavior.IElementAttributes;
   import org.apache.jcs.engine.control.Cache;
   import org.apache.jcs.engine.control.CacheHub;
   
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
  -
   /** */
   public class GroupCacheHub
  -     extends CacheHub
  -     implements Serializable
  +    extends CacheHub
  +    implements Serializable
   {
  -    private final static Log log =
  -        LogFactory.getLog( CacheHub.class );
  -
       /**
  -     * Overides the base class getInstance method to use a GroupCacheHub
  -     * as the instance.
  +     * @see CacheHub#createInstance
        */
  -    public static synchronized CacheHub getInstance( String propFile )
  +    protected static CacheHub createInstance()
       {
  -        if ( instance == null )
  -        {
  -            log.debug( "Instance is null, creating" );
  -
  -            if ( propFile == null )
  -            {
  -                instance = new GroupCacheHub();
  -            }
  -            else
  -            {
  -                instance = new GroupCacheHub( propFile );
  -            }
  -        }
  -
  -        ( ( GroupCacheHub ) instance ).incrementClients();
  -
  -        return instance;
  -    }
  -
  -    /** Constructor for the GroupCacheHub object */
  -    protected GroupCacheHub()
  -    {
  -        super();
  +        return new GroupCacheHub();
       }
   
       /**
  -     * Constructor for the GroupCacheHub object
  -     *
  -     * @param propFile
  +     * @see CacheHub#createSystemCache
        */
  -    protected GroupCacheHub( String propFile )
  -    {
  -        super( propFile );
  -    }
  -
  -    /** Factory method to create the actual GroupCache instance. */
       protected Cache createSystemCache( String cacheName,
                                          ICache[] auxCaches,
                                          ICompositeCacheAttributes cattr,
  @@ -73,10 +36,12 @@
               ( ICompositeCache ) systemCaches.get( "groupIdCache" );
   
           return new GroupCache( cacheName, auxCaches, cattr, attr,
  -            systemGroupIdCache );
  +                               systemGroupIdCache );
       }
   
  -    /** */
  +    /**
  +     * @see CacheHub#createCache
  +     */
       protected Cache createCache( String cacheName,
                                    ICache[] auxCaches,
                                    ICompositeCacheAttributes cattr,
  @@ -86,6 +51,6 @@
               ( ICompositeCache ) systemCaches.get( "groupIdCache" );
   
           return new GroupCache( cacheName, auxCaches, cattr, attr,
  -            systemGroupIdCache );
  +                               systemGroupIdCache );
       }
   }
  
  
  

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

Reply via email to