1 31 package org.objectweb.proactive.ic2d.util; 32 33 import ibis.rmi.NotBoundException; 34 import ibis.rmi.registry.LocateRegistry; 35 import ibis.rmi.registry.Registry; 36 37 import org.apache.log4j.Logger; 38 import org.objectweb.proactive.core.ProActiveException; 39 import org.objectweb.proactive.core.node.Node; 40 import org.objectweb.proactive.core.node.NodeImpl; 41 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 42 import org.objectweb.proactive.core.runtime.ibis.RemoteProActiveRuntime; 43 import org.objectweb.proactive.core.runtime.ibis.RemoteProActiveRuntimeAdapter; 44 import org.objectweb.proactive.core.util.IbisProperties; 45 46 49 public class IbisHostNodeFinder implements HostNodeFinder { 50 51 static Logger log4jlogger = Logger.getLogger(IbisHostNodeFinder.class.getName()); 52 53 static { 54 IbisProperties.load(); 55 } 56 57 private static final int DEFAULT_RMI_PORT = 1099; 58 private IC2DMessageLogger logger; 59 60 64 public IbisHostNodeFinder(IC2DMessageLogger logger) { 65 this.logger = logger; 66 } 67 68 public IbisHostNodeFinder() { 69 } 70 71 72 76 80 public Node[] findNodes(String host) throws java.io.IOException { 81 log("RMIHostNodeFinder findNodes for " + host); 83 String hostname = host; 84 int port = DEFAULT_RMI_PORT; 85 int pos = host.lastIndexOf(":"); 86 if (pos != -1) { 87 try { 89 port = Integer.parseInt(host.substring(1 + pos)); 90 } catch (NumberFormatException e) { 91 port = DEFAULT_RMI_PORT; 92 } 93 hostname = host.substring(0, pos); 94 } 95 log("Trying " + hostname + ":" + port); 96 97 Registry registry = LocateRegistry.getRegistry(hostname, port); 99 return findNodes(registry,host); 100 } 101 102 103 107 private Node[] findNodes(Registry registry, String host) throws java.io.IOException { 108 log("Listing bindings for " + registry); 110 String [] list = registry.list(); 111 if(log4jlogger.isDebugEnabled()){ 112 log4jlogger.debug("list " + list.length); 113 } 114 if (list.length == 0) { 115 return new Node[0]; 116 } 117 java.util.ArrayList nodes = new java.util.ArrayList (list.length); 118 for (int i = 0; i < list.length; i++) { 119 Object obj; 120 if(list[i].indexOf("PA_RT")== -1 && list[i].indexOf("SpyListenerNode") == -1 && list[i].indexOf("_VN")== -1){ 122 try { 124 obj = registry.lookup(list[i]); 125 } catch (NotBoundException e) { 126 log(" registry.lookup of "+list[i]+" throwed ex=" + e); 128 continue; 129 } 130 if (obj instanceof org.objectweb.proactive.core.runtime.ibis.RemoteProActiveRuntime) { 134 log(" -> Found remote node " + list[i]); 136 try { 138 ProActiveRuntime part = new RemoteProActiveRuntimeAdapter((RemoteProActiveRuntime)obj); 139 String url = "//"+host+"/"+list[i]; 140 nodes.add(new NodeImpl(part,url,"rmi", url)); 141 } catch (ProActiveException e) { 142 log("Error while trying to create a RuntimeAdapter for "+list[i]+", check the version of ProActive or jdk"); 143 } 144 } 145 } 146 } 147 Node[] nodeArray = new Node[nodes.size()]; 148 if (nodes.size() > 0) { 149 nodeArray = (Node[]) nodes.toArray(nodeArray); 150 } 151 return nodeArray; 152 } 153 154 155 private void log(String s) { 156 if (logger != null) { 157 logger.log(s); 158 } else { 159 log4jlogger.info(s); 160 } 161 } 162 163 private void log(String s, Exception e) { 164 if (logger != null) { 165 logger.log(s, e); 166 } else { 167 log4jlogger.info(s); 168 e.printStackTrace(); 169 } 170 } 171 } 172 | Popular Tags |