KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > body > ibis > IbisRemoteBodyAdapter


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.ibis;
32
33
34 /**
35  * An adapter for a IbisRemoteBody to be able to receive remote calls. This helps isolate RMI-specific
36  * code into a small set of specific classes, thus enabling reuse if we one day decide to switch
37  * to another remote objects library.
38  */

39 import java.io.IOException JavaDoc;
40 import java.security.PublicKey JavaDoc;
41 import java.security.cert.X509Certificate JavaDoc;
42 import java.util.ArrayList JavaDoc;
43
44 import org.apache.log4j.Logger;
45 import org.objectweb.proactive.core.ProActiveException;
46 import org.objectweb.proactive.core.UniqueID;
47 import org.objectweb.proactive.core.body.UniversalBody;
48 import org.objectweb.proactive.core.body.reply.Reply;
49 import org.objectweb.proactive.core.body.request.Request;
50 import org.objectweb.proactive.ext.security.Communication;
51 import org.objectweb.proactive.ext.security.CommunicationForbiddenException;
52 import org.objectweb.proactive.ext.security.Policy;
53 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
54 import org.objectweb.proactive.ext.security.RenegotiateSessionException;
55 import org.objectweb.proactive.ext.security.SecurityContext;
56 import org.objectweb.proactive.ext.security.SecurityNotAvailableException;
57 import org.objectweb.proactive.ext.security.crypto.AuthenticationException;
58 import org.objectweb.proactive.ext.security.crypto.ConfidentialityTicket;
59 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
60
61
62 public class IbisRemoteBodyAdapter implements UniversalBody,
63     java.io.Serializable JavaDoc {
64     protected static Logger logger = Logger.getLogger(IbisRemoteBodyAdapter.class.getName());
65
66     /**
67      * The encapsulated IbisRemoteBody
68      */

69     protected IbisRemoteBody proxiedRemoteBody;
70
71     /**
72      * Cache the ID of the Body locally for speed
73      */

74     protected UniqueID bodyID;
75
76     //
77
// -- CONSTRUCTORS -----------------------------------------------
78
//
79
public IbisRemoteBodyAdapter() {
80     }
81
82     public IbisRemoteBodyAdapter(IbisRemoteBody remoteBody)
83         throws ProActiveException {
84         this.proxiedRemoteBody = remoteBody;
85         if (logger.isDebugEnabled()) {
86             logger.debug(" remote body = " + proxiedRemoteBody.getClass());
87         }
88         try {
89             this.bodyID = remoteBody.getID();
90         } catch (ibis.rmi.RemoteException e) {
91             throw new ProActiveException(e);
92         }
93     }
94
95     public IbisRemoteBodyAdapter(UniversalBody body) throws ProActiveException {
96         try {
97             this.proxiedRemoteBody = new IbisRemoteBodyImpl(body);
98             if (logger.isDebugEnabled()) {
99                 logger.debug("proxiedRemoteBody = " +
100                     proxiedRemoteBody.getClass());
101             }
102         } catch (ibis.rmi.RemoteException e) {
103             throw new ProActiveException(e);
104         }
105         this.bodyID = body.getID();
106     }
107
108     //
109
// -- PUBLIC METHODS -----------------------------------------------
110
//
111

112     /**
113      * Registers an active object into a RMI registry. In fact it is the
114      * remote version of the body of the active object that is registered into the
115      * RMI Registry under the given URL.
116      * @param obj the active object to register.
117      * @param url the url under which the remote body is registered.
118      * @exception java.io.IOException if the remote body cannot be registered
119      */

120     public static void register(IbisRemoteBodyAdapter bodyAdapter, String JavaDoc url)
121         throws java.io.IOException JavaDoc {
122         ibis.rmi.Naming.rebind(url, bodyAdapter.proxiedRemoteBody);
123     }
124
125     /**
126      * Unregisters an active object previously registered into a RMI registry.
127      * @param url the url under which the active object is registered.
128      * @exception java.io.IOException if the remote object cannot be removed from the registry
129      */

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

148     public static UniversalBody lookup(String JavaDoc url) throws java.io.IOException JavaDoc {
149         Object JavaDoc o = null;
150
151         // Try if URL is the address of a IbisRemoteBody
152
try {
153             o = ibis.rmi.Naming.lookup(url);
154         } catch (ibis.rmi.NotBoundException e) {
155             throw new java.io.IOException JavaDoc("The url " + url +
156                 " is not bound to any known object");
157         }
158         if (o instanceof IbisRemoteBody) {
159             try {
160                 return new IbisRemoteBodyAdapter((IbisRemoteBody) o);
161             } catch (ProActiveException e) {
162                 throw new java.io.IOException JavaDoc("Cannot build a Remote Adapter" +
163                     e.toString());
164             }
165         } else {
166             throw new java.io.IOException JavaDoc(
167                 "The given url does exist but doesn't point to a remote body url=" +
168                 url + " class found is " + o.getClass().getName());
169         }
170     }
171
172     public boolean equals(Object JavaDoc o) {
173         if (!(o instanceof IbisRemoteBodyAdapter)) {
174             return false;
175         }
176         IbisRemoteBodyAdapter rba = (IbisRemoteBodyAdapter) o;
177         return proxiedRemoteBody.equals(rba.proxiedRemoteBody);
178     }
179
180     public int hashCode() {
181         return proxiedRemoteBody.hashCode();
182     }
183
184     //
185
// -- implements UniversalBody -----------------------------------------------
186
//
187
public void receiveRequest(Request r) throws java.io.IOException JavaDoc, RenegotiateSessionException {
188         proxiedRemoteBody.receiveRequest(r);
189     }
190
191     public void receiveReply(Reply r) throws java.io.IOException JavaDoc {
192         proxiedRemoteBody.receiveReply(r);
193     }
194
195     public String JavaDoc getNodeURL() {
196         try {
197             return proxiedRemoteBody.getNodeURL();
198         } catch (ibis.rmi.RemoteException e) {
199             return "cannot contact the body to get the nodeURL";
200         }
201     }
202
203     public UniqueID getID() {
204         return bodyID;
205     }
206
207     public void updateLocation(UniqueID id, UniversalBody remoteBody)
208         throws java.io.IOException JavaDoc {
209         proxiedRemoteBody.updateLocation(id, remoteBody);
210     }
211
212     public UniversalBody getRemoteAdapter() {
213         return this;
214     }
215
216     public void enableAC() throws java.io.IOException JavaDoc {
217         proxiedRemoteBody.enableAC();
218     }
219
220     public void disableAC() throws java.io.IOException JavaDoc {
221         proxiedRemoteBody.disableAC();
222     }
223
224     public void setImmediateService(String JavaDoc methodName)
225         throws java.io.IOException JavaDoc {
226         proxiedRemoteBody.setImmediateService(methodName);
227     }
228
229     // SECURITY
230
/* (non-Javadoc)
231      * @see org.objectweb.proactive.core.body.UniversalBody#initiateSession(org.objectweb.proactive.core.body.UniversalBody)
232      */

233     public void initiateSession(int type,UniversalBody body) throws IOException JavaDoc, CommunicationForbiddenException, AuthenticationException, RenegotiateSessionException, SecurityNotAvailableException {
234         proxiedRemoteBody.initiateSession(type,body);
235         
236     }
237
238     /* (non-Javadoc)
239      * @see org.objectweb.proactive.core.body.UniversalBody#terminateSession(long)
240      */

241     public void terminateSession(long sessionID) throws IOException JavaDoc, SecurityNotAvailableException {
242 proxiedRemoteBody.terminateSession(sessionID) ;
243     }
244
245     /* (non-Javadoc)
246      * @see org.objectweb.proactive.core.body.UniversalBody#getCertificate()
247      */

248     public X509Certificate JavaDoc getCertificate() throws SecurityNotAvailableException, IOException JavaDoc {
249         return proxiedRemoteBody.getCertificate();
250     }
251
252     /* (non-Javadoc)
253      * @see org.objectweb.proactive.core.body.UniversalBody#getProActiveSecurityManager()
254      */

255     public ProActiveSecurityManager getProActiveSecurityManager() throws SecurityNotAvailableException, IOException JavaDoc {
256         return proxiedRemoteBody.getProActiveSecurityManager();
257     }
258
259     /* (non-Javadoc)
260      * @see org.objectweb.proactive.core.body.UniversalBody#getPolicyFrom(java.security.cert.X509Certificate)
261      */

262     public Policy getPolicyFrom(X509Certificate JavaDoc certificate) throws SecurityNotAvailableException, IOException JavaDoc {
263         return proxiedRemoteBody.getPolicyFrom(certificate);
264     }
265
266     /* (non-Javadoc)
267      * @see org.objectweb.proactive.core.body.UniversalBody#startNewSession(org.objectweb.proactive.ext.security.Policy)
268      */

269     public long startNewSession(Communication policy) throws SecurityNotAvailableException, IOException JavaDoc, RenegotiateSessionException {
270         return proxiedRemoteBody.startNewSession(policy);
271     }
272
273     /* (non-Javadoc)
274      * @see org.objectweb.proactive.core.body.UniversalBody#negociateKeyReceiverSide(org.objectweb.proactive.ext.security.crypto.ConfidentialityTicket, long)
275      */

276     public ConfidentialityTicket negociateKeyReceiverSide(ConfidentialityTicket confidentialityTicket, long sessionID) throws SecurityNotAvailableException, KeyExchangeException, IOException JavaDoc {
277         return proxiedRemoteBody.negociateKeyReceiverSide(confidentialityTicket,sessionID);
278     }
279
280     /* (non-Javadoc)
281      * @see org.objectweb.proactive.core.body.UniversalBody#getPublicKey()
282      */

283     public PublicKey JavaDoc getPublicKey() throws SecurityNotAvailableException, IOException JavaDoc {
284         return proxiedRemoteBody.getPublicKey();
285     }
286
287     /* (non-Javadoc)
288      * @see org.objectweb.proactive.core.body.UniversalBody#randomValue(long, byte[])
289      */

290     public byte[] randomValue(long sessionID, byte[] cl_rand) throws SecurityNotAvailableException, Exception JavaDoc {
291         return proxiedRemoteBody.randomValue(sessionID,cl_rand);
292     }
293
294     /* (non-Javadoc)
295      * @see org.objectweb.proactive.core.body.UniversalBody#publicKeyExchange(long, org.objectweb.proactive.core.body.UniversalBody, byte[], byte[], byte[])
296      */

297     public byte[][] publicKeyExchange(long sessionID, UniversalBody distantBody, byte[] my_pub, byte[] my_cert, byte[] sig_code) throws SecurityNotAvailableException, Exception JavaDoc, RenegotiateSessionException {
298         return proxiedRemoteBody.publicKeyExchange(sessionID,distantBody,my_pub,my_cert,sig_code);
299     }
300
301     /* (non-Javadoc)
302      * @see org.objectweb.proactive.core.body.UniversalBody#secretKeyExchange(long, byte[], byte[], byte[], byte[], byte[])
303      */

304     public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1, byte[] tmp2, byte[] tmp3, byte[] tmp4) throws SecurityNotAvailableException, Exception JavaDoc, RenegotiateSessionException {
305         return proxiedRemoteBody.secretKeyExchange(sessionID,tmp,tmp1,tmp2,tmp3,tmp4);
306     }
307
308     /* (non-Javadoc)
309      * @see org.objectweb.proactive.core.body.UniversalBody#getPolicyTo(java.lang.String, java.lang.String, java.lang.String)
310      */

