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


1.7
date	2001.05.30.01.11.12;	author leonardr;	state dead;
branches;
next	1.6;

1.6
date	2001.05.22.20.35.14;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2001.05.22.00.14.19;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2001.05.21.21.06.01;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.05.17.14.51.17;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.05.11.19.38.55;	author leonardr;	state Exp;
branches;
next	1.1;

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


desc
@@


1.7
log
@Got rid of denormalized project-project group mapping table in favor of per-JVM caching solution.
@
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.acl;

import java.util.*;
import java.rmi.RemoteException;
import javax.servlet.ServletConfig;

import org.apache.turbine.services.*;
import org.apache.turbine.util.Log;

import org.tigris.helm.om.*;
import org.tigris.helm.tool.cluster.*;
import org.tigris.helm.tool.cache.*;

/**
 * In charge of ensuring that only one ProjectGraphDenormalizer cache
 * is running at any one time.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: ProjectGraphDenormalizerService.java,v 1.6 2001/05/22 20:35:14 leonardr Exp $ 
 */
public class ProjectGraphDenormalizerService extends ClusteredSingletonService
    implements Runnable
{
    /**
     * Whether or not to log debugging information
     */
    private static final boolean DEBUG = false;

    /**
     * The name of this service.  Used to retrive it from the broker.
     */
    public static final String SERVICE_NAME =
        "ProjectGraphDenormalizerService";

    /**
     * Descriptor for this singleton's timestamp event.
     */
    public final String getDescriptor()
    {
        return SERVICE_NAME;
    }

    /**
     * The cache which will be set up and registered when this service
     * becomes the singleton.
     */
    private ProjectGraphDenormalizer cache;

    /**
     * A wrapper method for getting the single instance of this
     * service from the Turbine services list.
     *
     * @@return Turbine's single instance of this service.
     */
    public static final ProjectGraphDenormalizerService getService()
    {
        return (ProjectGraphDenormalizerService)TurbineServices
            .getInstance().getService
            (ProjectGraphDenormalizerService.SERVICE_NAME);
    }

    /**
     * Constructor; initialize to not being the singleton.
     */
    public ProjectGraphDenormalizerService()
    {
        isSingleton = false;
    }

    /**
     * Run every time this service reasserts itself as the singleton.
     */
    public final void doService()
        throws Exception
    {
        if (cache == null)
        {
            cache = new ProjectGraphDenormalizer();
        }

        if (DenormalizedProjectProjectgroupPeer.itemsInTable()==0)
        {
            cache.rebuildDenormalizedTable();
        }
    }

    protected void releaseSingleton()
        throws Exception
    {
        super.releaseSingleton();
        cache.unregister();
        cache = null;
    }

}
@


1.6
log
@Got rid of debugging.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectGraphDenormalizerService.java,v 1.5 2001/05/22 00:14:19 leonardr Exp $ 
@


1.5
log
@Bug fixes for clustering.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectGraphDenormalizerService.java,v 1.4 2001/05/21 21:06:01 leonardr Exp $ 
a123 2
        Log.debug("ProjectGraphDenormalizerService " + " doService");
        Log.debug(String.valueOf(DenormalizedProjectProjectgroupPeer.itemsInTable()) + " items in table.");
a125 1
            Log.debug("!!!!!Creating denormalizer.");
a126 1
            Log.debug("Created.");
a130 1
            Log.debug("!!!!Creating denormalized table.");
a132 1
        Log.debug("Done.");
@


1.4
log
@Moved clustering features out of RMI and into the database.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectGraphDenormalizerService.java,v 1.3 2001/05/17 14:51:17 leonardr Exp $ 
d70 1
a113 1
        throws RemoteException
d122 1
a122 1
        throws RemoteException
d124 2
a125 1
        isSingleton = true;
d128 1
d130 1
d133 1
a133 8
        try
        {
            if (DenormalizedProjectProjectgroupPeer.itemsInTable()==0)
            {
                cache.rebuildDenormalizedTable();
            }
        }
        catch (Exception e)
d135 2
a136 3
            throw new Error
                ("Attempt to make initial build of denormalized table failed: "
                 + e.getMessage());
d138 1
a144 1
        //TODO: Unregister the cache.
@


1.3
log
@Refactored a lot of code to get rid of the good-looking but very slow IssueTrackingAccount{Descriptor,Map} classes. Also cleaned up the script-running interface quite a bit.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectGraphDenormalizerService.java,v 1.2 2001/05/11 19:38:55 leonardr Exp $ 
d69 1
a69 2
public class ProjectGraphDenormalizerService extends BaseUnicastRemoteService
    implements ProjectGraphDenormalizerServiceSpec
