Terminating a job from the Java code (DataStage)
You can throw an Exception class object, or throw a ConnectorException class object, or call the Logger.fatal() method to stop a job before it ends naturally.
Throwing an Exception class object
You can use the Exception (java.lang.Exception)
class or its subclass object
from your Processor implementation to stop a job.
The following example shows Java™ code that does a basic
calculation to get a price. If the value set to count
is zero, the Java code throws the java.lang.ArithmeticException
exception
and logs the message: Divide by zero.
public void process() throws Exception
{
int count = 0;
int total = 1000;
…
int price = total / count;
}
The Java code can also construct an
ArithmeticException
object with a message that you specify and throw it to
terminate a job.
public void process() throws Exception
{
…
if (result < 0)
{
throw new ArithmeticException("An exception occurred. result=" + result);
}
}
Throwing a ConnectorException class object
You can use the ConnectorException(com.ibm.is.cc.javastage.api.ConnectorException) class object from Processor implementation to stop a job that is running or to end a design-time operation with a message.
Use the ConnectorException
class to log messages that do not include the stack
trace information and also to assign message IDs to those messages.
In the following example, Java code constructs and throws a
ConnectorException
object after calling the Logger.setComponentID() method. The
connector framework catches the exception, logs the error message An exception
occurred. result=-1 and stops the job. The message ID is IIS-CONN-MYCONN-00999.
public class MyConnector extends Processor
{
public MyConnector()
{
super();
Logger.setComponentID(“MYCONN”);
}
public void process() throws Exception
{
…
if (result < 0)
{
throw new ConnectorException(999, " An exception occurred. result=" + result);
}
}
…
}
Calling the Logger.fatal() method
You can terminate a job by calling the com.ibm.is.cc.javastage.api.Logger.fatal() method from your Processor implementation.
When Java code calls the Logger.fatal() method, the job
does not return the control to the Java code. The
Processor.terminate()
method, which stops the job cannot be invoked. This might
result in an issue while restarting the job.
If your Java code requires a termination process, then use
the ConnectorException
object or any other Exception object, because the
Processor.terminate() method is invoked with the isAborted
argument set to
true.
The following example shows Java code calls the Logger.fatal() method. The job ends and the messageMy job terminates abnormally is logged to the job log with the message ID IIS-CONN-JAVA-00015.
Logger.fatal("My job terminates abnormally.");