KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > group > ProcessForAsyncCall


1 package org.objectweb.proactive.core.group;
2
3 import org.objectweb.proactive.Body;
4 import org.objectweb.proactive.core.body.LocalBodyStore;
5 import org.objectweb.proactive.core.body.proxy.UniversalBodyProxy;
6 import org.objectweb.proactive.core.mop.MethodCall;
7 import org.objectweb.proactive.core.mop.Proxy;
8 import org.objectweb.proactive.core.mop.StubObject;
9
10 import java.util.Vector JavaDoc;
11
12
13 /**
14  * This class provides multithreading for the (a)synchronous methodcall on a group.
15  *
16  * @author Laurent Baduel
17  */

18 public class ProcessForAsyncCall extends AbstractProcessForGroup
19     implements Runnable JavaDoc {
20
21     private Vector JavaDoc memberListOfResultGroup;
22     private int index;
23     private MethodCall mc;
24     private Body body;
25
26     public ProcessForAsyncCall(ProxyForGroup proxyGroup, Vector JavaDoc memberList,
27         Vector JavaDoc memberListOfResultGroup, int index, MethodCall mc, Body body) {
28         this.proxyGroup = proxyGroup;
29         this.memberList = memberList;
30         this.memberListOfResultGroup = memberListOfResultGroup;
31         this.index = index;
32         this.mc = mc;
33         this.body = body;
34     }
35
36     public synchronized void run() {
37         Object JavaDoc object = this.memberList.get(this.index);
38         LocalBodyStore.getInstance().setCurrentThreadBody(body);
39         boolean objectIsLocal = false;
40
41         /* only do the communication (reify) if the object is not an error nor an exception */
42         if (!(object instanceof Throwable JavaDoc)) {
43             Proxy lastProxy = AbstractProcessForGroup.findLastProxy(object);
44             if (lastProxy instanceof UniversalBodyProxy) {
45                 objectIsLocal = ((UniversalBodyProxy) lastProxy).isLocal();
46             }
47             try {
48                 if (lastProxy == null) {
49                     // means we are dealing with a standard Java Object
50
this.proxyGroup.addToListOfResult(memberListOfResultGroup,
51                         this.mc.execute(object), this.index);
52                 } else if (!objectIsLocal) {
53
54                     /* add the return value into the result group */
55                     this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
56                         ((StubObject) object).getProxy().reify(this.mc),
57                         this.index);
58                 } else {
59
60                     /* add the return value into the result group */
61                     this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
62                         ((StubObject) object).getProxy().reify(new MethodCall(
63                                 this.mc)), this.index);
64                 }
65             } catch (Throwable JavaDoc e) {
66
67                 /* when an exception occurs, put it in the result group instead of the (unreturned) value */
68                 this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
69                     new ExceptionInGroup(this.memberList.get(this.index), e),
70                     this.index);
71             }
72         } else {
73
74             /* when there is a Throwable instead of an Object, a method call is impossible, add null to the result group */
75             this.proxyGroup.addToListOfResult(this.memberListOfResultGroup,
76                 null, this.index);
77         }
78     }
79 }
80
Popular Tags