head	1.18;
access;
symbols;
locks; strict;
comment	@# @;


1.18
date	2001.06.08.21.52.09;	author leonardr;	state Exp;
branches;
next	1.17;

1.17
date	2001.06.08.20.44.45;	author leonardr;	state Exp;
branches;
next	1.16;

1.16
date	2001.05.30.20.15.25;	author leonardr;	state Exp;
branches;
next	1.15;

1.15
date	2001.05.30.00.33.16;	author leonardr;	state Exp;
branches;
next	1.14;

1.14
date	2001.05.23.01.08.07;	author leonardr;	state Exp;
branches;
next	1.13;

1.13
date	2001.05.23.00.35.00;	author leonardr;	state Exp;
branches;
next	1.12;

1.12
date	2001.05.22.00.14.19;	author leonardr;	state Exp;
branches;
next	1.11;

1.11
date	2001.05.21.21.06.01;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2001.05.17.14.40.05;	author leonardr;	state Exp;
branches;
next	1.9;

1.9
date	2001.05.11.19.38.56;	author leonardr;	state Exp;
branches;
next	1.8;

1.8
date	2001.04.12.05.15.04;	author dlr;	state Exp;
branches;
next	1.7;

1.7
date	2001.04.12.02.08.26;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2001.04.12.01.34.42;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2001.04.12.01.15.49;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2001.04.07.01.32.11;	author dlr;	state Exp;
branches;
next	1.3;

1.3
date	2001.04.07.01.19.19;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2001.04.07.01.11.03;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.04.07.00.55.33;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.18
log
@Added ability for caches to keep track of number of invalidations.
@
text
@/* ================================================================
 * Copyright (c) 2001 CollabNet.  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 CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * 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 COLLABNET 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 CollabNet.
 */

package org.tigris.helm.tool.cache;

import java.rmi.RemoteException;
import org.apache.turbine.util.Log;

/**
 * Supplies automatic registration with this JVM's
 * {@@link org.tigris.helm.tool.cache.CacheRegistry}.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: RegisterableCache.java,v 1.17 2001/06/08 20:44:45 leonardr Exp $
 */
public abstract class RegisterableCache
{
    /**
     * Whether or not to log debugging information;
     */
    public static final boolean DEBUG = false;

    /**
     * A human-readable name for this cache.
     */ 
    private String name;    

    /**
     * The number of times this cache has been invalidated.
     */ 
    private long invalidations;

    /**
     * An array of Strings describing the descriptors in which this 
     * cache is interested;
     */ 
    private String[] interestingDescriptors;    

    /**
     * A constructor which registers this cache with the JVM's {@@link
     * org.tigris.helm.tool.cache.CacheRegistry} as being interested
     * in invalidations of the specified class.
     */
    public RegisterableCache(String name, Class interestingDescriptor)
    {
        Class[] interestingDescriptors = {interestingDescriptor};
        register(name, interestingDescriptors);
    }

    /**
     * A constructor which registers this cache with the JVM's {@@link
     * org.tigris.helm.tool.cache.CacheRegistry} as being interested
     * in invalidations of the specified classes.
     */
    public RegisterableCache(String name, Class[] interestingDescriptors)
    {
        register(name, interestingDescriptors);
    }

    /**
     * Registers this cache as being interested in invalidations of
     * the specified classes.
     */     
    public void register(String name, Class[] interestingDescriptors)
    {
        this.name = name;

        StringBuffer c = null;
        if (DEBUG)
        {
            c = new StringBuffer();
        }

        //Turn classes into strings corresponding to the class names.
        this.interestingDescriptors = 
            new String[interestingDescriptors.length];
        for (int i = 0; i < this.interestingDescriptors.length; i++)
        {
            String descriptor = interestingDescriptors[i].getName();
            if (DEBUG)
            {
                c.append(descriptor).append(" ");
            }
            this.interestingDescriptors[i] = descriptor;
        }

        if (DEBUG)
        {
            Log.debug("Registering cache: " + name 
                      + ", interested in the following descriptors: " 
                      + c.toString());
        }
        CacheRegistryService.getService().register(this);
    }

    /**
     * Detaches this cache from the registry.
     */     
    public void unregister()
    {
        interestingDescriptors = null;
        CacheRegistryService.getService().unregister(this);
    }