d72 5
d83 1
a83 1
     * Whether or not this instance is the singleton.
d85 4
a88 1
    private boolean isSingleton;
d91 1
a91 1
     * The cache which will be set up and registered if this service
d109 3
d119 1
a119 22
     * Called during <code>Turbine.init()</code> (i.e. early initialization).
     *
     * @@param config The configuration we're operating under.
     */
    public void init(ServletConfig config)
        throws InitializationException
    {
        try 
        {
            register();
            setInit(true);
        }
        catch (RemoteException e)
        {
            Log.error(SERVICE_NAME + " registration with cluster mediator " +
                      "failed", e);
        }
    }

    /**
     * Register with the Singleton Mediator. My setAsSingleton()
     * method may be called in response.
d121 1
a121 1
    public void register()
d124 2
a125 30
        try
        {
            Log.debug(SERVICE_NAME + ": Attempting registration w/ mediator");
            ProjectGraphDenormalizerMediatorSpec mediator = getMediator();
            mediator.register(this);
        }
        catch (Exception e)
        {
            Log.error(e);
            throw new RemoteException(SERVICE_NAME + ": Registration with " +
                                      "mediator failed: " + e.getMessage());
        }
    }

    /**
     * Unregister with the Mediator. 
     */
    public void unregister()
        throws RemoteException
    {
        getMediator().unregister(this);
    }

    /**
     * Handle a recieved event.
     */
    public void handleEvent(MediatedEvent event)
        throws RemoteException
    {
        if (event instanceof PollEvent)
d127 1
a127 3
            //Respond to a poll event with proof of life.
            PollEvent e = new PollEvent(this, event);
            sendEvent(e);
a128 1
    }            
a129 11
    /**
     * Make this instance of the service in charge of invalidating the
     * database cache.
     */
    public final void setAsSingleton()
        throws RemoteException
    {
        isSingleton = true;
        cache = new ProjectGraphDenormalizer();

        //Possibly gate this so that the table is only built if empty.
d132 4
a135 1
            cache.rebuildDenormalizedTable();
d145 2
a146 37
    public final boolean isSingleton()
        throws RemoteException
    {
        return isSingleton;
    }

    /**
     * Send an event to the mediator.
     */
    public void sendEvent(MediatedEvent event)
        throws RemoteException
    {
        getMediator().handleEvent(event);
    }

    /**
     * Shuts down this service.
     */
    public final void shutdown()
    {
        setInit(false);
        try
        {
            unregister();
        }
        catch (Exception e)
        {
            Log.error(SERVICE_NAME + ": Denormalization service failed", e);
        }

    }

    /**
     * Macro to retrieve the cluster's mediator.
     */
    private final ProjectGraphDenormalizerMediatorSpec getMediator()
        throws RemoteException
d148 4
a151 4
        ProjectGraphDenormalizerMediatorSpec mediator =
         (ProjectGraphDenormalizerMediatorSpec) ClusterObject.get
            (ProjectGraphDenormalizerMediator.CLUSTER_KEY);
        return mediator;
a153 9
    /**
     * Macro to retrieve the cluster's singleton.
     */
    private final ProjectGraphDenormalizerServiceSpec getSingleton()
        throws RemoteException
    {
        return (ProjectGraphDenormalizerServiceSpec)
            getMediator().getSingleton();
    }
@


1.2
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
@d67 1
a67 1
 * @@version $Id: ProjectGraphDenormalizerService.java,v 1.1 2001/05/09 21:07:55 dlr Exp $ 
a124 1
            Log.debug("Stack trace:", e);
d138 2
a139 1
            getMediator().register(this);
a180 1
        CacheRegistry.getService().register(getClass(), cache);
d233 2
a234 1
        return (ProjectGraphDenormalizerMediatorSpec) ClusterObject.get
d236 1
@


1.1
log
@Added cross JVM single for denormalizing project graph database tables.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d57 1
d59 1
d62 2
a63 1
 * Denormalizes the project graph database tables.
d67 1
a67 1
 * @@version $Id: TaskRunnerService.java,v 1.24 2001/05/02 19:22:53 dlr Exp $
d78 3
d84 6
d130 2
a131 2
     * Register with the Mediator. A SingletonRecognitionEvent may be
     * sent to me in response.
d170 1
a170 1
    }
d173 2
a174 2
     * This instance of the service is now in charge of running the
     * thread.
d180 14
d212 1
a212 1
     * Shuts down this service, stopping the task running thread.
d223 1
a223 1
            Log.error(SERVICE_NAME + ": Task runner shutdown failed", e);
@

