org/objectweb/proactive/core/component/collectiveitfs/GatherFuturesHandler.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.component.collectiveitfs;
00032 
00033 import java.io.Serializable;
00034 import java.util.List;
00035 
00036 import org.objectweb.proactive.Body;
00037 import org.objectweb.proactive.ProActive;
00038 import org.objectweb.proactive.RunActive;
00039 import org.objectweb.proactive.Service;
00040 import org.objectweb.proactive.core.body.future.FutureResult;
00041 import org.objectweb.proactive.core.body.migration.MigrationException;
00042 import org.objectweb.proactive.core.body.request.Request;
00043 import org.objectweb.proactive.core.body.request.RequestFilter;
00044 import org.objectweb.proactive.core.component.representative.ItfID;
00045 import org.objectweb.proactive.core.exceptions.manager.ExceptionThrower;
00046 import org.objectweb.proactive.core.node.Node;
00047 
00092 public class GatherFuturesHandler implements RunActive, Serializable {
00093     List<ItfID> senders;
00094     List<?> resultOfGatheredInvocation;
00095     Throwable exceptionToRaise;
00096     String methodName = null;
00097     int step = 0;
00098     
00099     public GatherFuturesHandler() {
00100     }
00101   
00102     public void setFutureOfGatheredInvocation(FutureResult future) {
00103         if (future.getExceptionToRaise() != null) {
00104             exceptionToRaise = future.getExceptionToRaise();
00105         } else {
00106             // no cast for futures ==> need to get the result before casting
00107             resultOfGatheredInvocation = (List<?>) future.getResult();
00108             ProActive.waitFor(resultOfGatheredInvocation);
00109         }
00110     }
00111 
00112     // returns
00113     public Object distribute(ItfID sender) {
00114         if (exceptionToRaise != null) {
00115             ExceptionThrower.throwException(exceptionToRaise); // guillaume's exception thrower
00116         }
00117 
00118         // redistribution policies for results can be applied here
00119         return resultOfGatheredInvocation.get(senders.indexOf(sender));
00120     }
00121 
00122     public void migrateTo(Node node) throws MigrationException {
00123         ProActive.migrateTo(node);
00124     }
00125 
00126     public void setConnectedClientItfs(List<ItfID> connectedClientItfs) {
00127         senders = connectedClientItfs;
00128     }
00129 
00130     public void setMethodName(String methodName) {
00131         this.methodName = methodName;
00132     }
00133     
00134     public void passivate() {
00135         senders = null;
00136         methodName = null;
00137     }
00138     
00139     
00140     
00141 
00142     public void runActivity(Body body) {
00143         Service service = new Service(body);
00144         while (ProActive.getBodyOnThis().isActive()) {
00145             service.blockingServeOldest("setConnectedClientItfs");
00146             
00147             service.blockingServeOldest("setFutureOfGatheredInvocation");
00148             int i = 1;
00149             for (ItfID senderID : senders) {
00150                 service.blockingServeOldest("distribute");
00151                 i++;
00152             }
00153             
00154             service.blockingServeOldest("passivate");
00155             
00156         }
00157     }
00158 
00159 
00160 }

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