org/objectweb/proactive/core/body/request/BodyRequest.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.body.request;
00032 
00033 import java.lang.reflect.TypeVariable;
00034 import java.util.Map;
00035 
00036 import org.objectweb.proactive.Body;
00037 import org.objectweb.proactive.core.body.UniversalBody;
00038 import org.objectweb.proactive.core.body.message.MessageImpl;
00039 import org.objectweb.proactive.core.body.reply.Reply;
00040 import org.objectweb.proactive.core.exceptions.proxy.ProxyNonFunctionalException;
00041 import org.objectweb.proactive.core.mop.MethodCall;
00042 import org.objectweb.proactive.core.mop.MethodCallExecutionFailedException;
00043 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
00044 
00045 
00046 public class BodyRequest extends MessageImpl implements Request,
00047     java.io.Serializable {
00048     protected MethodCall methodCall;
00049     protected boolean isPriority;
00050         protected boolean isNFRequest;
00051         protected int nfRequestPriority;
00052 
00053     //
00054     // -- CONSTRUCTORS -----------------------------------------------
00055     //
00056         public BodyRequest(Body targetBody, String methodName,
00057                         Class[] paramClasses, Object[] params, boolean isPriority)
00058         throws NoSuchMethodException {
00059                 super(null, 0, true, methodName);
00060                 if (paramClasses == null) {
00061                         paramClasses = new Class[params.length];
00062                         for (int i = 0; i < params.length; i++) {
00063                                 paramClasses[i] = params[i].getClass();
00064                         }
00065                 }
00066                 methodCall = MethodCall.getMethodCall(targetBody.getClass().getMethod(methodName,
00067                                 paramClasses), params, (Map<TypeVariable, Class>)null);
00068                 this.isPriority = isPriority;
00069         }
00070 
00071         //Non functional BodyRequests constructor
00072     public BodyRequest(Body targetBody, String methodName,
00073                 Class[] paramClasses, Object[] params, boolean isNFRequest, int nfRequestPriority)
00074     throws NoSuchMethodException {
00075         super(null, 0, true, methodName);
00076         if (paramClasses == null) {
00077                 paramClasses = new Class[params.length];
00078                 for (int i = 0; i < params.length; i++) {
00079                         paramClasses[i] = params[i].getClass();
00080                 }
00081         }
00082         methodCall = MethodCall.getMethodCall(targetBody.getClass().getMethod(methodName,
00083                         paramClasses), params, (Map<TypeVariable, Class>)null);
00084         
00085         this.isNFRequest = isNFRequest;
00086         this.nfRequestPriority = nfRequestPriority;
00087     }
00088     
00089     // SECURITY
00090     public boolean isCiphered() {
00091         return false;
00092     }
00093 
00094     public boolean decrypt(ProActiveSecurityManager psm) {
00095         return true;
00096     }
00097 
00098     /* (non-Javadoc)
00099      * @see org.objectweb.proactive.core.body.request.Request#getSessionId()
00100      */
00101     public long getSessionId() {
00102         return 0;
00103     }
00104 
00105     public boolean crypt(ProActiveSecurityManager psm,
00106         UniversalBody destinationBody) {
00107         return true;
00108     }
00109 
00110     //
00111     // -- PUBLIC METHODS -----------------------------------------------
00112     //
00113     //
00114     // -- Implements Request -----------------------------------------------
00115     //
00116     public int send(UniversalBody destinationBody) throws java.io.IOException {
00117         int ftres;
00118         if (!(destinationBody instanceof Body)) {
00119             throw new java.io.IOException(
00120                 "The destination body is not a local body");
00121         }
00122         if (!isPriority) {
00123             ftres = ((Body) destinationBody).getRequestQueue().add(this);
00124         } else {
00125             ftres = ((Body) destinationBody).getRequestQueue().addToFront(this);
00126         }
00127         return ftres;
00128     }
00129 
00130     public Reply serve(Body targetBody) throws ServeException {
00131         serveInternal(targetBody);
00132         return null;
00133     }
00134 
00135     public Reply serveAlternate(Body targetBody, ProxyNonFunctionalException nfe) {
00136         return null;
00137     }
00138 
00139     public boolean isOneWay() {
00140         return true;
00141     }
00142 
00143     public boolean hasBeenForwarded() {
00144         return false;
00145     }
00146 
00147     public void resetSendCounter() {
00148     }
00149 
00150     public UniversalBody getSender() {
00151         return null;
00152     }
00153 
00154     public Object getParameter(int index) {
00155         return methodCall.getParameter(index);
00156     }
00157 
00158     public MethodCall getMethodCall() {
00159         return methodCall;
00160     }
00161 
00162     public void notifyReception(UniversalBody bodyReceiver)
00163         throws java.io.IOException {
00164     }
00165 
00166     //
00167     // -- PROTECTED METHODS -----------------------------------------------
00168     //
00169     protected void serveInternal(Body targetBody) throws ServeException {
00170         try {
00171             methodCall.execute(targetBody);
00172         } catch (MethodCallExecutionFailedException e) {
00173             throw new ServeException("serve method " + methodCall.getName() +
00174                 " failed", e);
00175         } catch (java.lang.reflect.InvocationTargetException e) {
00176             e.printStackTrace();
00177         }
00178     }
00179     
00180     
00181     //
00182     // -- METHODS DEALING WITH NON FUNCTIONAL REQUESTS
00183     //
00184     
00185         public boolean isFunctionalRequest() {
00186                 return this.isNFRequest;
00187         }
00188 
00189         public void setFunctionalRequest(boolean isFunctionalRequest) {
00190            this.isNFRequest = isFunctionalRequest; 
00191         }
00192 
00193         public void setNFRequestPriority(int nfReqPriority) {
00194                 this.nfRequestPriority = nfReqPriority;
00195         }
00196 
00197         public int getNFRequestPriority() {
00198                 return this.nfRequestPriority;
00199         }
00200 }

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