1 31 package org.objectweb.proactive.core.node; 32 33 import org.objectweb.proactive.ActiveObjectCreationException; 34 import org.objectweb.proactive.core.Constants; 35 import org.objectweb.proactive.core.ProActiveException; 36 import org.objectweb.proactive.core.body.UniversalBody; 37 import org.objectweb.proactive.core.mop.ConstructionOfProxyObjectFailedException; 38 import org.objectweb.proactive.core.mop.MOP; 39 import org.objectweb.proactive.core.mop.MOPException; 40 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 41 import org.objectweb.proactive.core.runtime.RuntimeFactory; 42 43 import java.io.ObjectInputStream ; 44 import java.io.Serializable ; 45 46 import java.util.ArrayList ; 47 48 49 67 public class NodeImpl implements Node, Serializable { 68 protected NodeInformation nodeInformation; 69 protected ProActiveRuntime proActiveRuntime; 70 71 protected String vnName; 72 public NodeImpl() { 76 } 77 78 public NodeImpl(ProActiveRuntime proActiveRuntime, String nodeURL, 79 String protocol, String jobID) { 80 this.proActiveRuntime = proActiveRuntime; 81 this.nodeInformation = new NodeInformationImpl(nodeURL, protocol, jobID); 82 } 83 84 87 90 public NodeInformation getNodeInformation() { 91 return nodeInformation; 92 } 93 94 97 public ProActiveRuntime getProActiveRuntime() { 98 return proActiveRuntime; 99 } 100 101 104 public Object [] getActiveObjects() 105 throws NodeException, ActiveObjectCreationException { 106 ArrayList bodyArray; 107 try { 108 bodyArray = this.proActiveRuntime.getActiveObjects(this.nodeInformation.getName()); 109 } catch (ProActiveException e) { 110 throw new NodeException( 111 "Cannot get Active Objects registered on this node: " + 112 this.nodeInformation.getURL(), e); 113 } 114 if (bodyArray.size() == 0) { 115 throw new NodeException( 116 "no ActiveObjects are registered for this node: " + 117 this.nodeInformation.getURL()); 118 } else { 119 Object [] stubOnAO = new Object [bodyArray.size()]; 120 for (int i = 0; i < bodyArray.size(); i++) { 121 UniversalBody body = (UniversalBody) ((ArrayList ) bodyArray.get(i)).get(0); 122 String className = (String ) ((ArrayList ) bodyArray.get(i)).get(1); 123 try { 124 stubOnAO[i] = createStubObject(className, body); 125 } catch (MOPException e) { 126 throw new ActiveObjectCreationException("Exception occured when trying to create stub-proxy", 127 e); 128 } 129 } 130 return stubOnAO; 131 } 132 } 133 134 137 public Object [] getActiveObjects(String className) 138 throws NodeException, ActiveObjectCreationException { 139 ArrayList bodyArray; 140 try { 141 bodyArray = this.proActiveRuntime.getActiveObjects(this.nodeInformation.getName(), 142 className); 143 } catch (ProActiveException e) { 144 throw new NodeException("Cannot get Active Objects of type " + 145 className + " registered on this node: " + 146 this.nodeInformation.getURL(), e); 147 } 148 if (bodyArray.size() == 0) { 149 throw new NodeException("no ActiveObjects of type " + className + 150 " are registered for this node: " + 151 this.nodeInformation.getURL()); 152 } else { 153 Object [] stubOnAO = new Object [bodyArray.size()]; 154 for (int i = 0; i < bodyArray.size(); i++) { 155 UniversalBody body = (UniversalBody) bodyArray.get(i); 156 try { 157 stubOnAO[i] = createStubObject(className, body); 158 } catch (MOPException e) { 159 throw new ActiveObjectCreationException("Exception occured when trying to create stub-proxy", 160 e); 161 } 162 } 163 return stubOnAO; 164 } 165 } 166 167 private void readObject(ObjectInputStream in) 168 throws java.io.IOException , ClassNotFoundException , ProActiveException { 169 in.defaultReadObject(); 170 if (NodeFactory.isNodeLocal(this)) { 171 this.proActiveRuntime = RuntimeFactory.getProtocolSpecificRuntime(nodeInformation.getProtocol()); 172 } 173 } 174 175 private static Object createStubObject(String className, UniversalBody body) 181 throws MOPException { 182 return createStubObject(className, null, new Object [] { body }); 183 } 184 185 private static Object createStubObject(String className, 186 Object [] constructorParameters, Object [] proxyParameters) 187 throws MOPException { 188 try { 189 return MOP.newInstance(className, constructorParameters, 190 Constants.DEFAULT_BODY_PROXY_CLASS_NAME, proxyParameters); 191 } catch (ClassNotFoundException e) { 192 throw new ConstructionOfProxyObjectFailedException( 193 "Class can't be found e=" + e); 194 } 195 } 196 197 protected class NodeInformationImpl implements NodeInformation { 201 private String nodeName; 202 private String nodeURL; 203 private String protocol; 204 private String jobID; 205 private java.net.InetAddress hostInetAddress; 206 private java.rmi.dgc.VMID hostVMID; 207 208 public NodeInformationImpl(String url, String protocol, String jobID) { 209 this.nodeURL = url; 210 this.hostVMID = proActiveRuntime.getVMInformation().getVMID(); 211 this.hostInetAddress = proActiveRuntime.getVMInformation() 212 .getInetAddress(); 213 this.protocol = protocol; 214 this.nodeName = extractNameFromUrl(url); 215 this.jobID = jobID; 216 } 217 218 221 public java.rmi.dgc.VMID getVMID() { 222 return hostVMID; 223 } 224 225 228 public String getName() { 229 return nodeName; 230 } 231 232 235 public String getProtocol() { 236 return protocol; 237 } 238 239 242 public String getURL() { 243 return nodeURL; 244 } 245 246 249 public java.net.InetAddress getInetAddress() { 250 return hostInetAddress; 251 } 252 253 public String getCreationProtocolID() { 254 return proActiveRuntime.getVMInformation().getCreationProtocolID(); 255 } 256 257 261 public void setCreationProtocolID(String protocolId) { 262 } 264 265 270 private String extractNameFromUrl(String url) { 271 int n = url.lastIndexOf("/"); 272 String name = url.substring(n + 1); 273 return name; 274 } 275 276 279 public String getJobID() { 280 return jobID; 281 } 282 } 283 284 288 public String getVnName() { 289 return vnName; 290 } 291 292 295 public void setVnName(String string) { 296 vnName = string; 297 } 298 } 299 | Popular Tags |