org/objectweb/proactive/core/body/ft/servers/location/LocationServerImpl.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.core.body.ft.servers.location;
00032 
00033 import java.rmi.RemoteException;
00034 import java.util.ArrayList;
00035 import java.util.Hashtable;
00036 
00037 import org.apache.log4j.Logger;
00038 import org.objectweb.proactive.core.UniqueID;
00039 import org.objectweb.proactive.core.body.UniversalBody;
00040 import org.objectweb.proactive.core.body.ft.servers.FTServer;
00041 import org.objectweb.proactive.core.util.log.Loggers;
00042 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00043 
00044 
00049 public class LocationServerImpl implements LocationServer {
00050     //logger
00051     protected static Logger logger = ProActiveLogger.getLogger(Loggers.FAULT_TOLERANCE);
00052 
00053     // global server
00054     private FTServer server;
00055 
00056     // locations table : id <-> adapter
00057     private Hashtable locations;
00058 
00059     public LocationServerImpl(FTServer server) {
00060         this.server = server;
00061         this.locations = new Hashtable();
00062     }
00063 
00067     public UniversalBody searchObject(UniqueID id, UniversalBody oldLocation,
00068         UniqueID caller) throws RemoteException {
00069         synchronized (this.locations) {
00070             UniversalBody currentLocation = (UniversalBody) (this.locations.get(id));
00071             if (currentLocation == null) {
00072                 logger.error("[LOCATION] **ERROR** " + id +
00073                     " is not registered !");
00074                 //throw new RuntimeException("TEST");
00075                 return null;
00076             } else if (currentLocation.equals(oldLocation)) {
00077                 this.server.forceDetection();
00078                 return null;
00079             } else {
00080                 // send the new location of id
00081                 logger.debug("[LOCATION] Return the new location of " + id);
00082                 return currentLocation;
00083             }
00084         }
00085     }
00086 
00090     public void updateLocation(UniqueID id, UniversalBody newLocation)
00091         throws RemoteException {
00092         synchronized (this.locations) {
00093             UniversalBody currentLocation = (UniversalBody) (this.locations.get(id));
00094             if (newLocation == null) {
00095                 // the body id is no more localized. Remove it from the location table
00096                 logger.info("[LOCATION] " + id +
00097                     " is removed from the location table");
00098                 this.locations.remove(id);
00099                 return;
00100             } else if (currentLocation == null) {
00101                 // register the location
00102                 this.locations.put(id, newLocation);
00103             } else {
00104                 if (currentLocation.equals(newLocation)) {
00105                     logger.info("[LOCATION] location of " + id +
00106                         " is already " + newLocation.getNodeURL());
00107                 } else {
00108                     logger.info("[LOCATION] " + id +
00109                         " is updating its location : " +
00110                         newLocation.getNodeURL());
00111                     this.locations.put(id, newLocation);
00112                 }
00113             }
00114         }
00115     }
00116 
00120     public ArrayList getAllLocations() throws RemoteException {
00121         synchronized (this.locations) {
00122             return new ArrayList(locations.values());
00123         }
00124     }
00125 
00129     public UniversalBody getLocation(UniqueID id) throws RemoteException {
00130         synchronized (this.locations) {
00131             return (UniversalBody) (this.locations.get(id));
00132         }
00133     }
00134 
00138     public void initialize() throws RemoteException {
00139         this.locations = new Hashtable();
00140     }
00141 }

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