Download Chapter 1. ProActive Scheduler
Transcript
Part I: ProActive Scheduler
Chapter 1: ProActive Scheduler
1.4.4.3. Create and Add a ProActive task
Note : It is only possible to add a ProActive task only in a ProActive Job.
To learn how to create a ProActive Job, just go to Section 1.4.3, “Create a ProActive job”. Once your ProActive Job created, it is
possible to just add ONE ProActive task inside your job.
1.4.4.3.1. Define your own ProActive executable
First of all, you must know that you can create your own ProActive executable by implementing scheduler executable interfaces.
What is called 'executable' is in fact, the executed process (that is a Java class in this case). Here's an example to create your own
ProActive executable application :
public class ProActiveExample extends ProActiveExecutable {
private int numberToFind = 5003;
@Override
public Object execute(ArrayList<Node> nodes) {
System.out.println("ProActive job started -!!");
// create workers (on local node)
Vector<Worker> workers = new Vector<Worker>();
for (Node node -: nodes) {
try {
Worker w = (Worker)PAActiveObject.newActive(Worker.class.getName(),
new Object[] { -}, node);
workers.add(w);
} catch (ActiveObjectCreationException e) {
e.printStackTrace();
} catch (NodeException e) {
e.printStackTrace();
}
}
// create controller Controller controller = new Controller(workers);
int result = controller.findNthPrimeNumber(numberToFind);
System.out.println("last prime -: -" + result);
return result;
}
}
As shown in a ProActive tutorial, this example uses the given nodes with the ProActive API in order to start 'workers' on them. The
execute(nodes) method shows what can be done inside this kind of task. For more details about how to use the ProActive API,
see the appropriate documentation. The complete example file can be found under 'jobs_descriptors/Job_ProActive.xml'.
1.4.4.4. Create and Add a ProActive task using XML descriptor
Just take a look at the example below to understand the syntax of the ProActive task :
<task id="Controller">
<description>Will control the workers in order to find the prime number</description>
17