org/objectweb/proactive/core/group/spmd/ProActiveSPMDGroupManager.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.group.spmd;
00032 
00033 import java.util.HashMap;
00034 import java.util.Iterator;
00035 import java.util.LinkedList;
00036 
00037 
00041 public class ProActiveSPMDGroupManager implements java.io.Serializable {
00042 
00046     private Object spmdGroup = null;
00047 
00053     private HashMap currentBarriers = new HashMap(4); // initial capacity is 4.
00054 
00060     private LinkedList barrierTags = new LinkedList();
00061 
00066     public void setSPMDGroup(Object o) {
00067         this.spmdGroup = o;
00068     }
00069 
00074     public Object getSPMDGroup() {
00075         return this.spmdGroup;
00076     }
00077 
00082     public void addToBarrierTags(String barrierID) {
00083         if (!this.barrierTags.contains(barrierID)) {
00084             this.barrierTags.add(barrierID);
00085         }
00086     }
00087 
00093     public BarrierState getBarrierStateFor(String barrierName) {
00094         return (BarrierState) this.currentBarriers.get(barrierName);
00095     }
00096 
00102     public void setAwaitedBarrierCalls(String barrierName, int nbCalls) {
00103         BarrierState bs = (BarrierState) this.currentBarriers.get(barrierName);
00104         if (bs == null) {
00105             // System.out.println("First barrier \"" + this.getIDName() + "\" encountered !");
00106             // build and add infos about new barrier
00107             bs = new BarrierState();
00108             this.addToCurrentBarriers(barrierName, bs);
00109         }
00110         bs.setAwaitedCalls(nbCalls);
00111     }
00112 
00118     public void addToCurrentBarriers(String barrierName, BarrierState bs) {
00119         this.currentBarriers.put(barrierName, bs);
00120     }
00121 
00127     public void remove(String barrierName) {
00128         // stop tagging the outgoing message
00129         this.barrierTags.remove(barrierName);
00130         // remove the barrier from the current active barriers list
00131         this.currentBarriers.remove(barrierName);
00132     }
00133 
00138     public boolean isTagsListEmpty() {
00139         return (this.barrierTags.size() == 0);
00140     }
00141 
00146     public LinkedList getBarrierTags() {
00147         return this.barrierTags;
00148     }
00149 
00156     public boolean checkExecution(LinkedList barrierTags) {
00157         if (barrierTags == null) {
00158             return true;
00159         }
00160         Iterator it = barrierTags.iterator();
00161         while (it.hasNext()) {
00162             if (this.currentBarriers.get((String) it.next()) != null) {
00163                 return false;
00164             }
00165         }
00166         return true;
00167     }
00168 
00173     public boolean isCurrentBarriersEmpty() {
00174         return (this.currentBarriers.size() == 0);
00175     }
00176 }

Generated on Mon Jan 22 15:16:08 2007 for ProActive by  doxygen 1.5.1