    /**
     * Describes this cache and its contents in a human-readable form.
     */ 
    public String describe()
    {
        StringBuffer buf = new StringBuffer("*** ").append(name)
            .append(" ***\n")
            .append(" Invalidated ").append(invalidations).append(" time")
            .append(invalidations==1 ? "" : "s").append(".\n")
            .append(" Interested in these descriptors:\n");
        for (int i = 0; i < interestingDescriptors.length; i++)
        {
            buf.append("  ").append(interestingDescriptors[i]).append("\n");
        }
        buf.append(describeContents());
        return buf.toString();
    }
    
    /**
     * Describes the contents of this cache in a human-readable form.
     */
    public abstract String describeContents();
    
    /**
     * Returns the human-readable name of the cache.
     */ 
    public String getName()
    {
        return name;
    }

    /**
     * Returns an array of descriptors which this cache finds interesting.
     */ 
    public String[] getInterestingDescriptors()
    {
        return interestingDescriptors;
    }

    /**
     * Invalidates the entire cache.
     */
    public void invalidate() 
        throws Exception
    {
        invalidations++;
    }
}
@


1.17
log
@Bugfixes and debugging cleanup.
@
text
@d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.16 2001/05/30 20:15:25 leonardr Exp $
d72 5
d85 1
a85 1
     * invalidations of the specified class.
d96 1
a96 1
     * invalidations of the specified classes.
d104 2
a105 1
     * Registers this cache as being interested in the specified
d155 2
d190 5
a194 1
    public abstract void invalidate() throws Exception;    
@


1.16
log
@Big cleanup of cache self-descriptions. Also added an admin tool to do manual selective cache invalidation.
@
text
@d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.15 2001/05/30 00:33:16 leonardr Exp $
d105 6
d116 6
a121 2
            this.interestingDescriptors[i] = 
                interestingDescriptors[i].getName();
d126 3
a128 3
            Log.debug("Registering cache: " + name);
            Log.debug(name + " is interested in: " 
                      + interestingDescriptors);
d182 1
a182 1
    public abstract void invalidate();
@


1.15
log
@Make the beginning of a descriptor more obvious.
@
text
@d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.14 2001/05/23 01:08:07 leonardr Exp $
d137 3
a139 3
        StringBuffer buf = new StringBuffer("*** Registerable cache ")
            .append(name).append(" ***\n")
            .append("Interested in these descriptors: ");
d142 1
a142 5
            if (i > 0)
            {
                buf.append(", ");
            }
            buf.append(interestingDescriptors[i]);
d144 1
a144 1
        buf.append("\n").append(describeContents());
@


1.14
log
@Added method to display the contents of every currently registered cache.
@
text
@d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.13 2001/05/23 00:35:00 leonardr Exp $
d137 2
a138 2
        StringBuffer buf = new StringBuffer("Registerable cache ")
            .append(name).append("\n")
@


1.13
log
@Cleanup of caching and cache invalidation.
@
text
@d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.12 2001/05/22 00:14:19 leonardr Exp $
d137 1
a137 1
        StringBuffer description = new StringBuffer("Registerable cache ")
d139 11
a149 4
            .append("Interested in these descriptors: ")
            .append(interestingDescriptors).append("\n")
            .append(describeContents());
        return description.toString();
@


1.12
log
@Bug fixes for clustering.
@
text
@d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.11 2001/05/21 21:06:01 leonardr Exp $
d61 3
d67 25
a91 2
     * Registers with this JVM's 
     * {@@link org.tigris.helm.tool.cache.CacheRegistry}.
d93 9
a101 1
    public RegisterableCache(String[] interestingDescriptors)
