KickJava   Java API By Example, From Geeks To Geeks.

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


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.mixedlocation;
32
33 import org.objectweb.proactive.core.ProActiveException;
34 import org.objectweb.proactive.core.ProActiveRuntimeException;
35 import org.objectweb.proactive.core.body.MetaObjectFactory;
36 import org.objectweb.proactive.core.body.ProActiveMetaObjectFactory;
37 import org.objectweb.proactive.core.body.RemoteBodyFactory;
38 import org.objectweb.proactive.core.body.UniversalBody;
39 import org.objectweb.proactive.core.body.ibis.IbisRemoteBodyAdapter;
40 import org.objectweb.proactive.core.body.migration.MigrationManager;
41 import org.objectweb.proactive.core.body.migration.MigrationManagerFactory;
42 import org.objectweb.proactive.core.body.request.Request;
43 import org.objectweb.proactive.core.body.request.RequestFactory;
44 import org.objectweb.proactive.core.mop.MethodCall;
45 import org.objectweb.proactive.ext.locationserver.LocationServer;
46 import org.objectweb.proactive.ext.locationserver.LocationServerFactory;
47
48
49 /**
50  * <p>
51  * This class overrides the default Factory to provide Request and MigrationManager
52  * with a mixed location server.
53  * </p>
54  *
55  * @author ProActive Team
56  * @version 1.0, 2002/05
57  * @since ProActive 0.9.2
58  */

59 public class MixedLocationMetaObjectFactory extends ProActiveMetaObjectFactory {
60     //
61
// -- PRIVATE MEMBERS -----------------------------------------------
62
//
63
private static MetaObjectFactory instance = null;
64
65     //
66
// -- CONSTRUCTORS -----------------------------------------------
67
//
68

69     /**
70      * Constructor for LocationServerMetaObjectFactory.
71      */

72     protected MixedLocationMetaObjectFactory() {
73         super();
74     }
75
76     //
77
// -- PUBLICS METHODS -----------------------------------------------
78
//
79
public static synchronized MetaObjectFactory newInstance() {
80         if (instance == null) {
81             instance = new MixedLocationMetaObjectFactory();
82         }
83         return instance;
84     }
85
86     //
87
// -- PROTECTED METHODS -----------------------------------------------
88
//
89
protected RequestFactory newRequestFactorySingleton() {
90         return new RequestWithMixedLocationFactory();
91     }
92
93     protected MigrationManagerFactory newMigrationManagerFactorySingleton() {
94         return new MigrationManagerFactoryImpl();
95     }
96
97     //
98
// -- INNER CLASSES -----------------------------------------------
99
//
100
protected class RequestWithMixedLocationFactory implements RequestFactory,
101         java.io.Serializable JavaDoc {
102         transient private LocationServer server = LocationServerFactory.getLocationServer();
103
104         public Request newRequest(MethodCall methodCall,
105             UniversalBody sourceBody, boolean isOneWay, long sequenceID) {
106             return new RequestWithMixedLocation(methodCall, sourceBody,
107                 isOneWay, sequenceID, server);
108         }
109     }
110
111     protected static class MigrationManagerFactoryImpl
112         implements MigrationManagerFactory, java.io.Serializable JavaDoc {
113         public MigrationManager newMigrationManager() {
114             //System.out.println("BodyWithMixedLocation.createMigrationManager");
115
return new MigrationManagerWithMixedLocation(LocationServerFactory.getLocationServer());
116         }
117     }
118
119  
120     protected RemoteBodyFactory newRemoteBodyFactorySingleton() {
121         if ("ibis".equals(System.getProperty("proactive.communication.protocol"))) {
122             if (logger.isDebugEnabled()) {
123                 logger.debug("Factory is ibis");
124             }
125             return new RemoteIbisBodyFactoryImpl();
126         } else {
127             if (logger.isDebugEnabled()) {
128                 logger.debug("Factory is rmi");
129             }
130             return new RemoteRmiBodyFactoryImpl();
131         }
132     }
133
134     protected static class RemoteIbisBodyFactoryImpl
135         implements RemoteBodyFactory, java.io.Serializable JavaDoc {
136         public UniversalBody newRemoteBody(UniversalBody body) {
137             try {
138                 // System.out.println("Creating ibis remote body adapter");
139
return new IbisRemoteBodyAdapter(body);
140             } catch (ProActiveException e) {
141                 throw new ProActiveRuntimeException("Cannot create Ibis Remote body adapter ",
142                     e);
143             }
144         }
145     }
146      // end
147

148     protected static class RemoteRmiBodyFactoryImpl implements RemoteBodyFactory,
149         java.io.Serializable JavaDoc {
150         public UniversalBody newRemoteBody(UniversalBody body) {
151             try {
152                 return new org.objectweb.proactive.core.body.rmi.RemoteBodyAdapter(body);
153             } catch (ProActiveException e) {
154                 throw new ProActiveRuntimeException("Cannot create Remote body adapter ",
155                     e);
156             }
157         }
158     }
159      // end inner class RemoteBodyFactoryImpl
160
}
161
Popular Tags