Appendix C. Files of the ProActive source base cited in the manual

C.1. XML descriptors cited in the manual

C.2. Java classes cited in the manual

Example C.16.  InitActive.java

Example C.17.  RunActive.java

Example C.18.  EndActive.java

Example C.21.  ProActive.java

Example C.26.  Body.java

C.3. Tutorial files : Adding activities and migration to HelloWorld

The following files illustrate the tutorial. They are the results of the addition of

  • migration capabilities

  • init and end activities

to the helloworld example of Section 13.10, “The Hello world example”.

      import org.objectweb.proactive.Body;
import org.objectweb.proactive.EndActive;
import org.objectweb.proactive.InitActive;
import org.objectweb.proactive.ProActive;


public class InitializedHello extends Hello implements InitActive, EndActive {
    /** Constructor for InitializedHello. */
    public InitializedHello() {
    }

    /** Constructor for InitializedHello.
     * @param name */
    public InitializedHello(String name) {
        super(name);
    }

    /** @see org.objectweb.proactive.InitActive#initActivity(Body)
     * This is the place where to make initialization before the object
     * starts its activity */
    public void initActivity(Body body) {
        System.out.println("I am about to start my activity");
    }

    /** @see org.objectweb.proactive.EndActive#endActivity(Body)
     * This is the place where to clean up or terminate things after the
     * object has finished its activity */
    public void endActivity(Body body) {
        System.out.println("I have finished my activity");
    }

    /** This method will end the activity of the active object */
    public void terminate() {
        // the termination of the activity is done through a call on the
        // terminate method of the body associated to the current active object
        ProActive.getBodyOnThis().terminate();
    }

