org/objectweb/proactive/ext/util/SimpleLocationServer.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.ext.util;
00032 
00033 import java.net.UnknownHostException;
00034 
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.proactive.ProActive;
00037 import org.objectweb.proactive.core.UniqueID;
00038 import org.objectweb.proactive.core.body.BodyMap;
00039 import org.objectweb.proactive.core.body.UniversalBody;
00040 import org.objectweb.proactive.core.node.NodeFactory;
00041 import org.objectweb.proactive.core.util.UrlBuilder;
00042 import org.objectweb.proactive.core.util.log.Loggers;
00043 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00044 import org.objectweb.proactive.ext.locationserver.LocationServer;
00045 
00046 
00050 public class SimpleLocationServer implements org.objectweb.proactive.RunActive,
00051     LocationServer {
00052     static Logger logger = ProActiveLogger.getLogger(Loggers.MIGRATION);
00053     private BodyMap table;
00054     private String url;
00055 
00056     public SimpleLocationServer() {
00057     }
00058 
00059     public SimpleLocationServer(String url) {
00060         this.url = normalizeURL(url);
00061         this.table = new BodyMap();
00062     }
00063 
00068     public void updateLocation(UniqueID i, UniversalBody s) {
00069         //       System.out.println("Server: updateLocation() " + i + " object = " + s);
00070         table.updateBody(i, s);
00071     }
00072 
00077     public UniversalBody searchObject(UniqueID id) {
00078         return (UniversalBody) table.getBody(id);
00079     }
00080 
00085     public void runActivity(org.objectweb.proactive.Body body) {
00086         this.register();
00087         org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body);
00088         service.fifoServing();
00089     }
00090 
00091     protected String normalizeURL(String url) {
00092         String tmp = url;
00093 
00094         //if it starts with rmi we remove it
00095         String temp = null;
00096         try {
00097             tmp = UrlBuilder.checkUrl(url);
00098         } catch (UnknownHostException e) {
00099             e.printStackTrace();
00100         }
00101         return tmp;
00102     }
00103 
00104     protected void register() {
00105         try {
00106             logger.info("Attempt at binding : " + url);
00107             ProActive.register(ProActive.getStubOnThis(), url);
00108             logger.info("Location Server bound in registry : " + url);
00109         } catch (Exception e) {
00110             logger.fatal("Cannot bind in registry - aborting " + url);
00111             e.printStackTrace();
00112             return;
00113         }
00114     }
00115 
00116     public static void main(String[] args) {
00117         if (args.length < 1) {
00118             logger.error(
00119                 "usage: java org.objectweb.proactive.ext.util.SimpleLocationServer <server url> [node]");
00120             System.exit(-1);
00121         }
00122         Object[] arg = new Object[1];
00123         arg[0] = args[0];
00124         SimpleLocationServer server = null;
00125         try {
00126             if (args.length == 2) {
00127                 server = (SimpleLocationServer) ProActive.newActive("org.objectweb.proactive.ext.util.SimpleLocationServer",
00128                         arg, NodeFactory.getNode(args[1]));
00129             } else {
00130                 server = (SimpleLocationServer) ProActive.newActive("org.objectweb.proactive.ext.util.SimpleLocationServer",
00131                         arg);
00132             }
00133         } catch (Exception e) {
00134             e.printStackTrace();
00135         }
00136     }
00137 
00138         public void updateLocation(UniqueID i, UniversalBody s, int version) {
00139                 this.updateLocation(i,s,0);
00140                 
00141         }
00142 }

Generated on Mon Jan 22 15:16:11 2007 for ProActive by  doxygen 1.5.1