Here is a very simple example application. It adds two numbers together and writes the result to the console.

Java  Copy imageCopy
package stkscalabilitysdk;


import agi.parallel.client.ClusterJobScheduler;
import agi.parallel.client.IJobScheduler;
import agi.parallel.client.Job;
import agi.parallel.infrastructure.Task;

public class SimpleExample {
    public static void main(String[] args) {
        IJobScheduler scheduler = new ClusterJobScheduler("localhost");
        try {
            scheduler.connect();
            Job job = scheduler.createJob();
            Task task = new SimpleTask(1, 1);
            job.addTask(task);
            job.submit();
            job.waitUntilDone();
            System.out.println("Result = " + task.getResult());
        } finally {
            scheduler.dispose();
        }
    }

    public static class SimpleTask extends Task {
        private int a;
        private int b;

        public SimpleTask(int first, int second) {
            a = first;
            b = second;
        }

        @Override
        public void execute() {
            this.setResult(a + b);
        }
    }
}

Lets compile and run this example. To do this open a cmd prompt and enter the following commands. First, create three folders (stkscalabilitysdk, lib, and classes) that will be used for all the example applications in this programmer's guide.

  Copy imageCopy
mkdir stkscalabilitysdk
mkdir lib
mkdir classes

Copy agi.parallel.client-1.1.0.jar to the lib directory. For instance:

  Copy imageCopy
copy [PathToSTKScalabilityApiJavaFolder]\Jars\agi.parallel.client-1.1.0.jar lib

Save SimpleExample.java (copy and paste the above code) to the stkscalabilitysdk folder and compile.

  Copy imageCopy
javac -cp lib\agi.parallel.client-1.1.0.jar -d classes stkscalabilitysdk\SimpleExample.java

Before running the application, make sure to jar the class files.

  Copy imageCopy
jar cvf SimpleExample.jar -C classes/ .

Finally, run the application!

  Copy imageCopy
java -cp "lib\agi.parallel.client-1.1.0.jar;SimpleExample.jar" stkscalabilitysdk.SimpleExample
Important

Make sure to run the jar command before running the application. If the class files are run directly, the ClassNotFoundException exception will be thrown and the task will not run correctly. Below is an example of the output received when the jar step is missing:

Example output of not running jar

The application first connects and submits a task to the coordinator. An agent will be assigned the work and execute the task in an isolated process. The result of the task is finally sent back to the client. That is the basic structure of an application.

Step through the code in an IDE line by line, examine the messages written from the coordinator and agent consoles. Take note of how the coordinator and agent respond stepping through each line. For example, stepping past job.submit will cause the coordinator console to log "added task to queue". What this means will be discussed later.

Step Through Code

Continue to experiment with this application. Try to add more tasks to the job, set the jobs's TaskEnvironment, or modify some of the job options. As this example shows, the basic structure and core pieces of an application written with the API are simple but powerful!

Next Steps

With a rudimentary example application finished, explore the help system and move on to more advanced topics. The following sections give various topics in the API more treatment.

Title

Read this if you want to...

Tutorial

Read a step by step narrative of another sample application.

How To

Get solutions to common patterns in the API.

Key concepts

Understand the key concepts and building blocks of the product.

Debugging

Get instructions on how to step through the remote task code.

Frequently Asked Questions

Get answers to frequently asked questions.

Internals

Gain a firm understanding of the internals of the product.

Library Reference

Explore what is available in the API.