org/objectweb/proactive/core/body/jini/JiniBodyAdapter.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.body.jini;
00032 
00033 import org.objectweb.proactive.core.ProActiveException;
00034 import org.objectweb.proactive.core.body.BodyAdapterImpl;
00035 import org.objectweb.proactive.core.body.RemoteBody;
00036 import org.objectweb.proactive.core.body.UniversalBody;
00037 import org.objectweb.proactive.core.body.rmi.RmiRemoteBody;
00038 
00039 
00047 public class JiniBodyAdapter extends BodyAdapterImpl {
00048     //
00049     // -- CONSTRUCTORS -----------------------------------------------
00050     //
00051     public JiniBodyAdapter() {
00052     }
00053 
00054     public JiniBodyAdapter(RemoteBody remoteBody) throws ProActiveException {
00055         construct(remoteBody);
00056     }
00057 
00058     public JiniBodyAdapter(UniversalBody body) throws ProActiveException {
00059         try {
00060             RemoteBody remoteBody = new JiniRemoteBodyImpl(body);
00061             construct(remoteBody);
00062         } catch (java.rmi.RemoteException e) {
00063             throw new ProActiveException(e);
00064         }
00065     }
00066 
00074     public void register(String url) throws java.io.IOException {
00075         java.rmi.Naming.rebind(url, (RmiRemoteBody) proxiedRemoteBody);
00076     }
00077 
00083     public void unregister(String url) throws java.io.IOException {
00084         try {
00085             java.rmi.Naming.unbind(url);
00086         } catch (java.rmi.NotBoundException e) {
00087             throw new java.io.IOException(
00088                 "No object is bound to the given url : " + url);
00089         }
00090     }
00091 
00101     public UniversalBody lookup(String url) throws java.io.IOException {
00102         Object o = null;
00103 
00104         // Try if URL is the address of a JiniBody
00105         try {
00106             o = java.rmi.Naming.lookup(url);
00107         } catch (java.rmi.NotBoundException e) {
00108             throw new java.io.IOException("The url " + url +
00109                 " is not bound to any known object");
00110         }
00111 
00112         if (o instanceof RmiRemoteBody) {
00113             try {
00114                 construct((RmiRemoteBody) o);
00115             } catch (ProActiveException e1) {
00116                 throw new java.io.IOException(
00117                         "The remote object at " + url + " is not accessible ");
00118             }
00119 
00120             return this;
00121         } else {
00122             throw new java.io.IOException(
00123                 "The given url does exist but doesn't point to a jini body  url=" +
00124                 url + " class found is " + o.getClass().getName());
00125         }
00126     }
00127 }

Generated on Mon Jan 22 15:16:05 2007 for ProActive by  doxygen 1.5.1