A basic example of ISS usage

This example is meant to be a very simple example of usage of ISS. It will not be a real life usage of ISS. It is even an unnecessary use of ISS since there is absolutely no load on the server from our petty processes. But it will help you visualize the theory explained before in actual working java code.

The process

First of all we need a process to run. As stated before it must implement the IProcess interface. This one will simply receive the number of lines it will print out to the standard output when executed.

public class AProcess implements IProcess {

        /** The number of lines to print */
        int lines;

        /**
         * The constructor
         * 
         * @param lines
         */
        public AProcess(int lines) {
                this.lines = lines;
        }

        /** @see pt.digitalis.iss.IProcess#execute() */
        public ProcessResults execute() {
                
                for (int i = 0; i < lines; i++)
                        System.out.println("Printing line number #" + i);
                
                ProcessResults result = new ProcessResults();
                result.setOnError(false);
                
                return result;
        }

}

The caller class

Now we just have to create a caller class that instanciates the processes and delegates them to an ISS instance.

public class Caller {

        /**
         * @param args
         */
        public static void main(String[] args) {

                ISS theISS = ISSManager.getISS("sample iss");
                ServiceRequest request;

                for (int i = 0; i < 5; i++) {
                        System.out.println("### Executing process #" + i + " ###");

                        request = theISS.delegate(new AProcess(i));

                        if (request.getState() == ProcessState.ERROR)
                                System.out.println("[ERROR] The process #" + i
                                                + " ended with errors!");
                }
        }
}

As you can see it is a very simple example. This launches 10 processes for execution. As the ISS instance wont be under heavy load it will execute all of them synchronously and so ISS wont even be noticeable. Every process launched will output one more line that the previous one.

The output

The example is extremely simple. As is it's output.

### Executing process #0 ###
### Executing process #1 ###
Printing line number #0
### Executing process #2 ###
Printing line number #0
Printing line number #1
### Executing process #3 ###
Printing line number #0
Printing line number #1
Printing line number #2
### Executing process #4 ###
Printing line number #0
Printing line number #1
Printing line number #2
Printing line number #3

For a real Sample Application of ISS do check the Sample Application section.