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


1.16
date	2001.05.18.21.56.26;	author leonardr;	state dead;
branches;
next	1.15;

1.15
date	2001.05.09.21.07.56;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2001.04.11.22.54.46;	author dlr;	state Exp;
branches;
next	1.13;

1.13
date	2001.04.11.22.42.58;	author dlr;	state Exp;
branches;
next	1.12;

1.12
date	2001.04.11.12.25.45;	author dlr;	state Exp;
branches;
next	1.11;

1.11
date	2001.04.11.11.23.17;	author dlr;	state Exp;
branches;
next	1.10;

1.10
date	2001.04.11.11.00.20;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2001.04.11.10.55.43;	author dlr;	state Exp;
branches;
next	1.8;

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

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

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

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

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

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

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

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


desc
@@


1.16
log
@Fixed up cluster singleton interface and made the task runner into a cluster singleton.
@
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" or
 * "Helm" names nor may "Tigris" or "Helm" 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.task;

import java.util.Map;
import java.util.Hashtable;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import org.apache.turbine.util.Log;

import org.tigris.helm.tool.cluster.BaseClusterSingletonMediator;
import org.tigris.helm.tool.cluster.ClusteredColleague;
import org.tigris.helm.tool.cluster.ClusteredSingletonColleague;
import org.tigris.helm.tool.cluster.MediatedEvent;
import org.tigris.helm.tool.cluster.PollEvent;
import org.tigris.helm.tool.cluster.PollTarget;

/**
 * Enforces the existance of one and only one operational task runner thread.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 */
public class TaskRunnerMediator extends BaseClusterSingletonMediator
    implements TaskRunnerMediatorSpec
{
    /**
     * The key used to reference a remote instance of this class.
     */
    public static final String CLUSTER_KEY = "org.tigris.helm.tool.task";

    public TaskRunnerMediator()
        throws RemoteException
    {
    }
}
@


1.15
log
@Added cross JVM single for denormalizing project graph database tables.
@
text
@@


1.14
log
@Implement the right Remote interface!
@
text
@d57 1
a57 1
import org.tigris.helm.tool.cluster.ClusterSingletonMediator;
d70 1
a70 1
public class TaskRunnerMediator extends UnicastRemoteObject
a77 2
    private PollTarget singletonPoll;

a80 71
        singletonPoll = null;
    }

    public synchronized void register(ClusteredColleague colleague)
        throws RemoteException
    {
        try
        {
            if (getSingleton() == null)
            {
                // singletonPoll must be set before setAsSingleton() will work
                singletonPoll = new PollTarget(colleague);
                ((ClusteredSingletonColleague) colleague).setAsSingleton();
                Log.debug("TaskRunnerMediator registered collague as " +
                          "singleton");
            }
            else
            {
                Log.debug("TaskRunnerMediator already registered a singleton");
            }
        }
        catch (Exception e)
        {
            Log.error(e);
            throw new RemoteException("Error registering colleague with " +
                                      "TaskRunnerMediator: " + e.getMessage());
        }
    }

    public final void unregister(ClusteredColleague colleague)
        throws RemoteException
    {
        if (colleague == getSingleton())
        {
            singletonPoll = null;
        }        
    }

    public void handleEvent(MediatedEvent event)
        throws RemoteException
    {
        if (event instanceof PollEvent)
        {
            // Extract the answering colleague and handle its poll response.
            ClusteredSingletonColleague singleton = getSingleton();
            synchronized (singleton)
            {
                if (((PollEvent) event).getSource() == singleton)
                {
                    singletonPoll.setTimePolledAt(PollTarget.NOT_WAITING);
                }
            }
        }
        else
        {
            Log.warn("Unhandled cluster event sent to TaskRunnerMediator: " +
                     event.toString());
        }
    }

    public void sendEvent(MediatedEvent event)
        throws RemoteException
    {
        getSingleton().handleEvent(event);
    }

    public final ClusteredSingletonColleague getSingleton()
        throws RemoteException
    {
        return (singletonPoll == null ? null :
                (ClusteredSingletonColleague) singletonPoll.getTarget());
@


1.13
log
@Catch Exception instead of Throwable to miss Errors, and log stack
traces to the Turbine log file.
@
text
@d71 1
a71 1
    implements ClusterSingletonMediator
@


1.12
log
@Refactored register(ClusteredColleague) to make it more robust.
@
text
@d104 1
a104 1
        catch (Throwable t)
d106 1
d108 1
a108 1
                                      "TaskRunnerMediator: " + t.getMessage());
@


1.11
log
@Corrected getSingleton() method to handle null pointer.
@
text
@d89 1
a89 1
        if (getSingleton() == null)
d91 17
a107 3
            ((ClusteredSingletonColleague) colleague).setAsSingleton();
            singletonPoll = new PollTarget(colleague);
            Log.debug("TaskRunnerMediator registered collague as singleton");
@


1.10
log
@Don't call getSingleton() more times than necessary.
@
text
@d93 1
d137 2
a138 1
        return (ClusteredSingletonColleague) singletonPoll.getTarget();
@


1.9
log
@Removed a couple unnecessary lines of code.
@
text
@d111 2
a112 1
            synchronized (getSingleton())
d114 1
a114 1
                if (((PollEvent) event).getSource() == getSingleton())
@


1.8
log
@* Added a couple imports.

* Changed from storing a ClusteredSingletonColleague reference to
storing a PollTarget reference which in turn contains the singleton
reference.

* Revamped getSingleton() to do the right thing and used it everywhere
to get the singleton reference.

* Initial mplementation of handleEvent().
@
text
@d113 1
a113 3
                ClusteredColleague polled =
                    (ClusteredColleague) ((PollEvent) event).getSource();
                if (polled == getSingleton())
@


1.7
log
@Added CLUSTER_KEY constant for use during RMI lookups.
@
text
@d55 2
d61 2
d78 1
a78 1
    private ClusteredSingletonColleague singleton;
d83 1
a83 1
        singleton = null;
d86 1
a86 1
    public void register(ClusteredColleague colleague)
d89 1
a89 1
        if (singleton == null)
d91 2
a92 2
            singleton = (ClusteredSingletonColleague) colleague;
            singleton.setAsSingleton();
d99 1
a99 1
        if (singleton == colleague)
d101 1
a101 1
            singleton = null;
d108 18
a125 1
        // TODO
d131 1
a131 1
        singleton.handleEvent(event);
d137 1
a137 1
        return singleton;
@


1.6
log
@Extended java.rmi.server.UnicastRemoteObject, the class defining a
non-replicated remote object whose references are valid only while the
server process is alive.
@
text
@d69 5
@


1.5
log
@Made unregister(ClusteredColleague) final.
@
text
@d53 1
d66 2
a67 1
public class TaskRunnerMediator implements ClusterSingletonMediator
d70 6
@


1.4
log
@Made ClusteredSingletonColleague() final.
@
text
@d79 1
a79 1
    public void unregister(ClusteredColleague colleague)
@


1.3
log
@Replaced SingletonRecognitionEvent with ClusteredSingletonColleage.setAsSingleton.
@
text
@d100 1
a100 1
    public ClusteredSingletonColleague getSingleton()
@


1.2
log
@Added unregister method to interface.
@
text
@d75 1
a75 1
            //TODO: send a SingletonRecognitionEvent.
d84 1
a84 1
            //TODO
@


1.1
log
@Cross JVM communication services.
@
text
@d72 14
a85 1
        singleton = (ClusteredSingletonColleague) colleague;
@