    public static void main(String[] args) {
        // Registers it with an URL
        try {
            // Creates an active instance of class HelloServer on the local node
            InitializedHello hello = (InitializedHello)
 org.objectweb.proactive.ProActive.newActive(InitializedHello.class.getName(),
                    new Object[] { "remote" });
            java.net.InetAddress localhost = java.net.InetAddress.getLocalHost();
            org.objectweb.proactive.ProActive.register(hello,
                "//" + localhost.getHostName() + "/Hello");
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

     

Example C.28. InitializedHello.java

      public class InitializedHelloClient {
    public static void main(String[] args) {
        InitializedHello myServer;
        String message;

        try {
            // checks for the server's URL
            if (args.length == 0) {
                // There is no url to the server, so create an active server within this VM
                myServer = (InitializedHello) org.objectweb.proactive.ProActive.newActive(
                        InitializedHello.class.getName(),
                        new Object[] { "local" });
            } else {
                // Lookups the server object
                System.out.println("Using server located on " + args[0]);
                myServer = (InitializedHello) org.objectweb.proactive.ProActive.lookupActive(
                        InitializedHello.class.getName(),
                        args[0]);
            }

            // Invokes a remote method on this object to get the message
            message = myServer.sayHello();
            // Prints out the message
            System.out.println("The message is : " + message);
            myServer.terminate();
        } catch (Exception e) {
            System.err.println("Could not reach/create server object");
            e.printStackTrace();
            System.exit(1);
        }
    }
}

     

Example C.29. InitializedHelloClient.java

      import org.objectweb.proactive.ActiveObjectCreationException;
import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.body.migration.MigrationException;
import org.objectweb.proactive.core.node.NodeException;

import java.io.Serializable;


// the object that will be migrated active has to be Serializable
public class MigratableHello extends InitializedHello implements Serializable {
    /** Creates a new MigratableHello object. */
    public MigratableHello() {
    }

    /** Creates a new MigratableHello object.  
    * @param name the name of the agent */
    // ProActive requires the active object to explicitely define (or redefine)
    // the constructors, so that they can be reified
    public MigratableHello(String name) {
        super(name);
    }

    /** Factory for local creation of the active object
    * @param name the name of the agent
    * @return an instance of a ProActive active object of type MigratableHello */
    public static MigratableHello createMigratableHello(String name) {
        try {
            return (MigratableHello) ProActive.newActive(MigratableHello.class.getName(),
                new Object[] { name });
        } catch (ActiveObjectCreationException aoce) {
            System.out.println("creation of the active object failed");
            aoce.printStackTrace();

            return null;
        } catch (NodeException ne) {
            System.out.println("creation of default node failed");
            ne.printStackTrace();

            return null;
        }
    }

    /** method for migrating
    * @param destination_node destination node */
    public void moveTo(String destination_node) {
        System.out.println("\n-----------------------------");
        System.out.println("starting migration to node : " + destination_node);
        System.out.println("...");

        try {
            // THIS MUST BE THE LAST CALL OF THE METHOD
            ProActive.migrateTo(destination_node);
        } catch (MigrationException me) {
            System.out.println("migration failed : " + me.toString());
        }
    }
}

     

Example C.30. MigratableHello.java

      public class MigratableHelloClient {
    /** entry point for the program
     * @param args destination nodes
     * for example :
    * rmi://localhost/node1 jini://localhost/node2*/
    public static void main(String[] args) { // instanciation-based creation of the active object

        MigratableHello migratable_hello = MigratableHello.createMigratableHello("agent1");

        // check if the migratable_hello has been created
        if (migratable_hello != null) {
            // say hello
            System.out.println(migratable_hello.sayHello());

            // start moving the object around
            for (int i = 0; i < args.length; i++) {
                migratable_hello.moveTo(args[i]);
                System.out.println("received message : " +
                    migratable_hello.sayHello());
            }

            // possibly terminate the activity of the active object ...
            migratable_hello.terminate();
        } else {
            System.out.println("creation of the active object failed");
        }
    }
}

     

Example C.31. MigratableHelloClient.java

      package org.objectweb.proactive.examples.hello;

import org.objectweb.proactive.ActiveObjectCreationException;
import org.objectweb.proactive.Body;
import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.body.migration.Migratable;
import org.objectweb.proactive.core.node.NodeException;
import org.objectweb.proactive.ext.migration.MigrationStrategyManager;
import org.objectweb.proactive.ext.migration.MigrationStrategyManagerImpl;


/** This class allows the "migration" of a graphical interface. A gui object is attached
 * to the current class, and the gui is removed before migration, thanks to the use
 * of a MigrationStrategyManager */
public class HelloFrameController extends MigratableHello {
    HelloFrame helloFrame;
    MigrationStrategyManager migrationStrategyManager;

    /**required empty constructor */
    public HelloFrameController() {
    }

    /**constructor */
    public HelloFrameController(String name) {
        super(name);
    }

    /** This method attaches a migration strategy manager to the current active object.
     * The migration strategy manager will help to define which actions to take before
     * and after migrating */
    public void initActivity(Body body) {
        // add a migration strategy manager on the current active object
        migrationStrategyManager = new MigrationStrategyManagerImpl((Migratable)
 ProActive.getBodyOnThis());
        // specify what to do when the active object is about to migrate
        // the specified method is then invoked by reflection
        migrationStrategyManager.onDeparture("clean");
    }

    /** Factory for local creation of the active object
    * @param name the name of the agent
    * @return an instance of a ProActive active object of type HelloFrameController */
    public static HelloFrameController createHelloFrameController(String name) {
        try {
            // creates (and initialize) the active object
            HelloFrameController obj = (HelloFrameController) ProActive.newActive(
                    HelloFrameController.class.getName(),
                    new Object[] { name });

            return obj;
        } catch (ActiveObjectCreationException aoce) {
            System.out.println("creation of the active object failed");
            aoce.printStackTrace();

            return null;
        } catch (NodeException ne) {
            System.out.println("creation of default node failed");
            ne.printStackTrace();

            return null;
        }
    }

    public String sayHello() {
        if (helloFrame == null) {
            helloFrame = new HelloFrame("Hello from " +
                    ProActive.getBodyOnThis().getNodeURL());
            helloFrame.show();
        }

        return "Hello from " + ProActive.getBodyOnThis().getNodeURL();
    }

    public void clean() {
        System.out.println("killing frame");
        helloFrame.dispose();
        helloFrame = null;
        System.out.println("frame is killed");
    }
}

     

Example C.32. HelloFrameController.java

      package org.objectweb.proactive.examples.hello;

/** This class allows the creation of a graphical window
 * with a text field */
public class HelloFrame extends javax.swing.JFrame {
    private javax.swing.JLabel jLabel1;

    /** Creates new form HelloFrame */
    public HelloFrame(String text) {
        initComponents();
        setText(text);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     *        It will perform the initialization of the frame */
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
                }
            });

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);
    }

    /** Kill the frame */
    private void exitForm(java.awt.event.WindowEvent evt) {
        //        System.exit(0); would kill the VM !
        dispose(); // this way, the active object agentFrameController stays alive
    }

    /** Sets the text of the label inside the frame */
    private void setText(String text) {
        jLabel1.setText(text);
    }
}

     

