1 31 package org.objectweb.proactive.core.body; 32 33 34 72 import java.util.Hashtable ; 73 74 import org.apache.log4j.Logger; 75 import org.objectweb.proactive.Body; 76 import org.objectweb.proactive.core.ProActiveException; 77 import org.objectweb.proactive.core.ProActiveRuntimeException; 78 import org.objectweb.proactive.core.UniqueID; 79 import org.objectweb.proactive.core.body.migration.MigrationManager; 80 import org.objectweb.proactive.core.body.migration.MigrationManagerFactory; 81 import org.objectweb.proactive.core.body.reply.ReplyReceiver; 82 import org.objectweb.proactive.core.body.reply.ReplyReceiverFactory; 83 import org.objectweb.proactive.core.body.request.BlockingRequestQueue; 84 import org.objectweb.proactive.core.body.request.Request; 85 import org.objectweb.proactive.core.body.request.RequestFactory; 86 import org.objectweb.proactive.core.body.request.RequestQueueFactory; 87 import org.objectweb.proactive.core.body.request.RequestReceiver; 88 import org.objectweb.proactive.core.body.request.RequestReceiverFactory; 89 import org.objectweb.proactive.core.component.ComponentParameters; 90 import org.objectweb.proactive.core.component.identity.ProActiveComponent; 91 import org.objectweb.proactive.core.component.identity.ProActiveComponentFactory; 92 import org.objectweb.proactive.core.component.identity.ProActiveComponentImpl; 93 import org.objectweb.proactive.core.component.request.ComponentRequestQueueImpl; 94 import org.objectweb.proactive.core.group.ProActiveGroupManager; 95 import org.objectweb.proactive.core.group.ProActiveGroupManagerFactory; 96 import org.objectweb.proactive.core.mop.MethodCall; 97 import org.objectweb.proactive.core.util.ThreadStore; 98 import org.objectweb.proactive.core.util.ThreadStoreFactory; 99 import org.objectweb.proactive.ext.security.ProActiveSecurityManager; 100 101 102 public class ProActiveMetaObjectFactory implements MetaObjectFactory, 103 java.io.Serializable { 104 public static final String COMPONENT_PARAMETERS_KEY = "component-parameters"; 105 protected static Logger logger = Logger.getLogger(ProActiveMetaObjectFactory.class.getName()); 106 107 private static MetaObjectFactory instance = new ProActiveMetaObjectFactory(); 112 public Hashtable parameters; 113 114 protected RequestFactory requestFactoryInstance; 118 protected ReplyReceiverFactory replyReceiverFactoryInstance; 119 protected RequestReceiverFactory requestReceiverFactoryInstance; 120 protected RequestQueueFactory requestQueueFactoryInstance; 121 protected MigrationManagerFactory migrationManagerFactoryInstance; 122 protected RemoteBodyFactory remoteBodyFactoryInstance; 123 protected ThreadStoreFactory threadStoreFactoryInstance; 124 protected ProActiveGroupManagerFactory proActiveGroupManagerFactoryInstance; 125 protected ProActiveComponentFactory componentFactoryInstance; 126 protected ProActiveSecurityManager proActiveSecurityManager; 127 128 protected ProActiveMetaObjectFactory() { 132 requestFactoryInstance = newRequestFactorySingleton(); 133 replyReceiverFactoryInstance = newReplyReceiverFactorySingleton(); 134 requestReceiverFactoryInstance = newRequestReceiverFactorySingleton(); 135 requestQueueFactoryInstance = newRequestQueueFactorySingleton(); 136 migrationManagerFactoryInstance = newMigrationManagerFactorySingleton(); 137 remoteBodyFactoryInstance = newRemoteBodyFactorySingleton(); 138 threadStoreFactoryInstance = newThreadStoreFactorySingleton(); 139 proActiveGroupManagerFactoryInstance = newProActiveGroupManagerFactorySingleton(); 140 } 141 142 147 public ProActiveMetaObjectFactory(Hashtable parameters) { 148 this.parameters = parameters; 149 if (parameters.containsKey(COMPONENT_PARAMETERS_KEY)) { 150 ComponentParameters initialComponentParameters = (ComponentParameters) parameters.get(COMPONENT_PARAMETERS_KEY); 151 componentFactoryInstance = newComponentFactorySingleton(initialComponentParameters); 152 requestFactoryInstance = newRequestFactorySingleton(); 153 replyReceiverFactoryInstance = newReplyReceiverFactorySingleton(); 154 requestReceiverFactoryInstance = newRequestReceiverFactorySingleton(); 155 requestQueueFactoryInstance = newRequestQueueFactorySingleton(); 156 migrationManagerFactoryInstance = newMigrationManagerFactorySingleton(); 157 remoteBodyFactoryInstance = newRemoteBodyFactorySingleton(); 158 threadStoreFactoryInstance = newThreadStoreFactorySingleton(); 159 proActiveGroupManagerFactoryInstance = newProActiveGroupManagerFactorySingleton(); 160 } 161 } 162 163 public static MetaObjectFactory newInstance() { 167 return instance; 168 } 169 170 public static void setNewInstance(MetaObjectFactory mo) { 171 instance = mo; 172 } 173 174 178 public Hashtable getParameters() { 179 return parameters; 180 } 181 182 public RequestFactory newRequestFactory() { 186 return requestFactoryInstance; 187 } 188 189 public ReplyReceiverFactory newReplyReceiverFactory() { 190 return replyReceiverFactoryInstance; 191 } 192 193 public RequestReceiverFactory newRequestReceiverFactory() { 194 return requestReceiverFactoryInstance; 195 } 196 197 public RequestQueueFactory newRequestQueueFactory() { 198 return requestQueueFactoryInstance; 199 } 200 201 public MigrationManagerFactory newMigrationManagerFactory() { 202 return migrationManagerFactoryInstance; 203 } 204 205 public RemoteBodyFactory newRemoteBodyFactory() { 206 return remoteBodyFactoryInstance; 207 } 208 209 public ThreadStoreFactory newThreadStoreFactory() { 210 return threadStoreFactoryInstance; 211 } 212 213 public ProActiveGroupManagerFactory newProActiveGroupManagerFactory() { 214 return proActiveGroupManagerFactoryInstance; 215 } 216 217 public ProActiveComponentFactory newComponentFactory() { 218 return componentFactoryInstance; 219 } 220 221 protected RequestFactory newRequestFactorySingleton() { 225 return new RequestFactoryImpl(); 226 } 227 228 protected ReplyReceiverFactory newReplyReceiverFactorySingleton() { 229 return new ReplyReceiverFactoryImpl(); 230 } 231 232 protected RequestReceiverFactory newRequestReceiverFactorySingleton() { 233 return new RequestReceiverFactoryImpl(); 234 } 235 236 protected RequestQueueFactory newRequestQueueFactorySingleton() { 237 return new RequestQueueFactoryImpl(); 238 } 239 240 protected MigrationManagerFactory newMigrationManagerFactorySingleton() { 241 return new MigrationManagerFactoryImpl(); 242 } 243 244 protected RemoteBodyFactory newRemoteBodyFactorySingleton() { 245 return new RemoteBodyFactoryImpl(); 246 } 247 248 protected ThreadStoreFactory newThreadStoreFactorySingleton() { 249 return new ThreadStoreFactoryImpl(); 250 } 251 252 protected ProActiveGroupManagerFactory newProActiveGroupManagerFactorySingleton() { 253 return new ProActiveGroupManagerFactoryImpl(); 254 } 255 256 protected ProActiveComponentFactory newComponentFactorySingleton( 257 ComponentParameters initialComponentParameters) { 258 return new ProActiveComponentFactoryImpl(initialComponentParameters); 259 } 260 261 protected static class RequestFactoryImpl implements RequestFactory, 265 java.io.Serializable { 266 public Request newRequest(MethodCall methodCall, 267 UniversalBody sourceBody, boolean isOneWay, long sequenceID) { 268 return new org.objectweb.proactive.core.body.request.RequestImpl(methodCall, 274 sourceBody, isOneWay, sequenceID); 275 } 277 } 278 280 protected static class ReplyReceiverFactoryImpl 281 implements ReplyReceiverFactory, java.io.Serializable { 282 public ReplyReceiver newReplyReceiver() { 283 return new org.objectweb.proactive.core.body.reply.ReplyReceiverImpl(); 284 } 285 } 286 288 protected static class RequestReceiverFactoryImpl 289 implements RequestReceiverFactory, java.io.Serializable { 290 public RequestReceiver newRequestReceiver() { 291 return new org.objectweb.proactive.core.body.request.RequestReceiverImpl(); 292 } 293 } 294 296 protected class RequestQueueFactoryImpl implements RequestQueueFactory, 297 java.io.Serializable { 298 public BlockingRequestQueue newRequestQueue(UniqueID ownerID) { 299 if (componentFactoryInstance != null) { 300 return new ComponentRequestQueueImpl(ownerID); 303 } else { 304 return new org.objectweb.proactive.core.body.request.BlockingRequestQueueImpl(ownerID); 305 } 306 } 307 } 308 310 protected static class MigrationManagerFactoryImpl 311 implements MigrationManagerFactory, java.io.Serializable { 312 public MigrationManager newMigrationManager() { 313 return new org.objectweb.proactive.core.body.migration.MigrationManagerImpl(); 318 } 320 } 321 323 protected static class RemoteBodyFactoryImpl implements RemoteBodyFactory, 324 java.io.Serializable { 325 public UniversalBody newRemoteBody(UniversalBody body) { 326 try { 327 if ("ibis".equals(System.getProperty("proactive.communication.protocol"))) { 328 if (logger.isDebugEnabled()) { 329 logger.debug("Factory is ibis"); 330 } 331 return new org.objectweb.proactive.core.body.ibis.IbisRemoteBodyAdapter(body); 332 } else { 333 if (logger.isDebugEnabled()) { 334 logger.debug("Factory is rmi"); 335 } 336 return new org.objectweb.proactive.core.body.rmi.RemoteBodyAdapter(body); 337 } 338 } catch (ProActiveException e) { 339 throw new ProActiveRuntimeException("Cannot create Remote body adapter ", 340 e); 341 } 342 } 343 } 344 346 protected static class ThreadStoreFactoryImpl implements ThreadStoreFactory, 347 java.io.Serializable { 348 public ThreadStore newThreadStore() { 349 return new org.objectweb.proactive.core.util.ThreadStoreImpl(); 350 } 351 } 352 354 protected static class ProActiveGroupManagerFactoryImpl implements ProActiveGroupManagerFactory, 355 java.io.Serializable { 356 public ProActiveGroupManager newProActiveGroupManager() { 357 return new ProActiveGroupManager(); 358 } 359 } 360 362 protected class ProActiveComponentFactoryImpl 363 implements ProActiveComponentFactory, java.io.Serializable { 364 private ComponentParameters componentParameters; 366 367 public ProActiveComponentFactoryImpl( 368 ComponentParameters initialComponentParameters) { 369 this.componentParameters = initialComponentParameters; 370 } 371 372 public ProActiveComponent newProActiveComponent(Body myBody) { 373 return new ProActiveComponentImpl(componentParameters, myBody); 374 } 375 } 376 377 public void setProActiveSecurityManager(ProActiveSecurityManager psm) { 379 this.proActiveSecurityManager = psm; 380 } 381 382 public ProActiveSecurityManager getProActiveSecurityManager() { 383 return proActiveSecurityManager; 384 } 385 386 } 387 | Popular Tags |