org/objectweb/proactive/core/group/ProcessForAsyncCall.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;
00032 
00033 import java.util.Vector;
00034 
00035 import org.objectweb.proactive.Body;
00036 import org.objectweb.proactive.core.body.LocalBodyStore;
00037 import org.objectweb.proactive.core.body.proxy.UniversalBodyProxy;
00038 import org.objectweb.proactive.core.component.ProActiveInterface;
00039 import org.objectweb.proactive.core.component.representative.ProActiveComponentRepresentative;
00040 import org.objectweb.proactive.core.mop.MethodCall;
00041 import org.objectweb.proactive.core.mop.Proxy;
00042 import org.objectweb.proactive.core.mop.StubObject;
00043 
00044 
00050 public class ProcessForAsyncCall extends AbstractProcessForGroup
00051     implements Runnable {
00052     private Vector memberListOfResultGroup;
00053     private int index;
00054     private MethodCall mc;
00055     private Body body;
00056 
00057     public ProcessForAsyncCall(ProxyForGroup proxyGroup, Vector memberList,
00058         Vector memberListOfResultGroup, int index, MethodCall mc, Body body) {
00059         this.proxyGroup = proxyGroup;
00060         this.memberList = memberList;
00061         this.memberListOfResultGroup = memberListOfResultGroup;
00062         this.index = index;
00063         this.mc = mc;
00064         this.body = body;
00065     }
00066 
00067     public void run() {
00068         Object object = this.memberList.get(this.index);
00069         LocalBodyStore.getInstance().setCurrentThreadBody(body);
00070         boolean objectIsLocal = false;
00071 
00072         /* only do the communication (reify) if the object is not an error nor an exception */
00073         if (!(object instanceof Throwable)) {
00074             try {
00075                 if (object instanceof ProActiveComponentRepresentative) {
00076                     // delegate to the corresponding interface
00077                     Object target;
00078                     if (mc.getComponentMetadata().getComponentInterfaceName() == null) {
00079                         // a call on the Component interface
00080                         target = object;
00081                     } else {
00082                         target = ((ProActiveComponentRepresentative) object).getFcInterface(mc.getComponentMetadata().getComponentInterfaceName());
00083                     }
00084                     this.proxyGroup.addToListOfResult(memberListOfResultGroup,
00085                         this.mc.execute(target), this.index);
00086                 } else if (object instanceof ProActiveInterface) {
00087                     this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
00088                         this.mc.execute(object), this.index);
00089                 } else {
00090                     Proxy lastProxy = AbstractProcessForGroup.findLastProxy(object);
00091                     if (lastProxy instanceof UniversalBodyProxy) {
00092                         objectIsLocal = ((UniversalBodyProxy) lastProxy).isLocal();
00093                     }
00094                     if (lastProxy == null) {
00095                         // means we are dealing with a standard Java Object 
00096                         this.proxyGroup.addToListOfResult(memberListOfResultGroup,
00097                             this.mc.execute(object), this.index);
00098                     } else if (!objectIsLocal) {
00099 
00100                         /* add the return value into the result group */
00101                         this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
00102                             ((StubObject) object).getProxy().reify(this.mc),
00103                             this.index);
00104                     } else {
00105 
00106                         /* add the return value into the result group */
00107                         this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
00108                             ((StubObject) object).getProxy().reify(new MethodCall(
00109                                     this.mc)), this.index);
00110                     }
00111                 }
00112             } catch (Throwable e) {
00113 
00114                 /* when an exception occurs, put it in the result group instead of the (unreturned) value */
00115                 this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
00116                     new ExceptionInGroup(this.memberList.get(this.index),
00117                         this.index, e.fillInStackTrace()), this.index);
00118             }
00119         } else {
00120 
00121             /* when there is a Throwable instead of an Object, a method call is impossible, add null to the result group */
00122             this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
00123                 null, this.index);
00124         }
00125     }
00126 }

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