Example C.33. HelloFrame.java

C.4. Other files cited in the manual

       <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="configFile">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="p2pconfig" type="p2pconfig" 
          maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="p2pconfig">
    <xs:sequence>
      <xs:element name="loadconfig" type="file" minOccurs="0" 
        maxOccurs="unbounded"/>
      <xs:element name="host" type="host" minOccurs="0" 
        maxOccurs="unbounded"/>
      <xs:element name="configForHost" type="config" minOccurs="0" 
        maxOccurs="1"/>
      <xs:element name="default" type="config" minOccurs="0" 
        maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="file">
    <xs:attribute name="path" type="xs:string" use="required"/>
  </xs:complexType>
  <xs:complexType name="host">
    <xs:attribute name="name" type="xs:string" use="required"/>
  </xs:complexType>
  <xs:complexType name="config">
    <xs:sequence>
      <xs:element name="periods" type="periods"/>
      <xs:element name="register" type="register" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="periods">
    <xs:sequence>
      <xs:element name="period" type="period" minOccurs="0" 
        maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="period">
    <xs:sequence>
      <xs:element name="start" type="moment"/>
      <xs:element name="end" type="moment"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="moment">
    <xs:attribute name="day" type="day" use="required"/>
    <xs:attribute name="hour" type="hour" use="required"/>
    <xs:attribute name="minute" type="minute" use="required"/>
  </xs:complexType>
  <xs:simpleType name="day">
    <xs:restriction base="xs:string">
      <xs:enumeration value="monday"/>
      <xs:enumeration value="tuesday"/>
      <xs:enumeration value="wednesday"/>
      <xs:enumeration value="thursday"/>
      <xs:enumeration value="friday"/>
      <xs:enumeration value="saturday"/>
      <xs:enumeration value="sunday"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="hour">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="23"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="minute">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="59"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="register">
    <xs:sequence>
      <xs:element name="registry" type="registry" minOccurs="0" 
        maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="registry">
    <xs:attribute type="xs:string" use="required" name="url"/>
  </xs:complexType>
</xs:schema>

      

Example C.34. P2P configuration: proactivep2p.xsd

       <?xml version="1.0" encoding="UTF-8"?>
<ProActiveDescriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="http://www-sop.inria.fr/oasis/proactive/schema/3.2/DescriptorSchema.
xsd">
  <componentDefinition>
    <virtualNodesDefinition>
      <virtualNode name="p2pvn" property="multiple"  />
    </virtualNodesDefinition>
  </componentDefinition>
  <deployment>
    <mapping>
      <map virtualNode="p2pvn">
        <jvmSet>
          <vmName value="Jvm1"/>
          <vmName value="Jvm2"/>
        </jvmSet>
      </map>
    </mapping>
    <jvms>
      <jvm name="Jvm1">
        <acquisition>
          <serviceReference refid="p2plookup"/>
        </acquisition>
      </jvm>
      <jvm name="Jvm2">
        <creation>
          <processReference refid="localJVM"></processReference>
        </creation>
      </jvm>
    </jvms>
  </deployment>
  <infrastructure>
  <processes>
      <processDefinition id="localJVM">
        <jvmProcess class="org.objectweb.proactive.core.process.JVMNodeProcess">
  </jvmProcess>
      </processDefinition>
      </processes>
    <services>
      <serviceDefinition id="p2plookup">
        <P2PService nodesAsked="2" acq="rmi" port="2410" NOA="10" TTU="60000" TTL="10">
          <peerSet>
            <peer>rmi://localhost:3000</peer>
          </peerSet>
        </P2PService>
      </serviceDefinition>
    </services>
  </infrastructure>
