00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.body.rmi;
00032
00033 import java.net.MalformedURLException;
00034 import java.rmi.ConnectException;
00035
00036 import org.objectweb.proactive.core.ProActiveException;
00037 import org.objectweb.proactive.core.body.BodyAdapterImpl;
00038 import org.objectweb.proactive.core.body.UniversalBody;
00039 import org.objectweb.proactive.core.util.UrlBuilder;
00040
00041
00050 public class RmiBodyAdapter extends BodyAdapterImpl {
00051
00052
00053
00054 public RmiBodyAdapter() {
00055 }
00056
00057 protected RmiBodyAdapter(RmiRemoteBody remoteBody)
00058 throws ProActiveException {
00059 construct(remoteBody);
00060 }
00061
00062 public RmiBodyAdapter(UniversalBody body) throws ProActiveException {
00063 try {
00064 RmiRemoteBody remoteBody = new RmiRemoteBodyImpl(body);
00065 construct(remoteBody);
00066 } catch (java.rmi.RemoteException e) {
00067 throw new ProActiveException(e);
00068 }
00069 }
00070
00078 public void register(String url) throws java.io.IOException {
00079 try {
00080 java.rmi.Naming.rebind(url, (RmiRemoteBody) proxiedRemoteBody);
00081 } catch (ConnectException e) {
00082
00083
00084 String url2 = UrlBuilder.getProtocol(url) + "//" +
00085 UrlBuilder.getHostNameFromUrl(url) + ":" +
00086 System.getProperty("proactive.rmi.port") + "/" +
00087 UrlBuilder.getNameFromUrl(url);
00088
00089 java.rmi.Naming.rebind(url2, (RmiRemoteBody) proxiedRemoteBody);
00090 }
00091 }
00092
00098 public void unregister(String url) throws java.io.IOException {
00099 try {
00100 try {
00101 java.rmi.Naming.unbind(url);
00102 } catch (ConnectException e) {
00103
00104
00105 String url2 = UrlBuilder.getProtocol(url) + "//" +
00106 UrlBuilder.getHostNameFromUrl(url) + ":" +
00107 System.getProperty("proactive.rmi.port") + "/" +
00108 UrlBuilder.getNameFromUrl(url);
00109
00110 java.rmi.Naming.unbind(url2);
00111 }
00112 } catch (java.rmi.NotBoundException e) {
00113 throw new java.io.IOException(
00114 "No object is bound to the given url : " + url);
00115 }
00116 }
00117
00127 public UniversalBody lookup(String url) throws java.io.IOException {
00128 Object o = null;
00129
00130
00131 try {
00132 try {
00133 o = java.rmi.Naming.lookup(url);
00134 } catch (ConnectException e) {
00135
00136 String url2 = UrlBuilder.getProtocol(url) + "//" +
00137 UrlBuilder.getHostNameFromUrl(url) + ":" +
00138 System.getProperty("proactive.rmi.port") + "/" +
00139 UrlBuilder.getNameFromUrl(url);
00140
00141 o = java.rmi.Naming.lookup(url2);
00142 }
00143 } catch (java.rmi.NotBoundException e) {
00144 throw new java.io.IOException("The url " + url +
00145 " is not bound to any known object");
00146 }
00147
00148
00149 if (o instanceof RmiRemoteBody) {
00150 try {
00151 construct((RmiRemoteBody) o);
00152 } catch (ProActiveException e1) {
00153 throw new java.io.IOException(
00154 "The remote object at " + url + " is not accessible ");
00155 }
00156 return this;
00157 }
00158
00159 throw new java.io.IOException(
00160 "The given url does exist but doesn't point to a remote body url=" +
00161 url + " class found is " + o.getClass().getName());
00162 }
00163
00164
00171 public String [] list(String url) throws java.io.IOException {
00172 String [] names = null;
00173
00174
00175 try {
00176 names = java.rmi.Naming.list(url);
00177 } catch (MalformedURLException e) {
00178
00179
00180
00181 String url2 = UrlBuilder.getProtocol(url) + "//" +
00182 UrlBuilder.getHostNameFromUrl(url) + ":" +
00183 System.getProperty("proactive.rmi.port") + "/" ;
00184
00185 names = java.rmi.Naming.list(url2);
00186 } catch (ConnectException e) {
00187 return new String [] {};
00188 }
00189 return names;
00190 }
00191 }