1 31 package org.objectweb.proactive.core.node; 32 33 import java.net.UnknownHostException ; 34 35 import org.apache.log4j.Logger; 36 import org.objectweb.proactive.ProActive; 37 import org.objectweb.proactive.core.ProActiveException; 38 import org.objectweb.proactive.core.UniqueID; 39 import org.objectweb.proactive.core.config.ProActiveConfiguration; 40 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 41 import org.objectweb.proactive.core.runtime.RuntimeFactory; 42 import org.objectweb.proactive.core.util.UrlBuilder; 43 import org.objectweb.proactive.ext.security.PolicyServer; 44 45 46 73 public class NodeFactory { 74 protected static Logger logger = Logger.getLogger(NodeFactory.class.getName()); 75 private static final String DEFAULT_NODE_NAME; 76 private static Node defaultNode = null; 77 78 static { 79 ProActiveConfiguration.load(); 80 81 String protocol = UrlBuilder.checkProtocol(System.getProperty( 82 "proactive.communication.protocol")); 83 String port = System.getProperty("proactive.rmi.port"); 84 if (port != null) { 85 DEFAULT_NODE_NAME = UrlBuilder.buildUrl("localhost", "Node", 86 protocol, new Integer (port).intValue()); 87 } else { 88 DEFAULT_NODE_NAME = UrlBuilder.buildUrl("localhost", "Node", 89 protocol); 90 } 91 } 92 93 99 105 public static synchronized Node getDefaultNode() throws NodeException { 106 String nodeURL; 107 ProActiveRuntime defaultRuntime; 108 String jobID = ProActive.getJobId(); 109 if (defaultNode == null) { 110 try { 111 defaultRuntime = RuntimeFactory.getDefaultRuntime(); 112 nodeURL = defaultRuntime.createLocalNode(DEFAULT_NODE_NAME + 113 Integer.toString( 114 new java.util.Random (System.currentTimeMillis()).nextInt()), 115 false,defaultRuntime.getPolicyServer(), "currentJVM",jobID ); 116 } catch (ProActiveException e) { 117 throw new NodeException("Cannot create the default Node", e); 118 } 119 defaultNode = new NodeImpl(defaultRuntime, nodeURL, 120 UrlBuilder.checkProtocol(System.getProperty("proactive.communication.protocol")), jobID); 121 } 122 return defaultNode; 123 } 124 125 129 public static boolean isNodeLocal(Node node) { 130 return node.getNodeInformation().getVMID().equals(UniqueID.getCurrentVMID()); 131 } 132 133 147 public static Node createNode(String nodeURL) throws NodeException { 148 return createNode(nodeURL, false,null,null); 149 } 150 151 166 public static Node createNode(String url, boolean replacePreviousBinding, PolicyServer ps, String vnname) 167 throws NodeException { 168 ProActiveRuntime proActiveRuntime; 169 String nodeURL; 170 String jobID = ProActive.getJobId(); 171 172 if (logger.isDebugEnabled()) { 173 logger.debug("NodeFactory: createNode(" + url + ")"); 174 } 175 176 String protocol = UrlBuilder.getProtocol(url); 178 179 try { 182 proActiveRuntime = RuntimeFactory.getProtocolSpecificRuntime(protocol); 183 nodeURL = proActiveRuntime.createLocalNode(url, 184 replacePreviousBinding,ps,vnname, jobID); 185 } catch (ProActiveException e) { 186 throw new NodeException("Cannot create a Node based on " + url, e); 187 } 188 Node node = new NodeImpl(proActiveRuntime, nodeURL, protocol, jobID); 189 return node; 190 } 191 192 199 public static Node getNode(String nodeURL) throws NodeException { 200 ProActiveRuntime proActiveRuntime; 201 String url; 202 String nodeName; 203 String jobID; 204 205 if (logger.isDebugEnabled()) { 206 logger.debug("NodeFactory: getNode() for " + nodeURL); 207 } 208 209 String protocol = UrlBuilder.getProtocol(nodeURL); 211 212 try { 214 url = UrlBuilder.checkUrl(nodeURL); 215 proActiveRuntime = RuntimeFactory.getRuntime(url, protocol); 216 jobID = proActiveRuntime.getJobID(url); 217 } catch (ProActiveException e) { 218 throw new NodeException("Cannot get the node based on " + nodeURL, e); 219 } catch (UnknownHostException e) { 220 throw new NodeException("Cannot get the node based on " + nodeURL, e); 221 } 222 Node node = new NodeImpl(proActiveRuntime, url, protocol, jobID); 223 return node; 224 } 225 226 231 public static void killNode(String nodeURL) throws NodeException { 232 ProActiveRuntime proActiveRuntime; 233 String url; 234 235 String protocol = UrlBuilder.getProtocol(nodeURL); 236 try { 237 url = UrlBuilder.checkUrl(nodeURL); 238 proActiveRuntime = RuntimeFactory.getRuntime(url, protocol); 239 proActiveRuntime.killNode(url); 240 } catch (ProActiveException e) { 241 throw new NodeException("Cannot get the node based on " + nodeURL, e); 242 } catch (UnknownHostException e) { 243 throw new NodeException("Cannot get the node based on " + nodeURL, e); 244 } 245 } 246 } 247 | Popular Tags |