00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00051 protected static Logger logger = ProActiveLogger.getLogger(Loggers.FAULT_TOLERANCE);
00052
00053
00054 private FTServer server;
00055
00056
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
00075 return null;
00076 } else if (currentLocation.equals(oldLocation)) {
00077 this.server.forceDetection();
00078 return null;
00079 } else {
00080
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
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
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 }