public class CommandCall
extends java.lang.Object
implements java.io.Serializable
Note: CommandCall is not designed to return interactive (screen-oriented) results, such as from
"WRK..." and "DSP..." commands. The recommended approach in such cases is to identify an equivalent
IBM i API or program, and use ProgramCall
instead.
The following example demonstrates the use of CommandCall:
// Work with commands on system named "Hal." AS400 system = new AS400("Hal"); CommandCall command = new CommandCall(system); try { // Run the command "CRTLIB FRED." if (command.run("CRTLIB FRED") != true) { // Note that there was an error. System.out.println("Command failed!"); } // Show the messages (returned whether or not there was an error.) AS400Message[] messagelist = command.getMessageList(); for (int i = 0; i < messagelist.length; ++i) { // Show each message. System.out.println(messagelist[i].getText()); } } catch (Exception e) { System.out.println("Command " + command.getCommand() + " issued an exception!"); e.printStackTrace(); } // Done with the system. system.disconnectService(AS400.COMMAND);
NOTE: When getting the message list from commands, users no longer have to create a MessageFile to obtain the message 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 (command.run("myCmd") != true) { // Show messages. AS400Message[] messageList = command.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()); } }
Command
,
Serialized FormModifier and Type | Field and Description |
---|---|
static java.lang.Boolean |
THREADSAFE_FALSE
Indicates that the command should be assumed to be non-threadsafe.
|
static java.lang.Boolean |
THREADSAFE_LOOKUP
Indicates that the command's threadsafety should be looked-up at runtime.
|
static java.lang.Boolean |
THREADSAFE_TRUE
Indicates that the command should be assumed to be threadsafe.
|
Constructor and Description |
---|
CommandCall()
Constructs a CommandCall object.
|
CommandCall(AS400 system)
Constructs a CommandCall object.
|
CommandCall(AS400 system,
java.lang.String command)
Constructs a CommandCall object.
|
Modifier and Type | Method and Description |
---|---|
void |
addActionCompletedListener(ActionCompletedListener listener)
Adds an ActionCompletedListener.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a VetoableChangeListener.
|
java.lang.String |
getCommand()
Returns the command to run.
|
RJob |
getJob()
Deprecated.
Use getServerJob() instead.
|
AS400Message[] |
getMessageList()
Returns the list of messages returned from running the command.
|
AS400Message |
getMessageList(int index)
Returns a message returned from running the command.
|
int |
getMessageOption()
Returns the option for how many messages will be retrieved.
|
Job |
getServerJob()
Returns a Job object which represents the system job in which the command will be run.
|
AS400 |
getSystem()
Returns the system on which the command is to be run.
|
java.lang.Thread |
getSystemThread()
Returns the thread on which the command would be run, if it were to be called on-thread.
|
int |
getThreadsafeIndicator()
Returns the value of the "Threadsafe" attribute of the CL command on the system.
|
boolean |
isStayOnThread()
Indicates whether or not the command will actually get run on the current thread.
|
boolean |
isThreadSafe()
Deprecated.
The name of this method is misleading. Use
isStayOnThread() or getThreadsafeIndicator() 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 command on the system.
|
boolean |
run(byte[] command)
Runs the command on the system.
|
boolean |
run(java.lang.String command)
Sets the command and runs it on the system.
|
void |
setCommand(java.lang.String command)
Sets the command to run.
|
void |
setMessageOption(int messageOption)
Specifies the option for how many messages should be retrieved.
|
void |
setSystem(AS400 system)
Sets the system to run the command.
|
void |
setThreadSafe(boolean threadSafe)
Specifies whether or not the command should be assumed thread-safe.
|
void |
setThreadSafe(java.lang.Boolean threadSafe)
Specifies whether or not the command should be assumed thread-safe.
|
void |
suggestThreadsafe(boolean threadSafe)
Specifies whether or not the command should be assumed to be thread-safe.
|
java.lang.String |
toString()
Returns the string representation of this command call object.
|
public static final java.lang.Boolean THREADSAFE_FALSE
public static final java.lang.Boolean THREADSAFE_TRUE
public static final java.lang.Boolean THREADSAFE_LOOKUP
public CommandCall()
public CommandCall(AS400 system)
system
- The system on which to run the command.public CommandCall(AS400 system, java.lang.String command)
system
- The system on which to run the command.command
- The command to run on the system. If the command is not library qualified,
the library list will be used to find the command.public void addActionCompletedListener(ActionCompletedListener listener)
listener
- The listener object.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener object.public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener object.public java.lang.String getCommand()
public RJob getJob() 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 int getMessageOption()
public AS400Message[] getMessageList()
public AS400Message getMessageList(int index)
index
- The index into the list of messages returned by the command. It must be greater than
or equal to zero and less than the number of messages in the list.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, 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 int getThreadsafeIndicator() 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 isStayOnThread() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException
THREADSAFE_LOOKUP
, then the value returned by this method will depend on the command string that has been specified, in either the constructor or in setCommand()
.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.setThreadSafe(Boolean)
public boolean isThreadSafe() throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException
isStayOnThread()
or getThreadsafeIndicator()
instead.setThreadSafe()
or the com.ibm.as400.access.CommandCall.threadSafe
property.
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 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
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 run(java.lang.String command) throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, java.beans.PropertyVetoException
command
- The command to run. If the command is not library qualified, the library list will be used to find the command.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.java.beans.PropertyVetoException
- If the change is vetoed.public boolean run(byte[] command) throws AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, java.beans.PropertyVetoException
Unlike the run method that takes a string, this method cannot look up the thread safety of the command, and will assume that the command is not thread-safe. If this command is to be run on-thread when running on the system's JVM, setThreadSafe(true) must be called by the application.
Note: Interactive (screen-oriented) results are not returned.
command
- The command to run.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.java.beans.PropertyVetoException
- If the change is vetoed.public void setCommand(java.lang.String command) throws java.beans.PropertyVetoException
command
- The command to run on the system. If the command is not library qualified, the library list will be used to find the command.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 command.java.beans.PropertyVetoException
- If the change is vetoed.public void setThreadSafe(boolean threadSafe)
setThreadSafe(Boolean)
. For example, calling setThreadSafe(true) is equivalent to calling setThreadSafe(Boolean.TRUE).
threadSafe
- true if the command should be assumed to be thread-safe; false otherwise.setThreadSafe(Boolean)
public void setThreadSafe(java.lang.Boolean threadSafe)
THREADSAFE_FALSE
.
threadSafe
- Valid values are:
setThreadSafe(boolean)
,
isStayOnThread()
public void suggestThreadsafe(boolean threadSafe)
threadSafe
- true if the command should be assumed to be thread-safe; false if the command should be assumed to be not thread-safe.public java.lang.String toString()
toString
in class java.lang.Object