KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ext > locationserver > MigrationManagerWithLocationServer


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8  * Contact: proactive-support@inria.fr
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  * Initial developer(s): The ProActive Team
26  * http://www.inria.fr/oasis/ProActive/contacts.html
27  * Contributor(s):
28  *
29  * ################################################################
30  */

31 package org.objectweb.proactive.ext.locationserver;
32
33 import org.apache.log4j.Logger;
34
35 import org.objectweb.proactive.Body;
36 import org.objectweb.proactive.core.body.UniversalBody;
37 import org.objectweb.proactive.core.body.migration.MigrationException;
38 import org.objectweb.proactive.core.body.migration.MigrationManagerImpl;
39 import org.objectweb.proactive.core.body.reply.ReplyReceiver;
40 import org.objectweb.proactive.core.body.request.RequestReceiver;
41 import org.objectweb.proactive.core.node.Node;
42
43 import java.io.IOException JavaDoc;
44 import java.io.ObjectInputStream JavaDoc;
45
46
47 public class MigrationManagerWithLocationServer extends MigrationManagerImpl {
48     static Logger logger = Logger.getLogger(MigrationManagerWithLocationServer.class.getName());
49     transient private LocationServer locationServer;
50     protected Body myBody;
51
52     //
53
// -- CONSTRUCTORS -----------------------------------------------
54
//
55
public MigrationManagerWithLocationServer() {
56     }
57
58     public MigrationManagerWithLocationServer(LocationServer locationServer) {
59         this.locationServer = locationServer;
60     }
61
62     //
63
// -- PUBLIC METHODS -----------------------------------------------
64
//
65

66     /**
67      * update our location on the Location Server
68      */

69     public void updateLocation(Body body) {
70         if (locationServer == null) {
71             this.locationServer = LocationServerFactory.getLocationServer();
72         }
73
74         // if (locationServer != null) {
75
if (logger.isDebugEnabled()) {
76             logger.debug("Updating location with this stub " +
77                 body.getRemoteAdapter());
78         }
79         locationServer.updateLocation(body.getID(), body.getRemoteAdapter());
80         // }
81
}
82
83     //
84
// -- Implements MigrationManager -----------------------------------------------
85
//
86
public UniversalBody migrateTo(Node node, Body body)
87         throws MigrationException {
88         locationServer = null;
89         if (myBody == null) {
90             this.myBody = body;
91         }
92
93         // System.out.println("XXXXXXX");
94
UniversalBody remoteBody = super.migrateTo(node, body);
95
96         return remoteBody;
97     }
98
99 // public void startingAfterMigration(Body body) {
100
// //we update our location
101
// // System.out.println("YYYYYYYY");
102
// super.startingAfterMigration(body);
103
// updateLocation(body);
104
// }
105

106     public RequestReceiver createRequestReceiver(UniversalBody remoteBody,
107         RequestReceiver currentRequestReceiver) {
108         return new BouncingRequestReceiver();
109     }
110
111     public ReplyReceiver createReplyReceiver(UniversalBody remoteBody,
112         ReplyReceiver currentReplyReceiver) {
113         return currentReplyReceiver;
114     }
115
116     private void readObject(ObjectInputStream JavaDoc in)
117         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
118         in.defaultReadObject();
119         this.updateLocation(myBody);
120         // this.updateLocation();
121
}
122 }
123
Popular Tags