1 31 package org.objectweb.proactive.ic2d.data; 32 33 import org.objectweb.proactive.ActiveObjectCreationException; 34 import org.objectweb.proactive.core.node.Node; 35 import org.objectweb.proactive.core.node.NodeException; 36 import org.objectweb.proactive.core.util.UrlBuilder; 37 import org.objectweb.proactive.ic2d.event.HostObjectListener; 38 import org.objectweb.proactive.ic2d.util.HostNodeFinder; 39 import org.objectweb.proactive.ic2d.util.IbisHostNodeFinder; 40 import org.objectweb.proactive.ic2d.util.RMIHostNodeFinder; 41 import org.objectweb.proactive.ic2d.util.RunnableProcessor; 42 43 44 47 public class HostObject extends AbstractDataObject { 48 49 50 protected String hostname; 51 52 53 protected String os; 54 protected HostNodeFinder nodeFinder; 55 protected HostObjectListener listener; 56 57 public HostObject(WorldObject parent, String hostname, String protocol) { 61 super(parent); 62 try { 64 String shortHostname = java.net.InetAddress.getByName(UrlBuilder.removePortFromHost(hostname)) 65 .getHostName(); 66 67 this.hostname = hostname; 68 69 } catch (java.net.UnknownHostException e) { 71 this.hostname = hostname; 72 controller.warn("Hostname " + hostname + " failed reverse lookup."); 73 } 74 if ("ibis".equals(protocol)) { 75 this.nodeFinder = new IbisHostNodeFinder(controller); 76 } else { 77 this.nodeFinder = new RMIHostNodeFinder(controller); 78 } 79 } 80 81 public String toString() { 85 return "Host: " + hostname + "\n" + super.toString(); 86 } 87 88 public void createAllNodes() { 89 RunnableProcessor.getInstance().processRunnable("Create nodes for " + 90 hostname, new CreateNodeTask(), controller); 91 } 92 93 public void createOneNode(String nodeName) { 94 RunnableProcessor.getInstance().processRunnable("Create one node for " + 95 hostname, new CreateNodeTask(nodeName), controller); 96 } 97 98 public String getHostName() { 102 return hostname; 103 } 104 105 public String getOperatingSystem() { 106 return os; 107 } 108 109 public void registerListener(HostObjectListener listener) { 117 this.messageMonitoringListener = listener; 118 this.listener = listener; 119 } 120 121 125 128 public VMObject addVMObject(Node node) { 129 java.rmi.dgc.VMID vmid = node.getNodeInformation().getVMID(); 130 String protocolId = node.getNodeInformation().getCreationProtocolID(); 131 VMObject vmObject = getVMObject(vmid); 132 if (vmObject != null) { 133 controller.log("The node " + node.getNodeInformation().getURL() + 134 " belongs to an already existing vm id=" + vmid); 135 vmObject.addNodeObject(node); 137 vmObject.sendEventsForAllActiveObjects(); 139 return vmObject; 140 } 141 try { 142 vmObject = new VMObject(this, vmid, node, protocolId); 143 putChild(vmid, vmObject); 144 controller.log("The node " + node.getNodeInformation().getURL() + 145 " has been found on vm id=" + vmid); 146 if (listener != null) { 147 listener.vmObjectAdded(vmObject); 148 } 149 if (os == null) { 150 os = vmObject.getSystemProperty("os.name"); 151 if (listener != null) { 152 listener.operatingSystemFound(os); 153 } 154 } 155 return vmObject; 156 } catch (ActiveObjectCreationException e) { 157 controller.log("Cannot create the spy on host " + hostname + 158 " on node " + node.getNodeInformation().getURL(), e); 159 return null; 160 } catch (NodeException e) { 161 controller.log("Problem with the node " + 162 node.getNodeInformation().getURL(), e); 163 return null; 164 } 165 } 166 167 public void removeVMObject(java.rmi.dgc.VMID id) { 168 VMObject vmObject = (VMObject) removeChild(id); 169 if ((vmObject != null) && (listener != null)) { 170 listener.vmObjectRemoved(vmObject); 171 } 172 } 173 174 public VMObject getVMObject(java.rmi.dgc.VMID id) { 175 return (VMObject) getChild(id); 176 } 177 178 public void destroyObject() { 179 getTypedParent().removeHostObject(hostname); 180 } 181 182 public synchronized VMObject findVMObjectHavingExistingNode(String nodeName) { 183 if (getChildObjectsCount() == 0) { 184 return null; 185 } 186 java.util.Iterator iterator = childsIterator(); 187 while (iterator.hasNext()) { 188 VMObject vmObject = (VMObject) iterator.next(); 189 if (vmObject.getNodeObject(nodeName) != null) { 190 controller.log("Found that vm id=" + vmObject.getID() + 191 " own the node " + nodeName); 192 return vmObject; 193 } 194 } 195 return null; 196 } 197 198 protected WorldObject getTypedParent() { 202 return (WorldObject) parent; 203 } 204 205 protected synchronized boolean destroy() { 206 if (super.destroy()) { 208 listener = null; 210 nodeFinder = null; 211 return true; 212 } else { 213 return false; 214 } 215 } 216 217 private class CreateNodeTask implements Runnable { 221 private String targetNodeName; 222 223 public CreateNodeTask() { 224 } 225 226 public CreateNodeTask(String targetNodeName) { 227 this.targetNodeName = targetNodeName; 228 } 229 230 public void run() { 231 Node[] nodes; 232 try { 233 nodes = nodeFinder.findNodes(hostname); 234 } catch (java.io.IOException e) { 236 controller.log("There is no RMI Registry on host " + hostname, e); 237 return; 238 } 239 if (nodes.length == 0) { 240 controller.warn("A RMIRegistry has been found on host " + 241 hostname + " but no Node object are bound !"); 242 } 243 for (int i = 0; i < nodes.length; i++) { 244 Node node = nodes[i]; 245 246 String nodeName = node.getNodeInformation().getName(); 248 if ((targetNodeName == null) || 249 targetNodeName.equals(nodeName)) { 250 VMObject vmObject = findVMObjectHavingExistingNode(nodeName); 251 if (vmObject == null) { 252 addVMObject(node); 254 } else { 255 controller.log("The node " + nodeName + 256 " is already known by host " + hostname + 257 " look for new objects"); 258 vmObject.sendEventsForAllActiveObjects(); 259 } 260 } 261 } 262 if ((targetNodeName != null) && 263 (findVMObjectHavingExistingNode(targetNodeName) == null)) { 264 controller.warn("The node " + targetNodeName + 265 " was not found on host " + hostname + 266 ". Check the name of the node"); 267 } 268 } 269 } 270 } 272 | Popular Tags |