311     public Communication getPolicyTo(String JavaDoc type, String JavaDoc from, String JavaDoc to) throws SecurityNotAvailableException, IOException JavaDoc {
312         return proxiedRemoteBody.getPolicyTo(type,from,to);
313     }
314
315     /* (non-Javadoc)
316      * @see org.objectweb.proactive.core.body.UniversalBody#getPolicy(org.objectweb.proactive.ext.security.SecurityContext)
317      */

318     public SecurityContext getPolicy(SecurityContext securityContext) throws SecurityNotAvailableException, IOException JavaDoc {
319         return proxiedRemoteBody.getPolicy(securityContext);
320     }
321
322     /* (non-Javadoc)
323      * @see org.objectweb.proactive.core.body.UniversalBody#getVNName()
324      */

325     public String JavaDoc getVNName() throws SecurityNotAvailableException, IOException JavaDoc {
326         return proxiedRemoteBody.getVNName();
327     }
328
329     /* (non-Javadoc)
330      * @see org.objectweb.proactive.core.body.UniversalBody#getCertificateEncoded()
331      */

332     public byte[] getCertificateEncoded() throws SecurityNotAvailableException, IOException JavaDoc {
333         return proxiedRemoteBody.getCertificateEncoded();
334     }
335
336     /* (non-Javadoc)
337      * @see org.objectweb.proactive.core.body.UniversalBody#getEntities()
338      */

339     public ArrayList JavaDoc getEntities() throws SecurityNotAvailableException, IOException JavaDoc {
340         return proxiedRemoteBody.getEntities();
341     }
342
343     //
344
// -- PRIVATE METHODS -----------------------------------------------
345
//
346
}
347
Popular Tags