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


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

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

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

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

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

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

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

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

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

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

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


desc
@@


1.11
log
@Moved clustering features out of RMI and into the database.
@
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.cluster;

import java.rmi.Naming;
import java.rmi.RemoteException;

import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.TurbineException;

/**
 * Encapsulates object lookups in a cluster.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 */
public class ClusterObject
{
    /**
     * Returns a reference to an object in the cluster.  Currently
     * does a RMI lookup under the covers.
     *
     * @@param urlSnippet The URL snippet correspding to the desired
     *                   object (<i>without</i> the port number).
     *
     * @@exception TurbinException Object not bound, or other problem.
     */
    public static Object get(String urlSnippet)
        throws RemoteException
    {
        try
        {
            return Naming.lookup(getLookupURL(urlSnippet));
        }
        catch (Exception e)
        {
            throw new RemoteException("Cluster object lookup failed", e);
        }
    }

    /**
     * Returns a reference to an object in the cluster.  Currently
     * does a RMI lookup under the covers.
     *
     * @@param urlSnippet The URL snippet correspding to the desired
     *                   object (<i>without</i> the port number).
     *
     * @@exception TurbinException Object not bound, or other problem.
     */
    public static String[] list (String urlSnippet)
        throws RemoteException
    {
        try
        {
            return Naming.list(getLookupURL(urlSnippet));
        }
        catch (Exception e)
        {
            throw new RemoteException("Cluster list lookup failed", e);
        }
    }

    /**
     * Returns a lookup URL corresponding to the provided URL snippet.
     *
     * @@return The lookup URL.
     */
    public static final String getLookupURL(String urlSnippet)
    {
        String host = ClusterService.getMediatorHost();
        if (!StringUtils.isValid(host))
        {
            host = "localhost";
        }
        return ("rmi://" + host + ':' + getPort() + '/' + urlSnippet);
    }

    /**
     * Returns the port for this cluster's RMI registry.
     */
    private static final int getPort()
    {
        return ClusterService.getRMIRegistryPort();
    }
}
@


1.10
log
@Fixed up cluster singleton interface and made the task runner into a cluster singleton.
@
text
@@


1.9
log
@Use the method that already encapsulates this functionality.
@
text
@d86 22
@


1.8
log
@More informative error message.
@
text
@d52 1
d93 1
a93 1
        if (host == null || host.equals(""))
@


1.7
log
@Now creating a properly formed URL!
@
text
@d80 1
a80 1
            throw new RemoteException("Lookup failed", e);
@


1.6
log
@Refactored URL creation into separate method.
@
text
@d96 1
a96 1
        return ("rmi://" + host + '/' + urlSnippet + ':' + getPort());
@


1.5
log
@Properly address the RMI registry.
@
text
@a73 6
        String host = ClusterService.getMediatorHost();
        if (host == null || host.equals(""))
        {
            host = "localhost";
        }

d76 1
a76 2
            return Naming.lookup("rmi://" + host + '/' + urlSnippet + ':' +
                                 getPort());
d82 15
@


1.4
log
@Oops, wrong constructor.
@
text
@d74 6
d82 2
a83 1
            return Naming.lookup("rmi://localhost/" + urlSnippet + getPort());
d92 1
a92 1
     * TODO
d94 1
a94 1
    private static final String getPort()
d96 1
a96 1
        return "";
@


1.3
log
@Throw RemoteException instead.
@
text
@d80 1
a80 1
            throw new RemoteException(e);
@


1.2
log
@Corrected package name.
@
text
@d72 1
a72 1
        throws TurbineException
d80 1
a80 1
            throw new TurbineException(e);
@


1.1
log
@Encapsulates object lookups in a cluster.
@
text
@d47 1
a47 1
package org.tigris.helm.tool.cache;
@

