001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ha.framework.interfaces;
023:
024: import java.util.ArrayList;
025: import java.util.Hashtable;
026:
027: /**
028: * JVM singleton that associates a list of targets (+ other info)
029: * contained in a FamilyClusterInfo to a proxy family. For example
030: * All remote proxies for a given EJB in a given cluster are part of the
031: * same proxy family. Note that home and remote for a same EJB form *2*
032: * proxy families.
033: *
034: * @see org.jboss.ha.framework.interfaces.FamilyClusterInfo
035: * @see org.jboss.ha.framework.interfaces.FamilyClusterInfoImpl
036: *
037: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
038: * @version $Revision: 57188 $
039: *
040: * <p><b>Revisions:</b>
041: *
042: * <p><b>2002/08/23, Sacha Labourey:</b>
043: * <ul>
044: * <li> First implementation </li>
045: * </ul>
046: */
047:
048: public class ClusteringTargetsRepository {
049: // Constants -----------------------------------------------------
050:
051: // Attributes ----------------------------------------------------
052:
053: protected static Hashtable families = new Hashtable();
054:
055: // Static --------------------------------------------------------
056:
057: public synchronized static FamilyClusterInfo initTarget(
058: String familyName, ArrayList targets) {
059: return initTarget(familyName, targets, 0L);
060: }
061:
062: public synchronized static FamilyClusterInfo initTarget(
063: String familyName, ArrayList targets, long viewId) {
064: // this method must be somehow synchronized to avoid multiple FamilyClusterInfoImpl
065: // for the same familyName in multi-threaded app accessing the same bean
066: //
067: FamilyClusterInfoImpl family = (FamilyClusterInfoImpl) families
068: .get(familyName);
069: if (family == null) {
070: family = new FamilyClusterInfoImpl(familyName, targets,
071: viewId);
072: families.put(familyName, family);
073: } else {
074: // no need to initialize: it is already done: we keep the same object
075: //
076: family.updateClusterInfo(targets, viewId); // should not happen: possible if redeploy after undeploy fails
077: }
078:
079: return family;
080:
081: }
082:
083: public static FamilyClusterInfo getFamilyClusterInfo(
084: String familyName) {
085: return (FamilyClusterInfo) families.get(familyName);
086: }
087:
088: // Constructors --------------------------------------------------
089:
090: private ClusteringTargetsRepository() {
091: }
092:
093: // Public --------------------------------------------------------
094:
095: // Z implementation ----------------------------------------------
096:
097: // Y overrides ---------------------------------------------------
098:
099: // Package protected ---------------------------------------------
100:
101: // Protected -----------------------------------------------------
102:
103: // Private -------------------------------------------------------
104:
105: // Inner classes -------------------------------------------------
106:
107: }
|