Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Introduction

This article describes how a JAVA program can explains how to access arguments and how to set and return variables from a job implemented with Java.

Implementation

Receiving

...

Arguments

Variables Arguments are provided by the associated environment variable. environment variables that are mapped to the job.

In the example the environment variable $VAR1 VAR1 is send to stdoutused.

Returning Variables

Variables are Values can be returned as order return variables by writing name key=value pairs to a temporary file that is provided by the controllerAgent. There is one temporary file for each order in each workflow. The name of path to the temporary file is stored in available from the environment variable $JS7 JS7_RETURN_VALUES. The return variable is available with the next step instruction in the workflow.


Code Block
languagejava
firstline1
titleReceiving Arguments and return returning Variables
linenumberstruecollapsetrue
package js7;

import java.io.FileWriter;
import java.io.IOException;

public class SetAndGetVariables {

	protected void setVar(String name, String value) throws IOException {
		try {
			String tmpFileName = System.getenv("JS7_RETURN_VALUES");
			FileWriter fw = new FileWriter(tmpFileName, true);
			fw              
            w.write(name + "=" + value + System.lineSeparator());
			            fw.close();
		} catch (IOException ioe) {
			System.err.println("IOException: " + ioe.getMessage());
		}

	}

    protected String getVar(String name){
       return System.getenv(name);
	}

	public static void main(String[] args) throws IOException {

		SetAndGetVariables setAndGetVariables = new SetAndGetVariables();
		System.out.println("var1=" +  setAndGetVariables.getVar("var1VAR1"));
		setAndGetVariables.setVar("var1", "newValue");
	}

}