1 31 package org.objectweb.proactive.core.body.request; 32 33 import org.objectweb.proactive.Body; 34 import org.objectweb.proactive.core.body.UniversalBody; 35 import org.objectweb.proactive.core.body.message.MessageImpl; 36 import org.objectweb.proactive.core.body.reply.Reply; 37 import org.objectweb.proactive.core.mop.MethodCall; 38 import org.objectweb.proactive.core.mop.MethodCallExecutionFailedException; 39 import org.objectweb.proactive.ext.security.ProActiveSecurityManager; 40 41 public class BodyRequest extends MessageImpl implements Request, java.io.Serializable { 42 43 protected MethodCall methodCall; 44 protected boolean isPriority; 45 46 50 public BodyRequest(Body targetBody, String methodName, Class [] paramClasses, Object [] params, boolean isPriority) throws NoSuchMethodException { 51 super(null, 0, true, methodName); 52 if (paramClasses == null) { 53 paramClasses = new Class [params.length]; 54 for (int i = 0; i < params.length; i++) { 55 paramClasses[i] = params[i].getClass(); 56 } 57 } 58 methodCall = MethodCall.getMethodCall(targetBody.getClass().getMethod(methodName, paramClasses), params); 59 this.isPriority = isPriority; 60 } 61 62 63 public boolean isCiphered() { 65 return false; 66 } 67 68 public boolean decrypt(ProActiveSecurityManager psm) { 69 return true; 70 } 71 72 75 public long getSessionId() { 76 return 0; 77 } 78 82 86 public void send(UniversalBody destinationBody) throws java.io.IOException { 87 if (! (destinationBody instanceof Body)) { 88 throw new java.io.IOException ("The destination body is not a local body"); 89 } 90 if (isPriority) { 91 ((Body)destinationBody).getRequestQueue().add(this); 92 } else { 93 ((Body)destinationBody).getRequestQueue().addToFront(this); 94 } 95 } 96 97 98 public Reply serve(Body targetBody) throws ServeException { 99 serveInternal(targetBody); 100 return null; 101 } 102 103 104 public boolean isOneWay() { 105 return true; 106 } 107 108 109 public boolean hasBeenForwarded() { 110 return false; 111 } 112 113 public UniversalBody getSender() { 114 return null; 115 } 116 117 118 public Object getParameter(int index) { 119 return methodCall.getParameter(index); 120 } 121 122 123 public MethodCall getMethodCall() { 124 return methodCall; 125 } 126 127 128 public void notifyReception(UniversalBody bodyReceiver) throws java.io.IOException { 129 } 130 131 132 136 protected void serveInternal(Body targetBody) throws ServeException { 137 try { 138 methodCall.execute(targetBody); 139 } catch (MethodCallExecutionFailedException e) { 140 throw new ServeException("serve method " + methodCall.getName() + " failed", e); 141 } catch (java.lang.reflect.InvocationTargetException e) { 142 e.printStackTrace(); 143 } 144 } 145 146 } 147 | Popular Tags |