KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > body > rmi > RemoteBodyAdapter


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.rmi;
32
33 import java.io.IOException JavaDoc;
34 import java.security.PublicKey JavaDoc;
35 import java.security.cert.X509Certificate JavaDoc;
36 import java.util.ArrayList JavaDoc;
37
38 import org.apache.log4j.Logger;
39 import org.objectweb.proactive.core.ProActiveException;
40 import org.objectweb.proactive.core.UniqueID;
41 import org.objectweb.proactive.core.body.UniversalBody;
42 import org.objectweb.proactive.core.body.reply.Reply;
43 import org.objectweb.proactive.core.body.request.Request;
44 import org.objectweb.proactive.ext.security.Communication;
45 import org.objectweb.proactive.ext.security.CommunicationForbiddenException;
46 import org.objectweb.proactive.ext.security.Policy;
47 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
48 import org.objectweb.proactive.ext.security.RenegotiateSessionException;
49 import org.objectweb.proactive.ext.security.SecurityContext;
50 import org.objectweb.proactive.ext.security.SecurityNotAvailableException;
51 import org.objectweb.proactive.ext.security.crypto.AuthenticationException;
52 import org.objectweb.proactive.ext.security.crypto.ConfidentialityTicket;
53 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
54
55
56 public class RemoteBodyAdapter implements UniversalBody, java.io.Serializable JavaDoc {
57     protected static Logger logger = Logger.getLogger(RemoteBodyAdapter.class.getName());
58
59     /**
60      * The encapsulated RemoteBody
61      */

62     protected RemoteBody proxiedRemoteBody;
63
64     /**
65      * Cache the ID of the Body locally for speed
66      */

67     protected UniqueID bodyID;
68
69     //
70
// -- CONSTRUCTORS -----------------------------------------------
71
//
72
public RemoteBodyAdapter() {
73     }
74
75     public RemoteBodyAdapter(RemoteBody remoteBody) throws ProActiveException {
76         // Thread.dumpStack();
77
// ProActiveConfiguration.getConfiguration().dumpLoadedProperties();
78
this.proxiedRemoteBody = remoteBody;
79         if (logger.isDebugEnabled()) {
80             logger.debug(proxiedRemoteBody.getClass());
81         }
82         try {
83             this.bodyID = remoteBody.getID();
84         } catch (java.rmi.RemoteException JavaDoc e) {
85             throw new ProActiveException(e);
86         }
87     }
88
89     public RemoteBodyAdapter(UniversalBody body) throws ProActiveException {
90         try {
91             this.proxiedRemoteBody = new RemoteBodyImpl(body);
92         } catch (java.rmi.RemoteException JavaDoc e) {
93             throw new ProActiveException(e);
94         }
95         if (logger.isDebugEnabled()) {
96             logger.debug(proxiedRemoteBody.getClass());
97         }
98         this.bodyID = body.getID();
99     }
100
101     //
102
// -- PUBLIC METHODS -----------------------------------------------
103
//
104

105     /**
106      * Registers an active object into a RMI registry. In fact it is the
107      * remote version of the body of the active object that is registered into the
108      * RMI Registry under the given URL.
109      * @param obj the active object to register.
110      * @param url the url under which the remote body is registered.
111      * @exception java.io.IOException if the remote body cannot be registered
112      */

113     public static void register(RemoteBodyAdapter bodyAdapter, String JavaDoc url)
114         throws java.io.IOException JavaDoc {
115         java.rmi.Naming.rebind(url, bodyAdapter.proxiedRemoteBody);
116     }
117
118     /**
119      * Unregisters an active object previously registered into a RMI registry.
120      * @param url the url under which the active object is registered.
121      * @exception java.io.IOException if the remote object cannot be removed from the registry
122      */

123     public static void unregister(String JavaDoc url) throws java.io.IOException JavaDoc {
124         try {
125             java.rmi.Naming.unbind(url);
126         } catch (java.rmi.NotBoundException JavaDoc e) {
127             throw new java.io.IOException JavaDoc(
128                 "No object is bound to the given url : " + url);
129         }
130     }
131
132     /**
133      * Looks-up an active object previously registered in a RMI registry. In fact it is the
134      * remote version of the body of an active object that can be registered into the
135      * RMI Registry under a given URL.
136      * @param url the url the remote Body is registered to
137      * @return a UniversalBody
138      * @exception java.io.IOException if the remote body cannot be found under the given url
139      * or if the object found is not of type RemoteBody
140      */

141     public static UniversalBody lookup(String JavaDoc url) throws java.io.IOException JavaDoc {
142         Object JavaDoc o = null;
143         // Try if URL is the address of a RemoteBody
144
try {
145             o = java.rmi.Naming.lookup(url);
146         } catch (java.rmi.NotBoundException JavaDoc e) {
147             throw new java.io.IOException JavaDoc("The url " + url +
148                 " is not bound to any known object");
149         }
150         if (o instanceof RemoteBody) {
151             try {
152                 return new RemoteBodyAdapter((RemoteBody) o);
153             } catch (ProActiveException e) {
154                 throw new java.io.IOException JavaDoc("Cannot build a Remote Adapter" +
155                     e.toString());
156             }
157         } else {
158             throw new java.io.IOException JavaDoc(
159                 "The given url does exist but doesn't point to a remote body url=" +
160                 url + " class found is " + o.getClass().getName());
161         }
162     }
163
164     public boolean equals(Object JavaDoc o) {
165         if (!(o instanceof RemoteBodyAdapter)) {
166             return false;
167         }
168         RemoteBodyAdapter rba = (RemoteBodyAdapter) o;
169         return proxiedRemoteBody.equals(rba.proxiedRemoteBody);
170     }
171
172     public int hashCode() {
173         return proxiedRemoteBody.hashCode();
174     }
175
176     //
177
// -- implements UniversalBody -----------------------------------------------
178
//
179
public void receiveRequest(Request r) throws java.io.IOException JavaDoc, RenegotiateSessionException {
180         proxiedRemoteBody.receiveRequest(r);
181     }
182
183     public void receiveReply(Reply r) throws java.io.IOException JavaDoc {
184         proxiedRemoteBody.receiveReply(r);
185     }
186
187     public String JavaDoc getNodeURL() {
188         try {
189             return proxiedRemoteBody.getNodeURL();
190         } catch (java.rmi.RemoteException JavaDoc e) {
191             return "cannot contact the body to get the nodeURL";
192         }
193     }
194
195     public UniqueID getID() {
196         return bodyID;
197     }
198
199     public void updateLocation(UniqueID id, UniversalBody remoteBody)
200         throws java.io.IOException JavaDoc {
201         proxiedRemoteBody.updateLocation(id, remoteBody);
202     }
203
204     public UniversalBody getRemoteAdapter() {
205         return this;
206     }
207
208     public void enableAC() throws java.io.IOException JavaDoc {
209         proxiedRemoteBody.enableAC();
210     }
211
212     public void disableAC() throws java.io.IOException JavaDoc {
213         proxiedRemoteBody.disableAC();
214     }
215
216     public void setImmediateService(String JavaDoc methodName)
217         throws java.io.IOException JavaDoc {
218         proxiedRemoteBody.setImmediateService(methodName);
219     }
220
221     // SECURITY
222
public void initiateSession(int type,UniversalBody body)
223         throws IOException JavaDoc, CommunicationForbiddenException,
224             AuthenticationException, RenegotiateSessionException,
225             SecurityNotAvailableException {
226         proxiedRemoteBody.initiateSession(type,body);
227     }
228
229     public void terminateSession(long sessionID)
230         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
231         proxiedRemoteBody.terminateSession(sessionID);
232     }
233
234     public X509Certificate JavaDoc getCertificate()
235         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
236         return proxiedRemoteBody.getCertificate();
237     }
238
239     public ProActiveSecurityManager getProActiveSecurityManager()
240         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
241         return proxiedRemoteBody.getProActiveSecurityManager();
242     }
243
244     public Policy getPolicyFrom(X509Certificate JavaDoc certificate)
245         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
246         return proxiedRemoteBody.getPolicyFrom(certificate);
247     }
248
249     public long startNewSession(Communication policy)
250         throws IOException JavaDoc, RenegotiateSessionException,
251             SecurityNotAvailableException {
252         return proxiedRemoteBody.startNewSession(policy);
253     }
254
255     public ConfidentialityTicket negociateKeyReceiverSide(
256         ConfidentialityTicket confidentialityTicket, long sessionID)
257         throws java.io.IOException JavaDoc, KeyExchangeException,
258             SecurityNotAvailableException {
259         return proxiedRemoteBody.negociateKeyReceiverSide(confidentialityTicket,
260             sessionID);
261     }
262
263     public PublicKey JavaDoc getPublicKey()
264         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
265         return proxiedRemoteBody.getPublicKey();
266     }
267
268     public byte[] randomValue(long sessionID, byte[] cl_rand)
269         throws Exception JavaDoc, SecurityNotAvailableException {
270         return proxiedRemoteBody.randomValue(sessionID, cl_rand);
271     }
272
273     public byte[][] publicKeyExchange(long sessionID,
274         UniversalBody distantBody, byte[] my_pub, byte[] my_cert,
275         byte[] sig_code) throws Exception JavaDoc, SecurityNotAvailableException {
276         return proxiedRemoteBody.publicKeyExchange(sessionID, distantBody,
277             my_pub, my_cert, sig_code);
278     }
279
280     public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1,
281         byte[] tmp2, byte[] tmp3, byte[] tmp4)
282         throws Exception JavaDoc, SecurityNotAvailableException {
283         return proxiedRemoteBody.secretKeyExchange(sessionID, tmp, tmp1, tmp2,
284             tmp3, tmp4);
285     }
286
287     public Communication getPolicyTo(String JavaDoc type, String JavaDoc from, String JavaDoc to)
288         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
289         return proxiedRemoteBody.getPolicyTo(type, from, to);
290     }
291
292     /* (non-Javadoc)
293      * @see org.objectweb.proactive.core.body.UniversalBody#getVNName()
294      */

295     public String JavaDoc getVNName()
296         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
297         return proxiedRemoteBody.getVNName();
298     }
299
300     /* (non-Javadoc)
301      * @see org.objectweb.proactive.core.body.UniversalBody#getCertificateEncoded()
302      */

303     public byte[] getCertificateEncoded()
304         throws java.io.IOException JavaDoc, SecurityNotAvailableException {
305         return proxiedRemoteBody.getCertificateEncoded();
306     }
307
308     /* (non-Javadoc)
309      * @see org.objectweb.proactive.core.body.UniversalBody#getPolicy(org.objectweb.proactive.ext.security.SecurityContext)
310      */

311     public SecurityContext getPolicy(SecurityContext securityContext)
312         throws SecurityNotAvailableException, IOException JavaDoc {
313         return proxiedRemoteBody.getPolicy(securityContext);
314     }
315     
316     public ArrayList JavaDoc getEntities() throws SecurityNotAvailableException, IOException JavaDoc {
317             return proxiedRemoteBody.getEntities();
318         }
319
320
321     //
322
// -- PRIVATE METHODS -----------------------------------------------
323
//
324
}
325
Popular Tags