KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ProActive


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;
32
33 import org.apache.log4j.Logger;
34
35 import org.objectweb.fractal.api.Component;
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.fractal.api.factory.GenericFactory;
38 import org.objectweb.fractal.api.factory.InstantiationException;
39 import org.objectweb.fractal.util.Fractal;
40
41 import org.objectweb.proactive.core.Constants;
42 import org.objectweb.proactive.core.ProActiveException;
43 import org.objectweb.proactive.core.ProActiveRuntimeException;
44 import org.objectweb.proactive.core.body.LocalBodyStore;
45 import org.objectweb.proactive.core.body.MetaObjectFactory;
46 import org.objectweb.proactive.core.body.ProActiveMetaObjectFactory;
47 import org.objectweb.proactive.core.body.UniversalBody;
48 import org.objectweb.proactive.core.body.future.Future;
49 import org.objectweb.proactive.core.body.future.FuturePool;
50 import org.objectweb.proactive.core.body.ibis.IbisRemoteBodyAdapter;
51 import org.objectweb.proactive.core.body.migration.Migratable;
52 import org.objectweb.proactive.core.body.migration.MigrationException;
53 import org.objectweb.proactive.core.body.proxy.BodyProxy;
54 import org.objectweb.proactive.core.body.request.BodyRequest;
55 import org.objectweb.proactive.core.body.rmi.RemoteBodyAdapter;
56 import org.objectweb.proactive.core.component.ComponentParameters;
57 import org.objectweb.proactive.core.component.ContentDescription;
58 import org.objectweb.proactive.core.component.ControllerDescription;
59 import org.objectweb.proactive.core.config.ProActiveConfiguration;
60 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
61 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
62 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
63 import org.objectweb.proactive.core.descriptor.xml.ProActiveDescriptorHandler;
64 import org.objectweb.proactive.core.exceptions.NonFunctionalException;
65 import org.objectweb.proactive.core.exceptions.communication.ProActiveCommunicationException;
66 import org.objectweb.proactive.core.exceptions.creation.ProActiveCreationException;
67 import org.objectweb.proactive.core.exceptions.group.ProActiveGroupException;
68 import org.objectweb.proactive.core.exceptions.handler.HandlerCommunicationException;
69 import org.objectweb.proactive.core.exceptions.handler.HandlerCreationException;
70 import org.objectweb.proactive.core.exceptions.handler.HandlerGroupException;
71 import org.objectweb.proactive.core.exceptions.handler.HandlerMigrationException;
72 import org.objectweb.proactive.core.exceptions.handler.HandlerNonFunctionalException;
73 import org.objectweb.proactive.core.exceptions.handler.HandlerSecurityException;
74 import org.objectweb.proactive.core.exceptions.handler.HandlerServiceException;
75 import org.objectweb.proactive.core.exceptions.handler.IHandler;
76 import org.objectweb.proactive.core.exceptions.migration.ProActiveMigrationException;
77 import org.objectweb.proactive.core.exceptions.security.ProActiveSecurityException;
78 import org.objectweb.proactive.core.exceptions.service.ProActiveServiceException;
79 import org.objectweb.proactive.core.group.Group;
80 import org.objectweb.proactive.core.group.ProActiveGroup;
81 import org.objectweb.proactive.core.mop.ClassNotReifiableException;
82 import org.objectweb.proactive.core.mop.ConstructionOfProxyObjectFailedException;
83 import org.objectweb.proactive.core.mop.MOP;
84 import org.objectweb.proactive.core.mop.MOPException;
85 import org.objectweb.proactive.core.mop.StubObject;
86 import org.objectweb.proactive.core.node.Node;
87 import org.objectweb.proactive.core.node.NodeException;
88 import org.objectweb.proactive.core.node.NodeFactory;
89 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
90 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
91 import org.objectweb.proactive.core.runtime.RuntimeFactory;
92 import org.objectweb.proactive.core.util.UrlBuilder;
93
94 import java.net.UnknownHostException JavaDoc;
95
96 import java.util.HashMap JavaDoc;
97
98
99 public class ProActive {
100     protected static Logger logger = Logger.getLogger(ProActive.class.getName());
101
102     //
103
// -- STATIC MEMBERS -----------------------------------------------
104
//
105

106     /**
107      * This level is used for default handlers
108      */

109     static public HashMap JavaDoc defaultLevel = null;
110
111     /**
112      * VM level provides different strategies according to the virtual machine
113      */

114     static public HashMap JavaDoc VMLevel = null;
115
116     /**
117      * Code level is used for temporary handlers
118      */

119     static public HashMap JavaDoc codeLevel = null;
120
121     static {
122         ProActiveConfiguration.load();
123         Class JavaDoc c = org.objectweb.proactive.core.runtime.RuntimeFactory.class;
124
125         // Creation of lower levels of exception handling
126
defaultLevel = new HashMap JavaDoc();
127         VMLevel = new HashMap JavaDoc();
128         codeLevel = new HashMap JavaDoc();
129
130         // We create default handler and add them to default level
131
if (logger.isDebugEnabled()) {
132             logger.debug("Initialization of default level handlers");
133         }
134         setExceptionHandler(IHandler.ID_defaultLevel, null,
135             HandlerNonFunctionalException.class, NonFunctionalException.class);
136         setExceptionHandler(IHandler.ID_defaultLevel, null,
137             HandlerCommunicationException.class,
138             ProActiveCommunicationException.class);
139         setExceptionHandler(IHandler.ID_defaultLevel, null,
140             HandlerCreationException.class, ProActiveCreationException.class);
141         setExceptionHandler(IHandler.ID_defaultLevel, null,
142             HandlerGroupException.class, ProActiveGroupException.class);
143         setExceptionHandler(IHandler.ID_defaultLevel, null,
144             HandlerMigrationException.class, ProActiveMigrationException.class);
145         setExceptionHandler(IHandler.ID_defaultLevel, null,
146             HandlerSecurityException.class, ProActiveSecurityException.class);
147         setExceptionHandler(IHandler.ID_defaultLevel, null,
148             HandlerServiceException.class, ProActiveServiceException.class);
149
150         //ProActiveConfiguration.load();
151
}
152
153     //
154
// -- CONSTRUCTORS -----------------------------------------------
155
//
156
private ProActive() {
157     }
158
159     //
160
// -- PUBLIC METHODS -----------------------------------------------
161
//
162

163     /**
164      * Creates a new ActiveObject based on classname attached to a default node in the local JVM.
165      * @param classname the name of the class to instanciate as active
166      * @param constructorParameters the parameters of the constructor.
167      * @return a reference (possibly remote) on a Stub of the newly created active object
168      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
169      * @exception NodeException if the DefaultNode cannot be created
170      */

171     public static Object JavaDoc newActive(String JavaDoc classname,
172         Object JavaDoc[] constructorParameters)
173         throws ActiveObjectCreationException, NodeException {
174         // avoid ambiguity for method parameters types
175
Node nullNode = null;
176         return newActive(classname, constructorParameters, nullNode, null, null);
177     }
178
179     /**
180      * Creates a new ActiveObject based on classname attached to the node of the given URL.
181      * @param classname the name of the class to instanciate as active
182      * @param constructorParameters the parameters of the constructor.
183      * @param nodeURL the URL of the node where to create the active object. If null, the active object
184      * is created localy on a default node
185      * @return a reference (possibly remote) on a Stub of the newly created active object
186      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
187      * @exception NodeException if the node URL cannot be resolved as an existing Node
188      */

189     public static Object JavaDoc newActive(String JavaDoc classname,
190         Object JavaDoc[] constructorParameters, String JavaDoc nodeURL)
191         throws ActiveObjectCreationException, NodeException {
192         if (nodeURL == null) {
193             // avoid ambiguity for method parameters types
194
Node nullNode = null;
195             return newActive(classname, constructorParameters, nullNode, null,
196                 null);
197         } else {
198             return newActive(classname, constructorParameters,
199                 NodeFactory.getNode(nodeURL), null, null);
200         }
201     }
202
203     /**
204      * Creates a new ActiveObject based on classname attached to the given node or on
205      * a default node in the local JVM if the given node is null.
206      * @param classname the name of the class to instanciate as active
207      * @param constructorParameters the parameters of the constructor.
208      * @param node the possibly null node where to create the active object.
209      * @return a reference (possibly remote) on a Stub of the newly created active object
210      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
211      * @exception NodeException if the node was null and that the DefaultNode cannot be created
212      */

213     public static Object JavaDoc newActive(String JavaDoc classname,
214         Object JavaDoc[] constructorParameters, Node node)
215         throws ActiveObjectCreationException, NodeException {
216         return newActive(classname, constructorParameters, node, null, null);
217     }
218
219     /**
220      * Creates a new ActiveObject based on classname attached to the given node or on
221      * a default node in the local JVM if the given node is null.
222      * The object returned is a stub class that extends the target class and that is automatically
223      * generated on the fly. The Stub class reference a the proxy object that reference the body
224      * of the active object. The body referenced by the proxy can either be local of remote,
225      * depending or the respective location of the object calling the newActive and the active object
226      * itself.
227      * @param classname the name of the class to instanciate as active
228      * @param constructorParameters the parameters of the constructor of the object
229      * to instantiate as active. If some parameters are primitive types, the wrapper
230      * class types should be given here. null can be used to specify that no parameter
231      * are passed to the constructor.
232      * @param node the possibly null node where to create the active object. If null, the active object
233      * is created localy on a default node
234      * @param activity the possibly null activity object defining the different step in the activity of the object.
235      * see the definition of the activity in the javadoc of this classe for more information.
236      * @param factory the possibly null meta factory giving all factories for creating the meta-objects part of the
237      * body associated to the reified object. If null the default ProActive MataObject factory is used.
238      * @return a reference (possibly remote) on a Stub of the newly created active object
239      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
240      * @exception NodeException if the node was null and that the DefaultNode cannot be created
241      */

242     public static Object JavaDoc newActive(String JavaDoc classname,
243         Object JavaDoc[] constructorParameters, Node node, Active activity,
244         MetaObjectFactory factory)
245         throws ActiveObjectCreationException, NodeException {
246         //using default proactive node
247
if (node == null) {
248             node = NodeFactory.getDefaultNode();
249         }
250
251         if (factory == null) {
252             factory = ProActiveMetaObjectFactory.newInstance();
253         }
254
255         try {
256             return createStubObject(classname, constructorParameters, node,
257                 activity, factory);
258         } catch (MOPException e) {
259             Throwable JavaDoc t = e;
260
261             if (e.getTargetException() != null) {
262                 t = e.getTargetException();
263             }
264
265             throw new ActiveObjectCreationException(t);
266         }
267     }
268
269     /**
270             * Creates a new set of active objects based on classname attached to the given virtualnode.
271             * @param classname classname the name of the class to instanciate as active
272             * @param constructorParameters constructorParameters the parameters of the constructor.
273             * @param virtualnode The virtualnode where to create active objects. Active objects will be created
274             * on each node mapped to the given virtualnode in XML deployment descriptor.
275             * @return Object a Group of references (possibly remote) on Stub of newly created active objects
276             * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
277             * @throws NodeException if the virtualnode was null
278             */

279     public static Object JavaDoc newActive(String JavaDoc classname,
280         Object JavaDoc[] constructorParameters, VirtualNode virtualnode)
281         throws ActiveObjectCreationException, NodeException {
282         return ProActive.newActive(classname, constructorParameters,
283             virtualnode, null, null);
284     }
285
286     /**
287      * Creates a new ActiveObject based on classname attached to the given virtualnode.
288      * @param classname classname the name of the class to instanciate as active
289      * @param constructorParameters constructorParameters the parameters of the constructor.
290      * @param virtualnode The virtualnode where to create active objects. Active objects will be created
291      * on each node mapped to the given virtualnode in XML deployment descriptor.
292      * @param activity the possibly null activity object defining the different step in the activity of the object.
293      * see the definition of the activity in the javadoc of this classe for more information.
294      * @param factory the possibly null meta factory giving all factories for creating the meta-objects part of the
295      * body associated to the reified object. If null the default ProActive MataObject factory is used.
296      * @return Object a Group of references (possibly remote) on Stub of newly created active objects
297      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
298      * @throws NodeException if the virtualnode was null
299      *
300      */

301     public static Object JavaDoc newActive(String JavaDoc classname,
302
303         Object JavaDoc[] constructorParameters, VirtualNode virtualnode,
304         Active activity, MetaObjectFactory factory)
305         throws ActiveObjectCreationException, NodeException {
306         if (virtualnode != null) {
307             if (!virtualnode.isActivated()) {
308                 virtualnode.activate();
309             }
310             Node[] nodeTab = virtualnode.getNodes();
311             Group aoGroup = null;
312             try {
313                 aoGroup = ProActiveGroup.getGroup(ProActiveGroup.newGroup(
314                             classname));
315             } catch (ClassNotFoundException JavaDoc e) {
316                 throw new ActiveObjectCreationException(
317                     "Cannot create group of active objects" + e);
318             } catch (ClassNotReifiableException e) {
319                 throw new ActiveObjectCreationException(
320                     "Cannot create group of active objects" + e);
321             }
322             for (int i = 0; i < nodeTab.length; i++) {
323                 Object JavaDoc tmp = newActive(classname, constructorParameters,
324                         (Node) nodeTab[i], activity, factory);
325                 aoGroup.add(tmp);
326             }
327
328             return aoGroup.getGroupByType();
329         } else {
330             throw new NodeException(
331                 "VirtualNode is null, unable to activate the object");
332         }
333     }
334
335     /**
336       * Creates a new ProActive component over the specified base class, according to the
337       * given component parameters, and returns a reference on the component of type Component.
338       * A reference on the active object base class can be retreived through the component parameters controller's
339       * method "getStubOnReifiedObject".
340       *
341       * @param classname the name of the base class. "Composite" if the component is a composite,
342       * "ParallelComposite" if the component is a parallel composite component
343       * @param constructorParameters the parameters of the constructor of the object
344       * to instantiate as active. If some parameters are primitive types, the wrapper
345       * class types should be given here. null can be used to specify that no parameter
346       * are passed to the constructor.
347       * @param node the possibly null node where to create the active object. If null, the active object
348       * is created localy on a default node
349       * @param activity the possibly null activity object defining the different step in the activity of the object.
350       * see the definition of the activity in the javadoc of this classe for more information.
351       * @param factory should be null for components (automatically created)
352       * @param componentParameters the parameters of the component
353       * @return a component representative of type Component
354       * @exception ActiveObjectCreationException if a problem occurs while creating the stub or the body
355       * @exception NodeException if the node was null and that the DefaultNode cannot be created
356       */

357     public static Component newActiveComponent(String JavaDoc classname,
358         Object JavaDoc[] constructorParameters, Node node, Active activity,
359         MetaObjectFactory factory, ComponentParameters componentParameters)
360         throws ActiveObjectCreationException, NodeException {
361         // COMPONENTS
362
try {
363             Component boot = Fractal.getBootstrapComponent();
364             GenericFactory cf = Fractal.getGenericFactory(boot);
365             return cf.newFcInstance(componentParameters.getComponentType(),
366                 new ControllerDescription(componentParameters.getName(),
367                     componentParameters.getHierarchicalType()),
368                 new ContentDescription(classname, constructorParameters, node,
369                     activity, factory));
370         } catch (NoSuchInterfaceException e) {
371             throw new ActiveObjectCreationException(e);
372         } catch (InstantiationException JavaDoc e) {
373             if (e.getCause() instanceof NodeException) {
374                 throw new NodeException(e);
375             } else {
376                 throw new ActiveObjectCreationException(e);
377             }
378         }
379     }
380
381     /**
382      * Creates a new ProActive component over the specified base class, according to the
383      * given component parameters, and returns a reference on the component of type Component.
384      *
385      * This method allows automatic of primitive components on Virtual Nodes. In that case, the appendix
386      * -cyclicInstanceNumber-<b><i>number</i></b> is added to the name of each of these components.
387      * If the component is not a primitive, only one instance of the component is created, on the first node
388      * retreived from the specified virtual node.
389      *
390      * A reference on the active object base class can be retreived through the component parameters controller's
391      * method "getStubOnReifiedObject".
392      *
393      * @param classname the name of the base class. "Composite" if the component is a composite,
394      * "ParallelComposite" if the component is a parallel composite component
395      * @param constructorParameters the parameters of the constructor of the object
396      * to instantiate as active. If some parameters are primitive types, the wrapper
397      * class types should be given here. null can be used to specify that no parameter
398      * are passed to the constructor.
399      * @param node the possibly null node where to create the active object. If null, the active object
400      * is created localy on a default node
401      * @param activity the possibly null activity object defining the different step in the activity of the object.
402      * see the definition of the activity in the javadoc of this class for more information.
403      * @param factory should be null for components (automatically created)
404      * @param componentParameters the parameters of the component
405      * @return a typed group of component representative elements, of type Component
406      * @exception ActiveObjectCreationException if a problem occurs while creating the stub or the body
407      * @exception NodeException if the node was null and that the DefaultNode cannot be created
408      */

409     public static Component newActiveComponent(String JavaDoc className,
410         Object JavaDoc[] constructorParameters, VirtualNode vn,
411         ComponentParameters componentParameters)
412         throws ActiveObjectCreationException, NodeException {
413             // COMPONENTS
414
try {
415                 Component boot = Fractal.getBootstrapComponent();
416                 GenericFactory cf = Fractal.getGenericFactory(boot);
417                 return cf.newFcInstance(componentParameters.getComponentType(),
418                     new ControllerDescription(componentParameters.getName(),
419                         componentParameters.getHierarchicalType()),
420                     new ContentDescription(className, constructorParameters, vn));
421             } catch (NoSuchInterfaceException e) {
422                 throw new ActiveObjectCreationException(e);
423             } catch (InstantiationException JavaDoc e) {
424                 if (e.getCause() instanceof NodeException) {
425                     throw new NodeException(e);
426                 } else {
427                     throw new ActiveObjectCreationException(e);
428                 }
429             }
430     }
431
432     /**
433      * Turns the target object into an ActiveObject attached to a default node in the local JVM.
434      * The type of the stub is is the type of the existing object.
435      * @param target The object to turn active
436      * @return a reference (possibly remote) on a Stub of the existing object
437      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
438      * @exception NodeException if the DefaultNode cannot be created
439      */

440     public static Object JavaDoc turnActive(Object JavaDoc target)
441         throws ActiveObjectCreationException, NodeException {
442         return turnActive(target, (Node) null);
443     }
444
445     /**
446      * Turns the target object into an Active Object and send it to the Node
447      * identified by the given url.
448      * The type of the stub is is the type of the existing object.
449      * @param target The object to turn active
450      * @param nodeURL the URL of the node where to create the active object on. If null, the active object
451      * is created localy on a default node
452      * @return a reference (possibly remote) on a Stub of the existing object
453      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
454      * @exception NodeException if the node was null and that the DefaultNode cannot be created
455      */

456     public static Object JavaDoc turnActive(Object JavaDoc target, String JavaDoc nodeURL)
457         throws ActiveObjectCreationException, NodeException {
458         if (nodeURL == null) {
459             return turnActive(target, target.getClass().getName(), null, null,
460                 null);
461         } else {
462             return turnActive(target, target.getClass().getName(),
463                 NodeFactory.getNode(nodeURL), null, null);
464         }
465     }
466
467     /**
468      * Turns the target object into an Active Object and send it to the given Node
469      * or to a default node in the local JVM if the given node is null.
470      * The type of the stub is is the type of the target object.
471      * @param target The object to turn active
472      * @param node The Node the object should be sent to or null to create the active
473      * object in the local JVM
474      * @return a reference (possibly remote) on a Stub of the target object
475      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
476      * @exception NodeException if the node was null and that the DefaultNode cannot be created
477      */

478     public static Object JavaDoc turnActive(Object JavaDoc target, Node node)
479         throws ActiveObjectCreationException, NodeException {
480         return turnActive(target, target.getClass().getName(), node, null, null);
481     }
482
483     /**
484      * Turns the target object into an Active Object and send it to the given Node
485      * or to a default node in the local JVM if the given node is null.
486      * The type of the stub is is the type of the target object.
487      * @param target The object to turn active
488      * @param node The Node the object should be sent to or null to create the active
489      * object in the local JVM
490      * @param activity the possibly null activity object defining the different step in the activity of the object.
491      * see the definition of the activity in the javadoc of this classe for more information.
492      * @param factory the possibly null meta factory giving all factories for creating the meta-objects part of the
493      * body associated to the reified object. If null the default ProActive MataObject factory is used.
494      * @return a reference (possibly remote) on a Stub of the target object
495      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
496      * @exception NodeException if the node was null and that the DefaultNode cannot be created
497      */

498     public static Object JavaDoc turnActive(Object JavaDoc target, Node node, Active activity,
499         MetaObjectFactory factory)
500         throws ActiveObjectCreationException, NodeException {
501         return turnActive(target, target.getClass().getName(), node, activity,
502             factory);
503     }
504
505     /**
506      * Turns a Java object into an Active Object and send it to a remote Node or to a
507      * local node if the given node is null.
508      * The type of the stub is given by the parameter <code>nameOfTargetType</code>.
509      * @param target The object to turn active
510      * @param nameOfTargetType the fully qualified name of the type the stub class should
511      * inherit from. That type can be less specific than the type of the target object.
512      * @param node The Node the object should be sent to or null to create the active
513      * object in the local JVM
514      * @return a reference (possibly remote) on a Stub of the target object
515      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
516      * @exception NodeException if the node was null and that the DefaultNode cannot be created
517      */

518     public static Object JavaDoc turnActive(Object JavaDoc target, String JavaDoc nameOfTargetType,
519         Node node) throws ActiveObjectCreationException, NodeException {
520         return turnActive(target, nameOfTargetType, node, null, null);
521     }
522
523     /**
524      * Turns a Java object into an Active Object and send it to a remote Node or to a
525      * local node if the given node is null.
526      * The type of the stub is given by the parameter <code>nameOfTargetType</code>.
527      * A Stub is dynamically generated for the existing object. The result of the call
528      * will be an instance of the Stub class pointing to the proxy object pointing
529      * to the body object pointing to the existing object. The body can be remote
530      * or local depending if the existing is sent remotely or not.
531      * @param target The object to turn active
532      * @param nameOfTargetType the fully qualified name of the type the stub class should
533      * inherit from. That type can be less specific than the type of the target object.
534      * @param node The Node the object should be sent to or null to create the active
535      * object in the local JVM
536      * @param activity the possibly null activity object defining the different step in the activity of the object.
537      * see the definition of the activity in the javadoc of this classe for more information.
538      * @param factory the possibly null meta factory giving all factories for creating the meta-objects part of the
539      * body associated to the reified object. If null the default ProActive MataObject factory is used.
540      * @return a reference (possibly remote) on a Stub of the target object
541      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
542      * @exception NodeException if the node was null and that the DefaultNode cannot be created
543      */

544     public static Object JavaDoc turnActive(Object JavaDoc target, String JavaDoc nameOfTargetType,
545         Node node, Active activity, MetaObjectFactory factory)
546         throws ActiveObjectCreationException, NodeException {
547         if (node == null) {
548             //using default proactive node
549
node = NodeFactory.getDefaultNode();
550         }
551
552         if (factory == null) {
553             factory = ProActiveMetaObjectFactory.newInstance();
554         }
555
556         try {
557             return createStubObject(target, nameOfTargetType, node, activity,
558                 factory);
559         } catch (MOPException e) {
560             Throwable JavaDoc t = e;
561
562             if (e.getTargetException() != null) {
563                 t = e.getTargetException();
564             }
565
566             throw new ActiveObjectCreationException(t);
567         }
568     }
569
570     /**
571      * Turns a Java object into an Active Object and send it to remote Nodes mapped to the given virtualnode in
572      * the XML deployment descriptor.
573      * The type of the stub is given by the parameter <code>nameOfTargetType</code>.
574      * @param target The object to turn active
575      * @param nameOfTargetType the fully qualified name of the type the stub class should
576      * inherit from. That type can be less specific than the type of the target object.
577      * @param virtualnode The VirtualNode where the target object will be turn into an Active Object
578      * Target object will be turned into an Active Object on each node mapped to the given virtualnode in XML deployment descriptor.
579      * @return an array of references (possibly remote) on a Stub of the target object
580      * @exception ActiveObjectCreationException if a problem occur while creating the stub or the body
581      * @exception NodeException if the node was null and that the DefaultNode cannot be created
582      */

583     public static Object JavaDoc turnActive(Object JavaDoc target, String JavaDoc nameOfTargetType,
584         VirtualNode virtualnode)
585         throws ActiveObjectCreationException, NodeException {
586         if (virtualnode != null) {
587             Node[] nodeTab = virtualnode.getNodes();
588             Group aoGroup = null;
589             try {
590                 aoGroup = ProActiveGroup.getGroup(ProActiveGroup.newGroup(
591                             target.getClass().getName()));
592             } catch (ClassNotFoundException JavaDoc e) {
593                 throw new ActiveObjectCreationException(
594                     "Cannot create group of active objects" + e);
595             } catch (ClassNotReifiableException e) {
596                 throw new ActiveObjectCreationException(
597                     "Cannot create group of active objects" + e);
598             }
599
600             for (int i = 0; i < nodeTab.length; i++) {
601                 Object JavaDoc tmp = turnActive(target, nameOfTargetType,
602                         (Node) nodeTab[i], null, null);
603                 aoGroup.add(tmp);
604             }
605
606             return aoGroup;
607         } else {
608             throw new NodeException(
609                 "VirtualNode is null, unable to active the object");
610         }
611     }
612
613     /**
614      * Registers an active object into a RMI registry. In fact it is the
615      * remote version of the body of the active object that is registered into the
616      * RMI Registry under the given URL.
617      * @param obj the active object to register.
618      * @param url the url under which the remote body is registered.
619      * @exception java.io.IOException if the remote body cannot be registered
620      */

621     public static void register(Object JavaDoc obj, String JavaDoc url)
622         throws java.io.IOException JavaDoc {
623         // Check if obj is really a reified object
624
if (!(MOP.isReifiedObject(obj))) {
625             throw new java.io.IOException JavaDoc("The given object " + obj +
626                 " is not a reified object");
627         }
628
629         // Find the appropriate remoteBody
630
org.objectweb.proactive.core.mop.Proxy myProxy = ((StubObject) obj).getProxy();
631
632         if (myProxy == null) {
633             throw new java.io.IOException JavaDoc(
634                 "Cannot find a Proxy on the stub object: " + obj);
635         }
636
637         BodyProxy myBodyProxy = (BodyProxy) myProxy;
638         UniversalBody body = myBodyProxy.getBody().getRemoteAdapter();
639
640         if (body instanceof RemoteBodyAdapter) {
641             RemoteBodyAdapter.register((RemoteBodyAdapter) body, url);
642             if (logger.isInfoEnabled()) {
643                 logger.info("Success at binding url " + url);
644             }
645         } else {
646             if (body instanceof IbisRemoteBodyAdapter) {
647                 IbisRemoteBodyAdapter.register((IbisRemoteBodyAdapter) body, url);
648                 if (logger.isInfoEnabled()) {
649                     logger.info("Success at binding url " + url);
650                 }
651             } else {
652                 throw new java.io.IOException JavaDoc(
653                     "Cannot reconize the type of this UniversalBody: " +
654                     body.getClass().getName());
655             }
656         }
657     }
658
659     /**
660      * Unregisters an active object previously registered into a RMI registry.
661      * @param url the url under which the active object is registered.
662      * @exception java.io.IOException if the remote object cannot be removed from the registry
663      */

664     public static void unregister(String JavaDoc url) throws java.io.IOException JavaDoc {
665         RemoteBodyAdapter.unregister(url);
666         if (logger.isDebugEnabled()) {
667             logger.debug("Success at unbinding url " + url);
668         }
669     }
670
671     /**
672      * Looks-up an active object previously registered in a RMI registry. In fact it is the
673      * remote version of the body of an active object that can be registered into the
674      * RMI Registry under a given URL. If the lookup is successful, the method reconstructs
675      * a Stub-Proxy couple and point it to the RemoteBody found.
676      * @param classname the fully qualified name of the class the stub should inherit from.
677      * @param url the url under which the remote body is registered.
678      * @return a remote reference on a Stub of type <code>classname</code> pointing to the
679      * remote body found
680      * @exception java.io.IOException if the remote body cannot be found under the given url
681      * or if the object found is not of type RemoteBody
682      * @exception ActiveObjectCreationException if the stub-proxy couple cannot be created
683      */

684     public static Object JavaDoc lookupActive(String JavaDoc classname, String JavaDoc url)
685         throws ActiveObjectCreationException, java.io.IOException JavaDoc {
686         UniversalBody b = null;
687         if ("ibis".equals(System.getProperty("proactive.communication.protocol"))) {
688             b = IbisRemoteBodyAdapter.lookup(url);
689         } else {
690             b = RemoteBodyAdapter.lookup(url);
691         }
692
693         try {
694             return createStubObject(classname, b);
695         } catch (MOPException e) {
696             Throwable JavaDoc t = e;
697
698             if (e.getTargetException() != null) {
699                 t = e.getTargetException();
700             }
701
702             throw new ActiveObjectCreationException("Exception occured when trying to create stub-proxy",
703                 t);
704         }
705     }
706
707     /**
708      * Blocks the calling thread until the object <code>future</code>
709      * is available. <code&