</ProActiveDescriptor>

      

Example C.35. P2P configuration: sample_p2p.xml

       <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
  <display-name>Apache-SOAP</display-name>
  <description>no description</description>
  <servlet>
    <servlet-name>rpcrouter</servlet-name>
    <display-name>Apache-SOAP RPC Router</display-name>
    <description>no description</description>
    <servlet-class>org.apache.soap.server.http.RPCRouterServlet</servlet-class>
    <init-param>
      <param-name>faultListener</param-name>
      <param-value>org.apache.soap.server.DOMFaultListener</param-value>
    </init-param>
  </servlet>
  <servlet>
    <servlet-name>messagerouter</servlet-name>
    <display-name>Apache-SOAP Message Router</display-name>
    <servlet-class>org.apache.soap.server.http.MessageRouterServlet</servlet-class>
    <init-param>
      <param-name>faultListener</param-name>
      <param-value>org.apache.soap.server.DOMFaultListener</param-value>
    </init-param>
  </servlet>
  <servlet>
    <servlet-name>wsdlServlet</servlet-name>
    <display-name>ProActive WSDL Servlet</display-name>
    <servlet-class>org.objectweb.proactive.ext.webservices.soap.WsdlServlet</servlet-class>
    <init-param>
      <param-name>faultListener</param-name>
      <param-value>org.apache.soap.server.DOMFaultListener</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>rpcrouter</servlet-name>
    <url-pattern>/servlet/rpcrouter</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>messagerouter</servlet-name>
    <url-pattern>/servlet/messagerouter</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>wsdlServlet</servlet-name>
    <url-pattern>/servlet/wsdl</url-pattern>
  </servlet-mapping>
</web-app>

      

Example C.36. SOAP configuration: webservices/web.xml

       <?xml version="1.0" encoding="UTF-8"?>
<ProActiveDescriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"http://www-sop.inria.fr/oasis/proactive/schema/3.2/DescriptorSchema.xsd">
  <variables>
    <DescriptorVariable name="PROACTIVE_HOME" value="ProActive"/>
    <DescriptorVariable name="REMOTE_HOME" value="/home/smariani"/>
    <DescriptorVariable name="HOSTS_NUMBER" value="3"/>
    <DescriptorVariable name="MPIRUN_PATH" value="/usr/src/redhat/BUILD/mpich-1.2.6/bin/mpirun"
