org/objectweb/proactive/core/body/ibis/IbisBodyAdapter.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.ibis;
00032 
00033 import org.objectweb.proactive.core.ProActiveException;
00034 import org.objectweb.proactive.core.body.BodyAdapterImpl;
00035 import org.objectweb.proactive.core.body.UniversalBody;
00036 import org.objectweb.proactive.core.util.UrlBuilder;
00037 
00038 
00047 public class IbisBodyAdapter extends BodyAdapterImpl {
00048     //
00049     // -- CONSTRUCTORS -----------------------------------------------
00050     //
00051     public IbisBodyAdapter() {
00052     }
00053 
00054     public IbisBodyAdapter(IbisRemoteBody remoteBody) throws ProActiveException {
00055         construct(remoteBody);
00056     }
00057 
00058     public IbisBodyAdapter(UniversalBody body) throws ProActiveException {
00059         try {
00060             IbisRemoteBody remoteBody = new IbisRemoteBodyImpl(body);
00061             construct(remoteBody);
00062         } catch (ibis.rmi.RemoteException e) {
00063             throw new ProActiveException(e);
00064         }
00065     }
00066 
00067     //
00068     // -- PUBLIC METHODS -----------------------------------------------
00069     //
00070 
00078     public void register(String url) throws java.io.IOException {
00079         ibis.rmi.Naming.rebind(url, (IbisRemoteBody) proxiedRemoteBody);
00080     }
00081 
00087     public void unregister(String url) throws java.io.IOException {
00088         try {
00089             ibis.rmi.Naming.unbind(url);
00090         } catch (ibis.rmi.NotBoundException e) {
00091             throw new java.io.IOException(
00092                 "No object is bound to the given url : " + url);
00093         }
00094     }
00095 
00105     public UniversalBody lookup(String url) throws java.io.IOException {
00106         Object o = null;
00107 
00108         // Try if URL is the address of a IbisRemoteBody
00109         try {
00110             o = ibis.rmi.Naming.lookup(UrlBuilder.removeProtocol(url, "ibis:"));
00111         } catch (ibis.rmi.NotBoundException e) {
00112             throw new java.io.IOException("The url " + url +
00113                 " is not bound to any known object");
00114         }
00115 
00116         if (o instanceof IbisRemoteBody) {
00117             try {
00118                 construct((IbisRemoteBody) o);
00119             } catch (ProActiveException e1) {
00120                 throw new java.io.IOException(
00121                     "The remote object at " + url + " is not accessible ");
00122             }
00123 
00124             return this;
00125         } else {
00126             throw new java.io.IOException(
00127                 "The given url does exist but doesn't point to a remote body  url=" +
00128                 url + " class found is " + o.getClass().getName());
00129         }
00130     }
00131 }

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