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.mixedlocation; 00032 00033 import java.io.IOException; 00034 import java.io.ObjectInputStream; 00035 import java.io.ObjectOutputStream; 00036 00037 import org.apache.log4j.Logger; 00038 import org.objectweb.proactive.Body; 00039 import org.objectweb.proactive.core.body.UniversalBody; 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.reply.ReplyReceiverForwarder; 00043 import org.objectweb.proactive.core.body.request.RequestReceiver; 00044 import org.objectweb.proactive.core.body.request.RequestReceiverForwarder; 00045 import org.objectweb.proactive.core.util.log.Loggers; 00046 import org.objectweb.proactive.core.util.log.ProActiveLogger; 00047 import org.objectweb.proactive.ext.locationserver.LocationServer; 00048 import org.objectweb.proactive.ext.locationserver.LocationServerFactory; 00049 00050 00051 public class MigrationManagerWithMixedLocation extends MigrationManagerImpl 00052 implements java.io.Serializable { 00053 static Logger logger = ProActiveLogger.getLogger(Loggers.MIGRATION); 00054 protected UniversalBodyWrapper wrapper; 00055 transient protected LocationServer locationServer; 00056 protected int migrationCounter; 00057 00058 public MigrationManagerWithMixedLocation() { 00059 logger.info("<init> LocationServer is " + locationServer); 00060 } 00061 00062 public MigrationManagerWithMixedLocation(LocationServer locationServer) { 00063 this.migrationCounter = 0; 00064 if (logger.isDebugEnabled()) { 00065 logger.debug("LocationServer is " + locationServer); 00066 } 00067 this.locationServer = locationServer; 00068 } 00069 00070 protected synchronized void createWrapper(UniversalBody remoteBody) { 00071 if (this.wrapper == null) { 00072 this.wrapper = new UniversalBodyWrapper(remoteBody, 6000); 00073 } 00074 } 00075 00076 public RequestReceiver createRequestReceiver(UniversalBody remoteBody, 00077 RequestReceiver currentRequestReceiver) { 00078 this.createWrapper(remoteBody); 00079 return new RequestReceiverForwarder(wrapper); 00080 } 00081 00082 public ReplyReceiver createReplyReceiver(UniversalBody remoteBody, 00083 ReplyReceiver currentReplyReceiver) { 00084 this.createWrapper(wrapper); 00085 return new ReplyReceiverForwarder(wrapper); 00086 } 00087 00088 public void updateLocation(Body body) { 00089 if (locationServer == null) { 00090 this.locationServer = LocationServerFactory.getLocationServer(); 00091 } 00092 if (locationServer != null) { 00093 locationServer.updateLocation(body.getID(), body.getRemoteAdapter()); 00094 } 00095 } 00096 00097 public void startingAfterMigration(Body body) { 00098 super.startingAfterMigration(body); 00099 //we update our location 00100 this.migrationCounter++; 00101 if (logger.isDebugEnabled()) { 00102 logger.debug("XXX counter == " + this.migrationCounter); 00103 } 00104 00105 // if (this.migrationCounter > 3) { 00106 updateLocation(body); 00107 } 00108 00109 private void readObject(ObjectInputStream in) 00110 throws IOException, ClassNotFoundException { 00111 if (logger.isDebugEnabled()) { 00112 logger.debug("MigrationManagerWithMixedLocation readObject XXXXXXX"); 00113 } 00114 in.defaultReadObject(); 00115 } 00116 00117 private void writeObject(ObjectOutputStream out) throws IOException { 00118 if (logger.isDebugEnabled()) { 00119 logger.debug("MigrationManagerWithMixedLocation writeObject YYYYYY"); 00120 } 00121 this.locationServer = null; 00122 out.defaultWriteObject(); 00123 } 00124 }