1 31 package org.objectweb.proactive.ic2d.data; 32 33 import org.objectweb.proactive.core.util.UrlBuilder; 34 import org.objectweb.proactive.ic2d.event.WorldObjectListener; 35 import org.objectweb.proactive.ic2d.util.CreateJiniNodeTask; 36 import org.objectweb.proactive.ic2d.util.RunnableProcessor; 37 38 41 public class WorldObject extends AbstractDataObject { 42 43 protected WorldObjectListener listener; 44 45 49 public WorldObject(IC2DObject parent) { 50 super(parent); 51 controller.log("WorldObject created"); 52 } 53 54 55 59 60 64 public void registerListener(WorldObjectListener listener) { 65 this.messageMonitoringListener = listener; 66 this.listener = listener; 67 } 68 69 70 71 75 public HostObject addHostObject(String hostname, String protocol) throws java.rmi.RemoteException { 76 return addHostObject(hostname, null, protocol); 77 } 78 79 80 public HostObject addHostObject(String hostname, String nodeName, String protocol) throws java.rmi.RemoteException { 81 String shortHostname = null; 82 try { 83 shortHostname = java.net.InetAddress.getByName(UrlBuilder.removePortFromHost(hostname)).getHostName(); 84 } catch (java.net.UnknownHostException e) { 85 controller.warn("Hostname "+shortHostname+ " failed reverse lookup."); 86 return null; 87 } 88 HostObject host = getHostObject(hostname); 89 if (host == null) { 90 host = new HostObject(this, hostname, protocol); 91 putChild(hostname, host); 92 if (listener != null) listener.hostObjectAdded(host); 93 } else { 94 controller.log("Hostname "+hostname+ " already monitored, check for new nodes."); 95 } 96 if (nodeName == null) { 97 host.createAllNodes(); 98 } else { 99 host.createOneNode(nodeName); 100 } 101 return host; 102 } 103 104 public void addHosts(){ 105 RunnableProcessor.getInstance().processRunnable("Create Jini nodes", new CreateJiniNodeTask(this), controller); 106 } 107 108 public void addHosts(String host){ 109 RunnableProcessor.getInstance().processRunnable("Create Jini nodes", new CreateJiniNodeTask(this, host), controller); 110 } 111 112 public void addHostsObject(HostObject host){ 113 if (listener != null) listener.hostObjectAdded(host); 114 } 115 116 117 public void removeHostObject(String hostname) { 118 HostObject host = (HostObject) removeChild(hostname); 119 if (host != null) { 120 if (listener != null) listener.hostObjectRemoved(host); 121 } 122 } 123 124 125 public HostObject getHostObject(String hostname) { 126 return (HostObject) getChild(hostname); 127 } 128 129 130 public void destroyObject() { 131 destroy(); 132 } 133 134 135 139 protected IC2DObject getTypedParent() { 140 return (IC2DObject)parent; 141 } 142 143 144 147 protected synchronized boolean destroy() { 148 if (super.destroy()) { 149 listener = null; 150 return true; 151 } else { 152 return false; 153 } 154 } 155 156 157 161 } 162 163 164 | Popular Tags |