KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > body > request > BodyRequest


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

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 JavaDoc {
42
43   protected MethodCall methodCall;
44   protected boolean isPriority;
45   
46   //
47
// -- CONSTRUCTORS -----------------------------------------------
48
//
49

50   public BodyRequest(Body targetBody, String JavaDoc methodName, Class JavaDoc[] paramClasses, Object JavaDoc[] params, boolean isPriority) throws NoSuchMethodException JavaDoc {
51     super(null, 0, true, methodName);
52     if (paramClasses == null) {
53       paramClasses = new Class JavaDoc[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     // SECURITY
64
public boolean isCiphered() {
65         return false;
66     }
67
68     public boolean decrypt(ProActiveSecurityManager psm) {
69         return true;
70     }
71
72     /* (non-Javadoc)
73       * @see org.objectweb.proactive.core.body.request.Request#getSessionId()
74       */

75      public long getSessionId() {
76          return 0;
77      }
78   //
79
// -- PUBLIC METHODS -----------------------------------------------
80
//
81

82   //
83
// -- Implements Request -----------------------------------------------
84
//
85

86   public void send(UniversalBody destinationBody) throws java.io.IOException JavaDoc {
87     if (! (destinationBody instanceof Body)) {
88       throw new java.io.IOException JavaDoc("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 JavaDoc 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 JavaDoc {
129   }
130   
131   
132   //
133
// -- PROTECTED METHODS -----------------------------------------------
134
//
135

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 JavaDoc e) {
142         e.printStackTrace();
143     }
144   }
145
146 }
147
Popular Tags