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.locationserver; 00032 00033 import java.io.IOException; 00034 import java.io.ObjectInputStream; 00035 00036 import org.apache.log4j.Logger; 00037 import org.objectweb.proactive.Body; 00038 import org.objectweb.proactive.core.body.UniversalBody; 00039 import org.objectweb.proactive.core.body.migration.MigrationException; 00040 import org.objectweb.proactive.core.body.migration.MigrationManagerImpl; 00041 import org.objectweb.proactive.core.body.reply.ReplyReceiver; 00042 import org.objectweb.proactive.core.body.request.RequestReceiver; 00043 import org.objectweb.proactive.core.node.Node; 00044 import org.objectweb.proactive.core.util.log.Loggers; 00045 import org.objectweb.proactive.core.util.log.ProActiveLogger; 00046 00047 00048 public class MigrationManagerWithLocationServer extends MigrationManagerImpl { 00049 static Logger logger = ProActiveLogger.getLogger(Loggers.MIGRATION); 00050 transient private LocationServer locationServer; 00051 protected Body myBody; 00052 00053 // 00054 // -- CONSTRUCTORS ----------------------------------------------- 00055 // 00056 public MigrationManagerWithLocationServer() { 00057 } 00058 00059 public MigrationManagerWithLocationServer(LocationServer locationServer) { 00060 this.locationServer = locationServer; 00061 } 00062 00063 // 00064 // -- PUBLIC METHODS ----------------------------------------------- 00065 // 00066 00070 public void updateLocation(Body body) { 00071 if (locationServer == null) { 00072 this.locationServer = LocationServerFactory.getLocationServer(); 00073 } 00074 00075 // if (locationServer != null) { 00076 if (logger.isDebugEnabled()) { 00077 logger.debug("Updating location with this stub " + 00078 body.getRemoteAdapter()); 00079 } 00080 locationServer.updateLocation(body.getID(), body.getRemoteAdapter()); 00081 // } 00082 } 00083 00084 // 00085 // -- Implements MigrationManager ----------------------------------------------- 00086 // 00087 public UniversalBody migrateTo(Node node, Body body) 00088 throws MigrationException { 00089 locationServer = null; 00090 if (myBody == null) { 00091 this.myBody = body; 00092 } 00093 00094 // System.out.println("XXXXXXX"); 00095 UniversalBody remoteBody = super.migrateTo(node, body); 00096 00097 return remoteBody; 00098 } 00099 00100 // public void startingAfterMigration(Body body) { 00101 // //we update our location 00102 // // System.out.println("YYYYYYYY"); 00103 // super.startingAfterMigration(body); 00104 // updateLocation(body); 00105 // } 00106 public RequestReceiver createRequestReceiver(UniversalBody remoteBody, 00107 RequestReceiver currentRequestReceiver) { 00108 return new BouncingRequestReceiver(); 00109 } 00110 00111 public ReplyReceiver createReplyReceiver(UniversalBody remoteBody, 00112 ReplyReceiver currentReplyReceiver) { 00113 return currentReplyReceiver; 00114 } 00115 00116 private void readObject(ObjectInputStream in) 00117 throws IOException, ClassNotFoundException { 00118 in.defaultReadObject(); 00119 this.updateLocation(myBody); 00120 // this.updateLocation(); 00121 } 00122 }