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.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
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
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
00090 public boolean isCiphered() {
00091 return false;
00092 }
00093
00094 public boolean decrypt(ProActiveSecurityManager psm) {
00095 return true;
00096 }
00097
00098
00099
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
00112
00113
00114
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
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
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 }