/>
    <DescriptorVariable name="QSUB_PATH" value="/opt/torque/bin/qsub"/>
    <JavaPropertyVariable name="USER_HOME" value="java.home"/>
  </variables>
  <componentDefinition>
    <virtualNodesDefinition>
      <virtualNode name="JACOBIVN" />
    </virtualNodesDefinition>
  </componentDefinition>
  <deployment>
    <mapping>
      <map virtualNode="JACOBIVN">
        <jvmSet>
          <vmName value="Jvm1" />
        </jvmSet>
      </map>
    </mapping>
    <jvms>
      <jvm name="Jvm1">
        <creation>
          <processReference refid="sshProcess" />
        </creation>
      </jvm>
    </jvms>
  </deployment>
  <FileTransferDefinitions>
    <FileTransfer id="transfer">
      <!-- Transfer mpi program on remote host -->
      <file src="jacobi" dest="jacobi" />
    </FileTransfer>
  </FileTransferDefinitions>
  <infrastructure>
    <processes>

      <processDefinition id="localJVM1">
        <jvmProcess class="org.objectweb.proactive.core.process.JVMNodeProcess">
          <classpath>
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/ProActive.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/asm.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/log4j.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/components/fractal.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/xercesImpl.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/bouncycastle.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/jsch.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/javassist.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/classes" />
          </classpath>
          <javaPath>
            <absolutePath value="${REMOTE_HOME}/jdk1.5.0_05/bin/java" />
          </javaPath>
          <policyFile>
            <absolutePath value="${REMOTE_HOME}/proactive.java.policy" />
          </policyFile>
          <log4jpropertiesFile>
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/compile/proactive-log4j" />
          </log4jpropertiesFile>
          <jvmParameters>
            <parameter value="-Dproactive.useIPaddress=true" />
            <parameter value="-Dproactive.rmi.port=6099" />
          </jvmParameters>
        </jvmProcess>
      </processDefinition>

      <!-- remote jvm Process -->
      <processDefinition id="jvmProcess">
        <jvmProcess class="org.objectweb.proactive.core.process.JVMNodeProcess">
          <jvmParameters>
            <parameter value="-Dproactive.useIPaddress=true" />
            <parameter value="-Dproactive.rmi.port=6099" />
          </jvmParameters>
        </jvmProcess>
      </processDefinition>

      <!-- pbs Process -->
      <processDefinition id="pbsProcess">
        <pbsProcess class="org.objectweb.proactive.core.process.pbs.PBSSubProcess">
          <processReference refid="localJVM1" />
          <commandPath value=${QSUB_PATH} />
          <pbsOption>
            <hostsNumber>${HOSTS_NUMBER}</hostsNumber>
            <processorPerNode>1</processorPerNode>
            <bookingDuration>00:02:00</bookingDuration>
            <scriptPath>
              <absolutePath value="${REMOTE_HOME}/pbsStartRuntime.sh" />
            </scriptPath>
          </pbsOption>
        </pbsProcess>
      </processDefinition>

      <!-- mpi Process -->
      <processDefinition id="mpiJACOBI">
        <mpiProcess class="org.objectweb.proactive.core.process.mpi.MPIDependentProcess" 
mpiFileName="jacobi">
          <commandPath value=${MPIRUN_PATH} />
          <mpiOptions>
            <processNumber>${HOSTS_NUMBER}</processNumber>
            <localRelativePath>
              <relativePath origin="user.home" value="${PROACTIVE_HOME}/scripts/unix" />
            </localRelativePath>
            <remoteAbsolutePath>
              <absolutePath value="${REMOTE_HOME}/MyApp" />
            </remoteAbsolutePath>
          </mpiOptions>
        </mpiProcess>
      </processDefinition>

      <!-- dependent process -->
      <processDefinition id="dpsJACOBI">
        <dependentProcessSequence class=
"org.objectweb.proactive.core.process.DependentListProcess">
          <processReference refid="pbsProcess" />
          <processReference refid="mpiJACOBI" />
        </dependentProcessSequence>
      </processDefinition>

      <!-- ssh process -->
      <processDefinition id="sshProcess">
        <sshProcess class="org.objectweb.proactive.core.process.ssh.SSHProcess" hostname=
"nef.inria.fr" username="smariani">
          <processReference refid="dpsJACOBI" />
          <FileTransferDeploy refid="transfer">
            <copyProtocol>scp</copyProtocol>
            <!-- local host path -->
            <sourceInfo prefix=
"${USER_HOME}/${PROACTIVE_HOME}/src/org/objectweb/proactive/examples/mpi" />
            <!-- remote host path -->
            <destinationInfo prefix="${REMOTE_HOME}/MyApp" />
          </FileTransferDeploy>
        </sshProcess>
      </processDefinition>
    </processes>
  </infrastructure>
</ProActiveDescriptor>

      

Example C.37. MPI Wrapping: mpi_files/MPIRemote-descriptor.xml