org/objectweb/proactive/core/group/ProcessForOneWayCall.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 ProcessForOneWayCall extends AbstractProcessForGroup
00051     implements Runnable {
00052     private int index;
00053     private MethodCall mc;
00054     private Body body;
00055     private ExceptionListException exceptionList;
00056 
00057     public ProcessForOneWayCall(ProxyForGroup proxyGroup, Vector memberList,
00058         int index, MethodCall mc, Body body,
00059         ExceptionListException exceptionList) {
00060         this.proxyGroup = proxyGroup;
00061         this.memberList = memberList;
00062         this.index = index;
00063         this.mc = mc;
00064         this.body = body;
00065         this.exceptionList = exceptionList;
00066     }
00067 
00068     public void run() {
00069         LocalBodyStore.getInstance().setCurrentThreadBody(body);
00070         Object object = null;
00071 
00072         // try-catch block added by AdC for P2P
00073         try {
00074             object = this.memberList.get(this.index);
00075         } catch (ArrayIndexOutOfBoundsException e) {
00076             return;
00077         }
00078         boolean objectIsLocal = false;
00079 
00080         /* only do the communication (reify) if the object is not an error nor an exception */
00081         if (!(object instanceof Throwable)) {
00082             try {
00083                 if (object instanceof ProActiveComponentRepresentative) {
00084                     // delegate to the corresponding interface
00085                     Object target;
00086                     if (mc.getComponentMetadata().getComponentInterfaceName() == null) {
00087                         // a call on the Component interface
00088                         target = object;
00089                     } else {
00090                         target = ((ProActiveComponentRepresentative) object).getFcInterface(mc.getComponentMetadata()
00091                                                                                               .getComponentInterfaceName());
00092                     }
00093                     this.mc.execute(target);
00094                 } else if (object instanceof ProActiveInterface) {
00095                     this.mc.execute(object);
00096                 } else {
00097                     Proxy lastProxy = AbstractProcessForGroup.findLastProxy(object);
00098                     if (lastProxy instanceof UniversalBodyProxy) {
00099                         objectIsLocal = ((UniversalBodyProxy) lastProxy).isLocal();
00100                     }
00101                     if (lastProxy == null) {
00102                         // means we are dealing with a non-reified object (a standard Java Object)
00103                         this.mc.execute(object);
00104                     } else if (objectIsLocal) {
00105                         if (!(mc instanceof MethodCallControlForGroup)) {
00106                                                         ((StubObject) object).getProxy().reify(
00107                                                                         new MethodCall(this.mc));
00108                                                 } else {
00109                                                         ((StubObject) object).getProxy().reify(this.mc);
00110                                                 }
00111                                         } else {
00112                                                 ((StubObject) object).getProxy().reify(this.mc);
00113                                         }
00114                 }
00115             } catch (Throwable e) {
00116                 e.printStackTrace();
00117                 this.exceptionList.add(new ExceptionInGroup(object, this.index,
00118                         e.fillInStackTrace()));
00119             }
00120         }
00121     }
00122 }

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