1 31 package org.objectweb.proactive.ext.util; 32 33 import org.apache.log4j.Logger; 34 35 import org.objectweb.proactive.ProActive; 36 import org.objectweb.proactive.core.UniqueID; 37 import org.objectweb.proactive.core.body.BodyMap; 38 import org.objectweb.proactive.core.body.UniversalBody; 39 import org.objectweb.proactive.core.node.NodeFactory; 40 import org.objectweb.proactive.ext.locationserver.LocationServer; 41 42 43 46 public class SimpleLocationServer implements org.objectweb.proactive.RunActive, 47 LocationServer { 48 static Logger logger = Logger.getLogger(SimpleLocationServer.class.getName()); 49 private BodyMap table; 50 private String url; 51 52 public SimpleLocationServer() { 53 } 54 55 public SimpleLocationServer(String url) { 56 this.url = normalizeURL(url); 57 this.table = new BodyMap(); 58 } 59 60 64 public void updateLocation(UniqueID i, UniversalBody s) { 65 table.updateBody(i, s); 67 } 68 69 73 public UniversalBody searchObject(UniqueID id) { 74 return (UniversalBody) table.getBody(id); 75 } 76 77 81 public void runActivity(org.objectweb.proactive.Body body) { 82 this.register(); 83 org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body); 84 service.fifoServing(); 85 } 86 87 protected String normalizeURL(String url) { 88 String tmp = url; 89 90 if (url.startsWith("rmi:")) { 92 tmp = url.substring(4); 93 } 94 if (url.startsWith("ibis:")) { 95 tmp = url.substring(5); 96 } 97 98 if (!tmp.startsWith("//")) { 99 tmp = "//" + tmp; 100 } 101 return tmp; 102 } 103 104 protected void register() { 105 try { 106 logger.info("Attempt at binding : " + url); 107 ProActive.register(ProActive.getStubOnThis(), url); 108 logger.info("Location Server bound in registry : " + url); 109 } catch (Exception e) { 110 logger.fatal("Cannot bind in registry - aborting " + url); 111 e.printStackTrace(); 112 return; 113 } 114 } 115 116 public static void main(String [] args) { 117 if (args.length < 1) { 118 logger.error( 119 "usage: java org.objectweb.proactive.ext.util.SimpleLocationServer <server url> [node]"); 120 System.exit(-1); 121 } 122 Object [] arg = new Object [1]; 123 arg[0] = args[0]; 124 SimpleLocationServer server = null; 125 try { 126 if (args.length == 2) { 127 server = (SimpleLocationServer) ProActive.newActive("org.objectweb.proactive.ext.util.SimpleLocationServer", 128 arg, NodeFactory.getNode(args[1])); 129 } else { 130 server = (SimpleLocationServer) ProActive.newActive("org.objectweb.proactive.ext.util.SimpleLocationServer", 131 arg); 132 } 133 } catch (Exception e) { 134 e.printStackTrace(); 135 } 136 } 137 } 138 | Popular Tags |