1 package org.objectweb.proactive.core.runtime.ibis; 2 3 import ibis.rmi.AlreadyBoundException; 4 import ibis.rmi.Naming; 5 import ibis.rmi.NotBoundException; 6 import ibis.rmi.RemoteException; 7 import ibis.rmi.server.UnicastRemoteObject; 8 9 import java.io.IOException ; 10 import java.lang.reflect.InvocationTargetException ; 11 import java.net.UnknownHostException ; 12 import java.security.cert.X509Certificate ; 13 import java.util.ArrayList ; 14 15 import org.objectweb.proactive.Body; 16 import org.objectweb.proactive.core.body.UniversalBody; 17 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 18 import org.objectweb.proactive.core.mop.ConstructorCall; 19 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException; 20 import org.objectweb.proactive.core.node.NodeException; 21 import org.objectweb.proactive.core.process.UniversalProcess; 22 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 23 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl; 24 import org.objectweb.proactive.core.runtime.VMInformation; 25 import org.objectweb.proactive.core.runtime.rmi.RemoteRuntimeFactory; 26 import org.objectweb.proactive.core.util.UrlBuilder; 27 import org.objectweb.proactive.ext.security.PolicyServer; 28 import org.objectweb.proactive.ext.security.ProActiveSecurityManager; 29 30 31 37 public class RemoteProActiveRuntimeImpl extends UnicastRemoteObject 38 implements RemoteProActiveRuntime { 39 protected transient ProActiveRuntimeImpl proActiveRuntime; 40 protected String proActiveRuntimeURL; 41 42 protected ArrayList nodesArray; 44 45 protected ArrayList vnNodesArray; 47 48 public RemoteProActiveRuntimeImpl() 52 throws RemoteException, AlreadyBoundException { 53 this.proActiveRuntime = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime(); 55 this.nodesArray = new java.util.ArrayList (); 56 this.vnNodesArray = new java.util.ArrayList (); 57 this.proActiveRuntimeURL = buildRuntimeURL(); 58 register(proActiveRuntimeURL, false); 59 } 60 61 public String createLocalNode(String nodeName, 65 boolean replacePreviousBinding, PolicyServer ps, String vnname, String jobId) throws RemoteException, NodeException { 66 String nodeURL = null; 67 68 try { 70 nodeURL = buildNodeURL(nodeName); 72 String name = UrlBuilder.getNameFromUrl(nodeURL); 74 75 register(nodeURL, replacePreviousBinding); 77 proActiveRuntime.createLocalNode(name, replacePreviousBinding,ps,vnname, jobId); 78 } catch (java.net.UnknownHostException e) { 79 throw new RemoteException("Host unknown in " + nodeURL, e); 80 } 81 nodesArray.add(nodeURL); 82 return nodeURL; 83 } 84 85 public void killAllNodes() throws RemoteException { 86 for (int i = 0; i < nodesArray.size(); i++) { 87 String url = (String ) nodesArray.get(i); 88 killNode(url); 89 } 90 } 91 92 public void killNode(String nodeName) throws RemoteException { 93 String nodeUrl = null; 94 String name = null; 95 try { 96 nodeUrl = buildNodeURL(nodeName); 97 name = UrlBuilder.getNameFromUrl(nodeUrl); 98 unregister(nodeUrl); 99 } catch (UnknownHostException e) { 100 throw new RemoteException("Host unknown in " + nodeUrl, e); 101 } 102 proActiveRuntime.killNode(nodeName); 103 } 104 105 public void createVM(UniversalProcess remoteProcess) 111 throws IOException { 112 proActiveRuntime.createVM(remoteProcess); 113 } 114 115 public String [] getLocalNodeNames() { 120 return proActiveRuntime.getLocalNodeNames(); 121 } 122 123 public VMInformation getVMInformation() { 137 return proActiveRuntime.getVMInformation(); 138 } 139 140 public void register(ProActiveRuntime proActiveRuntimeDist, 141 String proActiveRuntimeName, String creatorID, String creationProtocol, String vmName) { 142 proActiveRuntime.register(proActiveRuntimeDist, proActiveRuntimeName, 143 creatorID, creationProtocol,vmName); 144 } 145 146 public ProActiveRuntime[] getProActiveRuntimes() { 147 return proActiveRuntime.getProActiveRuntimes(); 148 } 149 150 public ProActiveRuntime getProActiveRuntime(String proActiveRuntimeName) { 151 return proActiveRuntime.getProActiveRuntime(proActiveRuntimeName); 152 } 153 154 public void killRT(boolean softly) throws RemoteException { 155 killAllNodes(); 156 unregisterAllVirtualNodes(); 157 unregister(proActiveRuntimeURL); 158 proActiveRuntime.killRT(false); 159 } 160 161 public String getURL() { 162 return proActiveRuntimeURL; 163 } 164 165 public ArrayList getActiveObjects(String nodeName) { 166 return proActiveRuntime.getActiveObjects(nodeName); 167 } 168 169 public ArrayList getActiveObjects(String nodeName, String objectName) { 170 return proActiveRuntime.getActiveObjects(nodeName, objectName); 171 } 172 173 public VirtualNode getVirtualNode(String virtualNodeName) { 174 return proActiveRuntime.getVirtualNode(virtualNodeName); 175 } 176 177 public void registerVirtualNode(String virtualNodeName, 178 boolean replacePreviousBinding) throws RemoteException { 179 String virtualNodeURL = null; 180 181 try { 182 virtualNodeURL = buildNodeURL(virtualNodeName); 184 register(virtualNodeURL, replacePreviousBinding); 186 } catch (java.net.UnknownHostException e) { 187 throw new RemoteException("Host unknown in " + virtualNodeURL, e); 188 } 189 vnNodesArray.add(virtualNodeURL); 190 } 191 192 public void unregisterVirtualNode(String virtualnodeName) 193 throws RemoteException { 194 String virtualNodeURL = null; 195 proActiveRuntime.unregisterVirtualNode(UrlBuilder.removeVnSuffix( 196 virtualnodeName)); 197 try { 198 virtualNodeURL = buildNodeURL(virtualnodeName); 200 unregister(virtualNodeURL); 201 } catch (java.net.UnknownHostException e) { 202 throw new RemoteException("Host unknown in " + virtualNodeURL, e); 203 } 204 vnNodesArray.remove(virtualNodeURL); 205 } 206 207 public void unregisterAllVirtualNodes() throws RemoteException { 208 for (int i = 0; i < vnNodesArray.size(); i++) { 209 String url = (String ) vnNodesArray.get(i); 210 unregisterVirtualNode(url); 211 } 212 } 213 214 public UniversalBody createBody(String nodeName, 215 ConstructorCall bodyConstructorCall, boolean isNodeLocal) 216 throws ConstructorCallExecutionFailedException, 217 InvocationTargetException { 218 return proActiveRuntime.createBody(nodeName, bodyConstructorCall, 219 isNodeLocal); 220 } 221 222 public UniversalBody receiveBody(String nodeName, Body body) { 223 return proActiveRuntime.receiveBody(nodeName, body); 224 } 225 226 230 public X509Certificate getCreatorCertificate() 231 throws RemoteException { 232 return proActiveRuntime.getCreatorCertificate(); 233 } 234 235 238 public PolicyServer getPolicyServer() throws RemoteException { 239 return proActiveRuntime.getPolicyServer(); 240 } 241 242 public String getVNName(String nodename) throws RemoteException { 243 return proActiveRuntime.getVNName(nodename); 244 } 245 246 public void setProActiveSecurityManager(ProActiveSecurityManager ps) 247 throws RemoteException { 248 proActiveRuntime.setProActiveSecurityManager(ps); 249 } 250 251 254 public void setDefaultNodeVirtualNodeName(String s) 255 throws RemoteException { 256 proActiveRuntime.setDefaultNodeVirtualNodeName(s); 257 } 258 259 262 public void updateLocalNodeVirtualName() throws RemoteException { 263 } 265 266 269 public void listVirtualNodes() throws RemoteException { 270 proActiveRuntime.listVirtualNodes(); 271 } 272 273 276 public PolicyServer getNodePolicyServer(String nodeName) throws RemoteException { 277 return null; 278 } 279 280 283 public void enableSecurityIfNeeded() throws RemoteException { 284 286 } 287 288 291 public X509Certificate getNodeCertificate(String nodeName) throws RemoteException{ 292 return proActiveRuntime.getNodeCertificate(nodeName); 293 } 294 295 299 public ArrayList getEntities(String nodeName)throws RemoteException { 300 return proActiveRuntime.getEntities(nodeName); 301 } 302 303 307 public ArrayList getEntities(UniversalBody uBody) throws RemoteException { 308 return proActiveRuntime.getEntities(uBody); 309 } 310 311 312 313 316 public ArrayList getEntities() throws RemoteException { 317 return proActiveRuntime.getEntities(); 318 } 319 320 323 public String getJobID(String nodeUrl) throws RemoteException { 324 return proActiveRuntime.getJobID(nodeUrl); 325 } 326 327 328 329 330 private void register(String url, boolean replacePreviousBinding) 334 throws RemoteException { 335 try { 336 if (replacePreviousBinding) { 337 Naming.rebind(UrlBuilder.removeProtocol(url, "ibis:"), this); 338 } else { 339 Naming.bind(UrlBuilder.removeProtocol(url, "ibis:"), this); 340 } 341 if(url.indexOf("PA_RT")<0){ 342 logger.info(url + " successfully bound in registry at " + url); 343 } 344 } catch (AlreadyBoundException e) { 345 throw new RemoteException(url + " already bound in registry", e); 346 } catch (java.net.MalformedURLException e) { 347 throw new RemoteException("cannot bind in registry at " + url, e); 348 } 349 } 350 351 private void unregister(String url) throws RemoteException { 352 try { 353 Naming.unbind(UrlBuilder.removeProtocol(url, "ibis:")); 354 if(url.indexOf("PA_RT")<0){ 355 logger.info(url + " unbound in registry"); 356 } 357 } catch (java.net.MalformedURLException e) { 358 throw new RemoteException("cannot unbind in registry at " + url, e); 359 } catch (NotBoundException e) { 360 throw new RemoteException(url + "is not bound in the registry", e); 361 } 362 } 363 364 private String buildRuntimeURL() { 365 int port = RemoteRuntimeFactory.getRegistryHelper() 366 .getRegistryPortNumber(); 367 String host = getVMInformation().getInetAddress().getCanonicalHostName(); 368 String name = getVMInformation().getName(); 369 370 return UrlBuilder.buildUrl(host, name, "ibis:", port); 371 } 372 373 private String buildNodeURL(String url) 374 throws java.net.UnknownHostException { 375 int i = url.indexOf('/'); 376 377 if (i == -1) { 378 String host = getVMInformation().getInetAddress().getCanonicalHostName(); 380 int port = RemoteRuntimeFactory.getRegistryHelper() 381 .getRegistryPortNumber(); 382 return UrlBuilder.buildUrl(host, url, "ibis:", port); 383 } else { 384 return UrlBuilder.checkUrl(url); 385 } 386 } 387 388 389 } 390 | Popular Tags |