org/objectweb/proactive/ext/mixedlocation/MixedLocationMetaObjectFactory.java

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 org.objectweb.proactive.core.ProActiveException;
00034 import org.objectweb.proactive.core.ProActiveRuntimeException;
00035 import org.objectweb.proactive.core.body.MetaObjectFactory;
00036 import org.objectweb.proactive.core.body.ProActiveMetaObjectFactory;
00037 import org.objectweb.proactive.core.body.RemoteBodyFactory;
00038 import org.objectweb.proactive.core.body.UniversalBody;
00039 import org.objectweb.proactive.core.body.ibis.IbisBodyAdapter;
00040 import org.objectweb.proactive.core.body.migration.MigrationManager;
00041 import org.objectweb.proactive.core.body.migration.MigrationManagerFactory;
00042 import org.objectweb.proactive.core.body.request.Request;
00043 import org.objectweb.proactive.core.body.request.RequestFactory;
00044 import org.objectweb.proactive.core.mop.MethodCall;
00045 import org.objectweb.proactive.ext.locationserver.LocationServer;
00046 import org.objectweb.proactive.ext.locationserver.LocationServerFactory;
00047 
00048 
00059 public class MixedLocationMetaObjectFactory extends ProActiveMetaObjectFactory {
00060     //
00061     // -- PRIVATE MEMBERS -----------------------------------------------
00062     //
00063     private static MetaObjectFactory instance = null;
00064 
00065     //
00066     // -- CONSTRUCTORS -----------------------------------------------
00067     //
00068 
00072     protected MixedLocationMetaObjectFactory() {
00073         super();
00074     }
00075 
00076     //
00077     // -- PUBLICS METHODS -----------------------------------------------
00078     //
00079     public static synchronized MetaObjectFactory newInstance() {
00080         if (instance == null) {
00081             instance = new MixedLocationMetaObjectFactory();
00082         }
00083         return instance;
00084     }
00085 
00086     //
00087     // -- PROTECTED METHODS -----------------------------------------------
00088     //
00089     protected RequestFactory newRequestFactorySingleton() {
00090         return new RequestWithMixedLocationFactory();
00091     }
00092 
00093     protected MigrationManagerFactory newMigrationManagerFactorySingleton() {
00094         return new MigrationManagerFactoryImpl();
00095     }
00096 
00097     //
00098     // -- INNER CLASSES -----------------------------------------------
00099     //
00100     protected class RequestWithMixedLocationFactory implements RequestFactory,
00101         java.io.Serializable {
00102         transient private LocationServer server = LocationServerFactory.getLocationServer();
00103 
00104         public Request newRequest(MethodCall methodCall,
00105             UniversalBody sourceBody, boolean isOneWay, long sequenceID) {
00106             return new RequestWithMixedLocation(methodCall, sourceBody,
00107                 isOneWay, sequenceID, server);
00108         }
00109     }
00110 
00111     protected static class MigrationManagerFactoryImpl
00112         implements MigrationManagerFactory, java.io.Serializable {
00113         public MigrationManager newMigrationManager() {
00114             //System.out.println("BodyWithMixedLocation.createMigrationManager");
00115             return new MigrationManagerWithMixedLocation(LocationServerFactory.getLocationServer());
00116         }
00117     }
00118 
00119     protected RemoteBodyFactory newRemoteBodyFactorySingleton() {
00120         if ("ibis".equals(System.getProperty("proactive.communication.protocol"))) {
00121             if (logger.isDebugEnabled()) {
00122                 logger.debug("Factory is ibis");
00123             }
00124             return new RemoteIbisBodyFactoryImpl();
00125         } else {
00126             if (logger.isDebugEnabled()) {
00127                 logger.debug("Factory is rmi");
00128             }
00129             return new RemoteRmiBodyFactoryImpl();
00130         }
00131     }
00132 
00133     protected static class RemoteIbisBodyFactoryImpl
00134         implements RemoteBodyFactory, java.io.Serializable {
00135         public UniversalBody newRemoteBody(UniversalBody body) {
00136             try {
00137                 //      System.out.println("Creating ibis remote body adapter");
00138                 return new IbisBodyAdapter(body);
00139             } catch (ProActiveException e) {
00140                 throw new ProActiveRuntimeException("Cannot create Ibis Remote body adapter ",
00141                     e);
00142             }
00143         }
00144     }
00145 
00146     // end
00147     protected static class RemoteRmiBodyFactoryImpl implements RemoteBodyFactory,
00148         java.io.Serializable {
00149         public UniversalBody newRemoteBody(UniversalBody body) {
00150             try {
00151                 return new org.objectweb.proactive.core.body.rmi.RmiBodyAdapter(body);
00152             } catch (ProActiveException e) {
00153                 throw new ProActiveRuntimeException("Cannot create Remote body adapter ",
00154                     e);
00155             }
00156         }
00157     }
00158 
00159     // end inner class RemoteBodyFactoryImpl
00160 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1