00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.body;
00032
00033 import java.io.ByteArrayInputStream;
00034 import java.io.ByteArrayOutputStream;
00035 import java.io.IOException;
00036 import java.io.ObjectInputStream;
00037 import java.io.ObjectOutputStream;
00038 import java.io.Serializable;
00039 import java.util.HashMap;
00040 import java.util.Map;
00041
00042 import org.apache.log4j.Logger;
00043 import org.objectweb.proactive.Body;
00044 import org.objectweb.proactive.core.ProActiveException;
00045 import org.objectweb.proactive.core.ProActiveRuntimeException;
00046 import org.objectweb.proactive.core.UniqueID;
00047 import org.objectweb.proactive.core.body.ft.protocols.FTManager;
00048 import org.objectweb.proactive.core.body.ft.protocols.FTManagerFactory;
00049 import org.objectweb.proactive.core.body.ft.protocols.cic.managers.FTManagerCIC;
00050 import org.objectweb.proactive.core.body.ft.protocols.cic.managers.HalfFTManagerCIC;
00051 import org.objectweb.proactive.core.body.ft.protocols.pmlrb.managers.FTManagerPMLRB;
00052 import org.objectweb.proactive.core.body.ft.protocols.pmlrb.managers.HalfFTManagerPMLRB;
00053 import org.objectweb.proactive.core.body.migration.MigrationManager;
00054 import org.objectweb.proactive.core.body.migration.MigrationManagerFactory;
00055 import org.objectweb.proactive.core.body.reply.ReplyReceiver;
00056 import org.objectweb.proactive.core.body.reply.ReplyReceiverFactory;
00057 import org.objectweb.proactive.core.body.request.BlockingRequestQueue;
00058 import org.objectweb.proactive.core.body.request.Request;
00059 import org.objectweb.proactive.core.body.request.RequestFactory;
00060 import org.objectweb.proactive.core.body.request.RequestQueueFactory;
00061 import org.objectweb.proactive.core.body.request.RequestReceiver;
00062 import org.objectweb.proactive.core.body.request.RequestReceiverFactory;
00063 import org.objectweb.proactive.core.component.ComponentParameters;
00064 import org.objectweb.proactive.core.component.identity.ProActiveComponent;
00065 import org.objectweb.proactive.core.component.identity.ProActiveComponentFactory;
00066 import org.objectweb.proactive.core.component.identity.ProActiveComponentImpl;
00067 import org.objectweb.proactive.core.component.request.SynchronousComponentRequestReceiver;
00068 import org.objectweb.proactive.core.group.spmd.ProActiveSPMDGroupManager;
00069 import org.objectweb.proactive.core.group.spmd.ProActiveSPMDGroupManagerFactory;
00070 import org.objectweb.proactive.core.mop.MethodCall;
00071 import org.objectweb.proactive.core.util.ThreadStore;
00072 import org.objectweb.proactive.core.util.ThreadStoreFactory;
00073 import org.objectweb.proactive.core.util.log.Loggers;
00074 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00075 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
00076
00077
00078
00116 public class ProActiveMetaObjectFactory implements MetaObjectFactory,
00117 java.io.Serializable, Cloneable {
00118 public static final String COMPONENT_PARAMETERS_KEY = "component-parameters";
00119 public static final String SYNCHRONOUS_COMPOSITE_COMPONENT_KEY = "synchronous-composite";
00120 protected static Logger logger = ProActiveLogger.getLogger(Loggers.MOP);
00121
00122
00123
00124
00125
00126 private static MetaObjectFactory instance = new ProActiveMetaObjectFactory();
00127 public Map parameters = new HashMap();
00128
00129
00130
00131
00132 protected RequestFactory requestFactoryInstance;
00133 protected ReplyReceiverFactory replyReceiverFactoryInstance;
00134 protected RequestReceiverFactory requestReceiverFactoryInstance;
00135 protected RequestQueueFactory requestQueueFactoryInstance;
00136 protected MigrationManagerFactory migrationManagerFactoryInstance;
00137 protected RemoteBodyFactory remoteBodyFactoryInstance;
00138 protected ThreadStoreFactory threadStoreFactoryInstance;
00139 protected ProActiveSPMDGroupManagerFactory proActiveSPMDGroupManagerFactoryInstance;
00140 protected ProActiveComponentFactory componentFactoryInstance;
00141 protected ProActiveSecurityManager proActiveSecurityManager;
00142 protected FTManagerFactory ftmanagerFactoryInstance;
00143
00144
00145
00146
00147 protected ProActiveMetaObjectFactory() {
00148 requestFactoryInstance = newRequestFactorySingleton();
00149 replyReceiverFactoryInstance = newReplyReceiverFactorySingleton();
00150 requestReceiverFactoryInstance = newRequestReceiverFactorySingleton();
00151 requestQueueFactoryInstance = newRequestQueueFactorySingleton();
00152 migrationManagerFactoryInstance = newMigrationManagerFactorySingleton();
00153 remoteBodyFactoryInstance = newRemoteBodyFactorySingleton();
00154 threadStoreFactoryInstance = newThreadStoreFactorySingleton();
00155 proActiveSPMDGroupManagerFactoryInstance = newProActiveSPMDGroupManagerFactorySingleton();
00156 ftmanagerFactoryInstance = newFTManagerFactorySingleton();
00157 }
00158
00164 public ProActiveMetaObjectFactory(Map parameters) {
00165 this.parameters = parameters;
00166 if (parameters.containsKey(COMPONENT_PARAMETERS_KEY)) {
00167 ComponentParameters initialComponentParameters = (ComponentParameters) parameters.get(COMPONENT_PARAMETERS_KEY);
00168 componentFactoryInstance = newComponentFactorySingleton(initialComponentParameters);
00169 requestFactoryInstance = newRequestFactorySingleton();
00170 replyReceiverFactoryInstance = newReplyReceiverFactorySingleton();
00171 requestReceiverFactoryInstance = newRequestReceiverFactorySingleton();
00172 requestQueueFactoryInstance = newRequestQueueFactorySingleton();
00173 migrationManagerFactoryInstance = newMigrationManagerFactorySingleton();
00174 remoteBodyFactoryInstance = newRemoteBodyFactorySingleton();
00175 threadStoreFactoryInstance = newThreadStoreFactorySingleton();
00176 proActiveSPMDGroupManagerFactoryInstance = newProActiveSPMDGroupManagerFactorySingleton();
00177 ftmanagerFactoryInstance = newFTManagerFactorySingleton();
00178 }
00179 }
00180
00181
00182
00183
00184 public static MetaObjectFactory newInstance() {
00185 return instance;
00186 }
00187
00188 public static void setNewInstance(MetaObjectFactory mo) {
00189 instance = mo;
00190 }
00191
00196 public Map getParameters() {
00197 return parameters;
00198 }
00199
00200
00201
00202
00203 public RequestFactory newRequestFactory() {
00204 return requestFactoryInstance;
00205 }
00206
00207 public ReplyReceiverFactory newReplyReceiverFactory() {
00208 return replyReceiverFactoryInstance;
00209 }
00210
00211 public RequestReceiverFactory newRequestReceiverFactory() {
00212 return requestReceiverFactoryInstance;
00213 }
00214
00215 public RequestQueueFactory newRequestQueueFactory() {
00216 return requestQueueFactoryInstance;
00217 }
00218
00219 public MigrationManagerFactory newMigrationManagerFactory() {
00220 return migrationManagerFactoryInstance;
00221 }
00222
00223 public RemoteBodyFactory newRemoteBodyFactory() {
00224 return remoteBodyFactoryInstance;
00225 }
00226
00227 public ThreadStoreFactory newThreadStoreFactory() {
00228 return threadStoreFactoryInstance;
00229 }
00230
00231 public ProActiveSPMDGroupManagerFactory newProActiveSPMDGroupManagerFactory() {
00232 return proActiveSPMDGroupManagerFactoryInstance;
00233 }
00234
00235 public ProActiveComponentFactory newComponentFactory() {
00236 return componentFactoryInstance;
00237 }
00238
00239 public FTManagerFactory newFTManagerFactory() {
00240 return ftmanagerFactoryInstance;
00241 }
00242
00243
00244
00245
00246 protected RequestFactory newRequestFactorySingleton() {
00247 return new RequestFactoryImpl();
00248 }
00249
00250 protected ReplyReceiverFactory newReplyReceiverFactorySingleton() {
00251 return new ReplyReceiverFactoryImpl();
00252 }
00253
00254 protected RequestReceiverFactory newRequestReceiverFactorySingleton() {
00255 return new RequestReceiverFactoryImpl();
00256 }
00257
00258 protected RequestQueueFactory newRequestQueueFactorySingleton() {
00259 return new RequestQueueFactoryImpl();
00260 }
00261
00262 protected MigrationManagerFactory newMigrationManagerFactorySingleton() {
00263 return new MigrationManagerFactoryImpl();
00264 }
00265
00266 protected RemoteBodyFactory newRemoteBodyFactorySingleton() {
00267 return new RemoteBodyFactoryImpl();
00268 }
00269
00270 protected ThreadStoreFactory newThreadStoreFactorySingleton() {
00271 return new ThreadStoreFactoryImpl();
00272 }
00273
00274 protected ProActiveSPMDGroupManagerFactory newProActiveSPMDGroupManagerFactorySingleton() {
00275 return new ProActiveSPMDGroupManagerFactoryImpl();
00276 }
00277
00278 protected ProActiveComponentFactory newComponentFactorySingleton(
00279 ComponentParameters initialComponentParameters) {
00280 return new ProActiveComponentFactoryImpl(initialComponentParameters);
00281 }
00282
00283 protected FTManagerFactory newFTManagerFactorySingleton() {
00284 return new FTManagerFactoryImpl();
00285 }
00286
00287
00288
00289
00290 protected static class RequestFactoryImpl implements RequestFactory,
00291 java.io.Serializable {
00292 public Request newRequest(MethodCall methodCall,
00293 UniversalBody sourceBody, boolean isOneWay, long sequenceID) {
00294
00295
00296
00297
00298
00299 return new org.objectweb.proactive.core.body.request.RequestImpl(methodCall,
00300 sourceBody, isOneWay, sequenceID);
00301
00302 }
00303 }
00304
00305
00306 protected static class ReplyReceiverFactoryImpl
00307 implements ReplyReceiverFactory, java.io.Serializable {
00308 public ReplyReceiver newReplyReceiver() {
00309 return new org.objectweb.proactive.core.body.reply.ReplyReceiverImpl();
00310 }
00311 }
00312
00313
00314 protected class RequestReceiverFactoryImpl implements RequestReceiverFactory,
00315 java.io.Serializable {
00316 public RequestReceiver newRequestReceiver() {
00317 if (parameters.containsKey(SYNCHRONOUS_COMPOSITE_COMPONENT_KEY) &&
00318 ((Boolean) parameters.get(
00319 ProActiveMetaObjectFactory.SYNCHRONOUS_COMPOSITE_COMPONENT_KEY)).booleanValue()) {
00320 return new SynchronousComponentRequestReceiver();
00321 }
00322 return new org.objectweb.proactive.core.body.request.RequestReceiverImpl();
00323 }
00324 }
00325
00326
00327 protected class RequestQueueFactoryImpl implements RequestQueueFactory,
00328 java.io.Serializable {
00329 public BlockingRequestQueue newRequestQueue(UniqueID ownerID) {
00330 if ("true".equals(parameters.get(
00331 SYNCHRONOUS_COMPOSITE_COMPONENT_KEY))) {
00332 return null;
00333 }
00334
00335
00336
00337
00338
00339
00340 return new org.objectweb.proactive.core.body.request.BlockingRequestQueueImpl(ownerID);
00341
00342 }
00343 }
00344
00345
00346 protected static class MigrationManagerFactoryImpl
00347 implements MigrationManagerFactory, java.io.Serializable {
00348 public MigrationManager newMigrationManager() {
00349
00350
00351
00352
00353 return new org.objectweb.proactive.core.body.migration.MigrationManagerImpl();
00354
00355 }
00356 }
00357
00358
00359 protected static class RemoteBodyFactoryImpl implements RemoteBodyFactory,
00360 java.io.Serializable {
00361 public UniversalBody newRemoteBody(UniversalBody body) {
00362 try {
00363 if ("ibis".equals(System.getProperty(
00364 "proactive.communication.protocol"))) {
00365 if (logger.isDebugEnabled()) {
00366 logger.debug(
00367 "Using ibis factory for creating remote body");
00368 }
00369 return new org.objectweb.proactive.core.body.ibis.IbisBodyAdapter(body);
00370 } else if ("http".equals(System.getProperty(
00371 "proactive.communication.protocol"))) {
00372 if (logger.isDebugEnabled()) {
00373 logger.debug(
00374 "Using http factory for creating remote body");
00375 }
00376
00377 return new org.objectweb.proactive.core.body.http.HttpBodyAdapter(body);
00378 } else if ("rmissh".equals(System.getProperty(
00379 "proactive.communication.protocol"))) {
00380 if (logger.isDebugEnabled()) {
00381 logger.debug(
00382 "Using rmissh factory for creating remote body");
00383 }
00384 return new org.objectweb.proactive.core.body.rmi.SshRmiBodyAdapter(body);
00385 } else {
00386 if (logger.isDebugEnabled()) {
00387 logger.debug(
00388 "Using rmi factory for creating remote body");
00389 }
00390 return new org.objectweb.proactive.core.body.rmi.RmiBodyAdapter(body);
00391 }
00392 } catch (ProActiveException e) {
00393 throw new ProActiveRuntimeException("Cannot create Remote body adapter ",
00394 e);
00395 }
00396 }
00397 }
00398
00399
00400 protected static class ThreadStoreFactoryImpl implements ThreadStoreFactory,
00401 java.io.Serializable {
00402 public ThreadStore newThreadStore() {
00403 return new org.objectweb.proactive.core.util.ThreadStoreImpl();
00404 }
00405 }
00406
00407
00408 protected static class ProActiveSPMDGroupManagerFactoryImpl
00409 implements ProActiveSPMDGroupManagerFactory, java.io.Serializable {
00410 public ProActiveSPMDGroupManager newProActiveSPMDGroupManager() {
00411 return new ProActiveSPMDGroupManager();
00412 }
00413 }
00414
00415
00416 protected class ProActiveComponentFactoryImpl
00417 implements ProActiveComponentFactory, java.io.Serializable {
00418
00419 private ComponentParameters componentParameters;
00420
00421 public ProActiveComponentFactoryImpl(
00422 ComponentParameters initialComponentParameters) {
00423 this.componentParameters = initialComponentParameters;
00424 }
00425
00426 public ProActiveComponent newProActiveComponent(Body myBody) {
00427 return new ProActiveComponentImpl(componentParameters, myBody);
00428 }
00429 }
00430
00431
00432 protected class FTManagerFactoryImpl implements FTManagerFactory,
00433 Serializable {
00434 public FTManager newFTManager(int protocolSelector) {
00435 switch (protocolSelector) {
00436 case FTManagerFactory.PROTO_CIC:
00437 return new FTManagerCIC();
00438 case FTManagerFactory.PROTO_PML:
00439 return new FTManagerPMLRB();
00440 default:
00441 logger.error("Error while creating fault-tolerance manager : " +
00442 "no protocol is associated to selector value " +
00443 protocolSelector);
00444 return null;
00445 }
00446 }
00447
00448 public FTManager newHalfFTManager(int protocolSelector) {
00449 switch (protocolSelector) {
00450 case FTManagerFactory.PROTO_CIC:
00451 return new HalfFTManagerCIC();
00452 case FTManagerFactory.PROTO_PML:
00453 return new HalfFTManagerPMLRB();
00454 default:
00455 logger.error("Error while creating fault-tolerance manager : " +
00456 "no protocol is associated to selector value " +
00457 protocolSelector);
00458 return null;
00459 }
00460 }
00461 }
00462
00463
00464 public void setProActiveSecurityManager(ProActiveSecurityManager psm) {
00465 this.proActiveSecurityManager = psm;
00466 }
00467
00468 public ProActiveSecurityManager getProActiveSecurityManager() {
00469 return proActiveSecurityManager;
00470 }
00471
00472 public Object clone() throws CloneNotSupportedException {
00473 ProActiveMetaObjectFactory clone = null;
00474
00475 try {
00476 ByteArrayOutputStream bout = new ByteArrayOutputStream();
00477 ObjectOutputStream out = new ObjectOutputStream(bout);
00478
00479 out.writeObject(this);
00480 out.flush();
00481 bout.close();
00482
00483 bout.close();
00484
00485 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
00486 bout.toByteArray()));
00487
00488 clone = (ProActiveMetaObjectFactory) ois.readObject();
00489 } catch (IOException e) {
00490 e.printStackTrace();
00491 } catch (ClassNotFoundException e) {
00492 e.printStackTrace();
00493 }
00494
00495 return clone;
00496 }
00497 }