KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ext > mixedlocation > MigrationManagerWithMixedLocation


1 package org.objectweb.proactive.ext.mixedlocation;
2
3 import org.apache.log4j.Logger;
4
5 import org.objectweb.proactive.Body;
6 import org.objectweb.proactive.core.body.UniversalBody;
7 import org.objectweb.proactive.core.body.migration.MigrationManagerImpl;
8 import org.objectweb.proactive.core.body.reply.ReplyReceiver;
9 import org.objectweb.proactive.core.body.reply.ReplyReceiverForwarder;
10 import org.objectweb.proactive.core.body.request.RequestReceiver;
11 import org.objectweb.proactive.core.body.request.RequestReceiverForwarder;
12 import org.objectweb.proactive.ext.locationserver.LocationServer;
13 import org.objectweb.proactive.ext.locationserver.LocationServerFactory;
14
15 import java.io.IOException JavaDoc;
16 import java.io.ObjectInputStream JavaDoc;
17 import java.io.ObjectOutputStream JavaDoc;
18
19
20 public class MigrationManagerWithMixedLocation extends MigrationManagerImpl
21     implements java.io.Serializable JavaDoc {
22     static Logger logger = Logger.getLogger(MigrationManagerWithMixedLocation.class.getName());
23     protected UniversalBodyWrapper wrapper;
24     transient protected LocationServer locationServer;
25     protected int migrationCounter;
26
27     public MigrationManagerWithMixedLocation() {
28         logger.info("<init> LocationServer is " + locationServer);
29     }
30
31     public MigrationManagerWithMixedLocation(LocationServer locationServer) {
32         this.migrationCounter = 0;
33         if (logger.isDebugEnabled()) {
34             logger.debug("LocationServer is " + locationServer);
35         }
36         this.locationServer = locationServer;
37     }
38
39     protected synchronized void createWrapper(UniversalBody remoteBody) {
40         if (this.wrapper == null) {
41             this.wrapper = new UniversalBodyWrapper(remoteBody, 6000);
42         }
43     }
44
45     public RequestReceiver createRequestReceiver(UniversalBody remoteBody,
46         RequestReceiver currentRequestReceiver) {
47         this.createWrapper(remoteBody);
48         return new RequestReceiverForwarder(wrapper);
49     }
50
51     public ReplyReceiver createReplyReceiver(UniversalBody remoteBody,
52         ReplyReceiver currentReplyReceiver) {
53         this.createWrapper(wrapper);
54         return new ReplyReceiverForwarder(wrapper);
55     }
56
57     public void updateLocation(Body body) {
58         if (locationServer == null) {
59             this.locationServer = LocationServerFactory.getLocationServer();
60         }
61         if (locationServer != null) {
62             locationServer.updateLocation(body.getID(), body.getRemoteAdapter());
63         }
64     }
65
66     public void startingAfterMigration(Body body) {
67         super.startingAfterMigration(body);
68         //we update our location
69
this.migrationCounter++;
70         if (logger.isDebugEnabled()) {
71             logger.debug("XXX counter == " + this.migrationCounter);
72         }
73
74         // if (this.migrationCounter > 3) {
75
updateLocation(body);
76     }
77
78     private void readObject(ObjectInputStream JavaDoc in)
79         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
80         if (logger.isDebugEnabled()) {
81             logger.debug("MigrationManagerWithMixedLocation readObject XXXXXXX");
82         }
83         in.defaultReadObject();
84     }
85
86     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
87         if (logger.isDebugEnabled()) {
88             logger.debug("MigrationManagerWithMixedLocation writeObject YYYYYY");
89         }
90         this.locationServer = null;
91         out.defaultWriteObject();
92     }
93 }
94
Popular Tags