00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
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         
00073         if (!(object instanceof Throwable)) {
00074             try {
00075                 if (object instanceof ProActiveComponentRepresentative) {
00076                     
00077                     Object target;
00078                     if (mc.getComponentMetadata().getComponentInterfaceName() == null) {
00079                         
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                         
00096                         this.proxyGroup.addToListOfResult(memberListOfResultGroup,
00097                             this.mc.execute(object), this.index);
00098                     } else if (!objectIsLocal) {
00099 
00100                         
00101                         this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
00102                             ((StubObject) object).getProxy().reify(this.mc),
00103                             this.index);
00104                     } else {
00105 
00106                         
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                 
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             
00122             this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
00123                 null, this.index);
00124         }
00125     }
00126 }