d103 11
d116 2
a117 1
            Log.debug("Registering a cache interested in: " 
d120 1
a120 1
        CacheRegistryService.getService().register(this, interestingDescriptors);
d123 4
a126 1
    public RegisterableCache(Class classToMonitor)
d128 2
a129 1
        this(makeArray(classToMonitor.getName()));
d132 4
a135 1
    public static String[] makeArray(String item)
d137 19
a155 2
        String[] items = {item};
        return items;
d158 4
a161 1
    public void unregister()
d163 1
a163 1
        CacheRegistryService.getService().unregister(this);
a167 1
     *
@


1.11
log
@Moved clustering features out of RMI and into the database.
@
text
@d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.10 2001/05/17 14:40:05 leonardr Exp $
a62 1

a73 1

a76 5
    public void unregister()
    {
        CacheRegistryService.getService().unregister(this);
    }

d86 5
@


1.10
log
@Added some useful debugging.
@
text
@a51 2
import org.tigris.helm.tool.cluster.ClusterObject;

d57 1
a57 1
 * @@version $Id: RegisterableCache.java,v 1.9 2001/05/11 19:38:56 leonardr Exp $
a62 1
    protected Object key;
d68 1
a68 2
    public RegisterableCache(Object key)
        throws RemoteException
d72 2
a73 1
            Log.debug("Registering the cache with key " + key.toString());
d76 1
a76 2
        this.key = key;
        CacheRegistry.getService().register(key, this);
d79 11
a89 7
    /**
     * Registers with this JVM's {@@link
     * org.tigris.helm.tool.cache.CacheRegistry}, using the provided
     * {@@link java.lang.Class} instance's name as the key. 
     */
    public RegisterableCache(Class c)
        throws RemoteException
d91 2
a92 1
        this(c.getName());
d96 1
a96 1
     * Invalidates some portion of the cache.
a97 3
     * @@param invalidationDescriptor Description of the invalidation that 
     *                               should occur, or <code>null</code> for
     *                               complete invalidation.
d99 1
a99 1
    public abstract void invalidate(Object invalidationDescriptor);
@


1.9
log
@A Heartbreaking Patch of Staggering Genius: adds capacity (but no interface) for deeply nested projects, categories, and project groups. As a side effect, gets rid of the hacky special 'all public projects in domain' group. There are probably bugs in this, and some of those bugs are probably security holes, so watch out.
@
text
@d50 1
d59 1
a59 1
 * @@version $Id: RegisterableCache.java,v 1.8 2001/04/12 05:15:04 dlr Exp $
d63 2
d74 5
@


1.8
log
@Holding a reference to the key used to register this cache with the mediator.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d55 1
a55 1
 * {@@link org.tigris.helm.tool.CacheRegistry}.
d58 1
a58 1
 * @@version $Id: RegisterableCache.java,v 1.7 2001/04/12 02:08:26 dlr Exp $
d65 2
a66 1
     * Registers with this JVM's {@@link org.tigris.helm.tool.CacheRegistry}.
d76 3
a78 2
     * Registers with this JVM's {@@link org.tigris.helm.tool.CacheRegistry},
     * using the provided {@@link java.lang.Class} instance's name as the key.
@


1.7
log
@Added addition ctor which extracts the specified Class's name to use
as the cache key.
@
text
@d58 1
a58 1
 * @@version $Id: RegisterableCache.java,v 1.6 2001/04/12 01:34:42 dlr Exp $
d62 2
d70 1
@


1.6
log
@Use a key other than Class.
@
text
@d58 1
a58 1
 * @@version $Id: RegisterableCache.java,v 1.5 2001/04/12 01:15:49 dlr Exp $
d69 10
@


1.5
log
@Make use of Service-style API.
@
text
@d58 1
a58 1
 * @@version $Id: RegisterableCache.java,v 1.4 2001/04/07 01:32:11 dlr Exp $
d65 1
a65 1
    public RegisterableCache(Class key)
@


1.4
log
@Changed invalidate() to be abstract.
@
text
@d58 1
a58 1
 * @@version $Id: RegisterableCache.java,v 1.3 2001/04/07 01:19:19 dlr Exp $
d68 1
a68 2
        CacheRegistry registry = CacheRegistry.getInstance();
        registry.register(key, this);
@


1.3
log
@Corrected ctor to get the CacheRegistry specific to this JVM, rather
than to this cluster.
@
text
@d58 1
a58 1
 * @@version $Id: RegisterableCache.java,v 1.2 2001/04/07 01:11:03 dlr Exp $
d79 1
a79 4
    public void invalidate(Object invalidationDescriptor)
    {
        // TODO
    }
@


1.2
log
@Added ctor implementation.
@
text
@d58 1
a58 1
 * @@version $Id: RegisterableCache.java,v 1.1 2001/04/07 00:55:33 dlr Exp $
a62 6
     * RMI URL fragment to the registry.
     */
    public static final String REGISTRY_URL =
        "org.tigris.helm.tool.cache.CacheRegistry";

    /**
d68 1
a68 2
        CacheRegistry registry =
            (CacheRegistry) ClusterObject.get(REGISTRY_URL);
@


1.1
log
@Supplies automatic registration with this JVM's CacheRegistry.
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d49 4
d58 1
a58 1
 * @@version $Id: $
d60 1
a60 1
public abstract class RegisteredCache
d63 6
d71 2
a72 1
    public RegisteredCache()
d74 3
a76 1
        // TODO
@

