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


1.2
date	2001.05.21.21.06.01;	author leonardr;	state dead;
branches;
next	1.1;

1.1
date	2001.05.11.19.38.56;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Moved clustering features out of RMI and into the database.
@
text
@/* ================================================================
 * Copyright (c) 2000-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.tool.cluster.*;

/**
 * Denormalizes the project graph database tables.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: BaseClusterSingletonColleague.java,v 1.1 2001/05/11 19:38:56 leonardr Exp $
 */
public abstract class BaseClusterSingletonColleague 
    extends BaseUnicastRemoteService implements ClusteredColleague
{
    /**
     * The name of this service.  Used to retrive it from the broker.
     */
    public static final String SERVICE_NAME = "";

    /**
     * Whether or not this instance is the singleton.
     */
    private boolean isSingleton;

    /**
     * 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 BaseClusterSingletonColleague getService()
    {
        return (BaseClusterSingletonColleague)TurbineServices
            .getInstance().getService
            (ProjectGraphDenormalizerService.SERVICE_NAME);
    }

    public BaseClusterSingletonColleague()
        throws RemoteException
    {
        isSingleton = false;
    }

    /**
     * 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);
            Log.debug("Stack trace:", e);
        }
    }

    /**
     * Register with the Mediator. A SingletonRecognitionEvent may be
     * sent to me in response.
     */
    public void register()
        throws RemoteException
    {
        try
        {
            Log.debug(SERVICE_NAME + ": Attempting registration w/ mediator");
            getMediator().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)
        {
            //Respond to a poll event with proof of life.
            PollEvent e = new PollEvent(this, event);
            sendEvent(e);
        }
    }

    /**
     * This instance of the service is now in charge of running the
     * thread.
     */
    public final void setAsSingleton()
        throws RemoteException
    {
        isSingleton = true;
    }

    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, stopping the task running thread.
     */
    public final void shutdown()
    {
        setInit(false);
        try
        {
            unregister();
        }
        catch (Exception e)
        {
            Log.error(SERVICE_NAME + ": Task runner shutdown failed", e);
        }

    }

    /**
     * Macro to retrieve the cluster's mediator.
     */
    private final ProjectGraphDenormalizerMediatorSpec getMediator()
        throws RemoteException
    {
        return (ProjectGraphDenormalizerMediatorSpec) ClusterObject.get
            (ProjectGraphDenormalizerMediator.CLUSTER_KEY);
    }

    /**
     * Macro to retrieve the cluster's singleton.
     */
    private final ProjectGraphDenormalizerServiceSpec getSingleton()
        throws RemoteException
    {
        return (ProjectGraphDenormalizerServiceSpec)
            getMediator().getSingleton();
    }
}
@


1.1
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
@d64 1
a64 1
 * @@version $Id: ProjectGraphDenormalizerService.java,v 1.1 2001/05/09 21:07:55 dlr Exp $
@

