public class ProgramCall
extends java.lang.Object
implements java.io.Serializable
The following example demonstrates the use of Program Call:
// Call programs on system named "Hal." AS400 system = new AS400("Hal"); ProgramCall program = new ProgramCall(system); try { // Initialize the name of the program to run. String programName = "/QSYS.LIB/TESTLIB.LIB/TESTPROG.PGM"; // Set up the 3 parameters. ProgramParameter[] parameterList = new ProgramParameter[3]; // First parameter is to input a name. AS400Text nametext = new AS400Text(8); parameterList[0] = new ProgramParameter(nametext.toBytes("John Doe")); // Second parameter is to get the answer, up to 50 bytes long. parameterList[1] = new ProgramParameter(50); // Third parameter is to input a quantity and return a value up to 30 bytes long. byte[] quantity = new byte[2]; quantity[0] = 1; quantity[1] = 44; parameterList[2] = new ProgramParameter(quantity, 30); // Set the program name and parameter list. program.setProgram(programName, parameterList); // Run the program. if (program.run() != true) { // Report failure. System.out.println("Program failed!"); // Show the messages. AS400Message[] messagelist = program.getMessageList(); for (int i = 0; i < messagelist.length; ++i) { // Show each message. System.out.println(messagelist[i]); } } // Else no error, get output data. else { AS400Text text = new AS400Text(50); System.out.println(text.toObject(parameterList[1].getOutputData())); System.out.println(text.toObject(parameterList[2].getOutputData())); } } catch (Exception e) { System.out.println("Program " + program.getProgram() + " issued an exception!"); e.printStackTrace(); } // Done with the system. system.disconnectAllServices();
NOTE: When getting the AS400Message list from programs, users no longer have to create a MessageFile to obtain the program help text. The load() method can be used to retrieve additional message information. Then the getHelp() method can be called directly on the AS400Message object returned from getMessageList(). Here is an example:
if (program.run("myPgm", myParmList) != true) { // Show messages. AS400Message[] messageList = program.getMessageList(); for (int i = 0; i < messageList.length; ++i) { // Show each message. System.out.println(messageList[i].getText()); // Load additional message information. messageList[i].load(); //Show help text. System.out.println(messageList[i].getHelp()); } }
NOTE: When the program runs within the host server job, the library list will be the initial library list specified in the job description in the user profile.
NOTE: There are two ways to run a program in an iasp. Users can call a program directly with path prefixed with the iasp information like "/IASP1/QSYS.LIB/TESTLIB.LIB/TESTPROG.PGM". Users can also call AS400.setIASPGroup to set the asp group information firstly, then call the program in regular library-qualified object name syntax. The second way is recommended. For example:
// Call a program on system named "Hal" on asp "iasp1" AS400 system = new AS400("Hal"); system.setIASPGroup("iasp1"); //If do not use *CURUSR for current library and library list, call other setIASPGroup interfaces. ProgramCall program = new ProgramCall(system); program.setProgram("/QSYS.LIB/TESTLIB.LIB/TESTPROG.PGM");
Constructor and Description |
---|
ProgramCall()
Constructs a ProgramCall object.
|
ProgramCall(AS400 system)
Constructs a ProgramCall object.
|
ProgramCall(AS400 system,
java.lang.String program,
ProgramParameter[] parameterList)
Constructs a program call object.
|
Modifier and Type | Method and Description |
---|---|
void |
addActionCompletedListener(ActionCompletedListener listener)
Adds an ActionCompletedListener.
|
void |
addParameter(ProgramParameter parameter)
Adds a ProgramParameter to the parameter list.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a VetoableChangeListener.
|
void |
cancel()
End program call if the time exceeds the specified time
|
AS400Message[] |
getMessageList()
Returns the list of messages returned from running the program.
|
int |
getMessageOption()
Returns the option for how many messages will be retrieved.
|
ProgramParameter[] |
getParameterList()
Returns the list of parameters.
|
java.lang.String |
getProgram()
Returns the integrated file system pathname for the program.
|
Job |
getServerJob()
Returns a Job object which represents the server job in which the program will be run.
|
AS400 |
getSystem()
Returns the system on which the program is to be run.
|
java.lang.Thread |
getSystemThread()
Returns the thread on which the program would be run, if it were to be called on-thread.
|
int |
getTimeout()
Gets a valid time
|
boolean |
isRunning()
Check if the program is still running
|
boolean |
isStayOnThread()
Indicates whether or not the program will actually get run on the current thread.
|
boolean |
isThreadSafe()
Deprecated.
The name of this method is misleading. Use
isStayOnThread() instead. |
void |
removeActionCompletedListener(ActionCompletedListener listener)
Removes the ActionCompletedListener.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the PropertyChangeListener.
|
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes the VetoableChangeListener.
|
boolean |
run()
Runs the program on the system.
|
boolean |
run(java.lang.String program,
ProgramParameter[] parameterList)
Sets the program name and the parameter list and runs the program on the system.
|
void |
setMessageOption(int messageOption)
Specifies the option for how many messages should be retrieved.
|
void |
setParameterList(ProgramParameter[] parameterList)
Sets the list of parameters to pass to the program.
|
void |
setProgram(java.lang.String program)
Sets the path name of the program.
|
void |
setProgram(java.lang.String program,
ProgramParameter[] parameterList)
Sets the path name of the program and the parameter list.
|
void |
setSystem(AS400 system)
Sets the system to run the program.
|
void |
setThreadSafe(boolean threadSafe)
Specifies whether or not the program should be assumed thread-safe.
|
void |
setTimeOut(int timeOut)
Sets a valid time to run the program
|
void |
suggestThreadsafe()
Specifies that the called program should be assumed to be thread-safe.
|
java.lang.String |
toString()
Returns the string representation of this program call object.
|
public ProgramCall()
public ProgramCall(AS400 system)
system
- The system on which to run the program.public ProgramCall(AS400 system, java.lang.String program, ProgramParameter[] parameterList)
system
- The system on which to run the program.program
- The program name as a fully qualified path name in the library file system. The library and program name must each be 10 characters or less.parameterList
- A list of up to 35 parameters with which to run the program.public void setTimeOut(int timeOut)
timeOut
- the valid time in secpublic int getTimeout()
public boolean isRunning()
public void cancel()
public void addActionCompletedListener(ActionCompletedListener listener)
listener
- The listener object.public void addParameter(ProgramParameter parameter) throws java.beans.PropertyVetoException
parameter
- The ProgramParameter.java.beans.PropertyVetoException
- If the change is vetoed.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener object.public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener object.public AS400Message[] getMessageList()
public int getMessageOption()
public ProgramParameter[] getParameterList()
public java.lang.String getProgram()
public Job getServerJob() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException
AS400.disconnectService()
or AS400.disconnectAllServices()
.
Note: This method is not supported in the Toolbox proxy environment.
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.public AS400 getSystem()
public java.lang.Thread getSystemThread() throws AS400SecurityException, java.io.IOException
AS400SecurityException
- If a security or authority error occurs.java.io.IOException
- If an error occurs while communicating with the system.public boolean isStayOnThread() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.public boolean isThreadSafe()
isStayOnThread()
instead.setThreadSafe()
or the com.ibm.as400.access.ProgramCall.threadSafe
property.
public void removeActionCompletedListener(ActionCompletedListener listener)
listener
- The listener object.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener object.public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener object.public boolean run() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist on the system.public boolean run(java.lang.String program, ProgramParameter[] parameterList) throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException, java.beans.PropertyVetoException
program
- The fully qualified integrated file system path name to the program. The library and program name must each be 10 characters or less.parameterList
- The list of parameters with which to run the program.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist on the system.java.beans.PropertyVetoException
- If a change is vetoed.public void setParameterList(ProgramParameter[] parameterList) throws java.beans.PropertyVetoException
parameterList
- A list of up to 35 parameters with which to run the program.java.beans.PropertyVetoException
- If a change is vetoed.public void setProgram(java.lang.String program, ProgramParameter[] parameterList) throws java.beans.PropertyVetoException
program
- The fully qualified integrated file system path name to the program. The library and program name must each be 10 characters or less.parameterList
- A list of up to 35 parameters with which to run the program.java.beans.PropertyVetoException
- If a change is vetoed.public void setProgram(java.lang.String program) throws java.beans.PropertyVetoException
program
- The fully qualified integrated file system path name to the program. The library and program name must each be 10 characters or less.java.beans.PropertyVetoException
- If the change is vetoed.public void setMessageOption(int messageOption)
messageOption
- A constant indicating how many messages to retrieve. Valid values are:
public void setSystem(AS400 system) throws java.beans.PropertyVetoException
system
- The system on which to run the program.java.beans.PropertyVetoException
- If the change is vetoed.public void setThreadSafe(boolean threadSafe)
threadSafe
- true if the program should be assumed to be thread-safe; false otherwise.public void suggestThreadsafe()
public java.lang.String toString()
toString
in class java.lang.Object