public class JavaApplicationCall
extends java.lang.Object
implements java.io.Serializable
Provides an easy way to run Java applications on the IBM i system's Java Virtual Machine from a client. The client Java program specifies the environment, the program to run, and the program parameters. The program then runs on the IBM i system's Java Virtual Machine. Text-based input/output is provided by JavaApplicationCall. Input can be sent to the Java program which will receive the input via standard input (stdin). Standard output (stdout) and standard error (stderr) text generated by the Java program are received by JavaApplicationCall and made available to the calling program. JavaApplicationCall does not support displaying the graphical user interface of the IBM i system's Java program on the client. Other Java facilities, such as remote AWT must be used to display graphical interfaces on the client.
Sockets are used to send stdin, stdout and stderr between client and IBM i system. The port used can be set via setPort(). The default port sequence is 2850, 2851 and 2852. If the port is in use, this class searches for available ports if findPort is true. stdin, stdout and stderr are not transported across a secure connection even when the rest of the Toolbox is using SSL.
Note: The presence of a firewall, in either direction between the IBM i system and the client, may prevent JavaApplicationCall from opening the necessary additional ports (for stdin, stdout, and stderr). The administrator may need to authenticate the application through the firewall in both directions: From client to IBM i system; and from IBM i system to client.
For example, suppose the Java class HelloWorld resides in directory /javatest on the system. The following calls this program and receives program output written to stdout and stderr.
import com.ibm.as400.access.*; public class test implements Runnable { JavaApplicationCall jaCall; public static void main(String[] args) { test me = new test(); me.Main(args); } void Main(String[] args) { try { // The IBM i system where the Java program to run, is located. AS400 as400 = new AS400(); // Construct a JavaApplicationCall object. jaCall = new JavaApplicationCall(as400); // Set the name of the Java application to be run. jaCall.setJavaApplication("HelloWorld"); // Set the classpath environment variable used by the IBM i system's // JVM so it can find the class to run. jaCall.setClassPath("/javatest"); // Start the thread that will receive stdout Thread outputThread = new Thread(this); outputThread.start(); // Start the program. The call to run() will not return // until the IBM i system Java program completes. If the Toolbox // cannot start the Java program, false is returned with // a list of AS400Message objects indicating why the program // could not start. if (jaCall.run() != true) { AS400Message[] messageList = jaCall.getMessageList(); for (int msg = 0; msg < messageList.length; msg++) System.out.println(messageList[msg].toString()); } } catch (Exception e) { e.printStackTrace(); } System.exit(0); } // This thread will get the output from the IBM i system Java program, // and print it. Note the call to sleep(). // The getXxxString() methods return immediately even if there is no data. public void run() { while (true) { String stdOut = jaCall.getStandardOutString(); if (stdOut != null) System.out.println(stdOut); String stdErr = jaCall.getStandardErrorString(); if (stdErr != null) System.out.println(stdErr); try { Thread.sleep(100); } catch (Exception e) {} } } }
Constructor and Description |
---|
JavaApplicationCall()
Constructs a JavaApplicationCall object.
|
JavaApplicationCall(AS400 system)
Constructs a JavaApplicationCall object.
|
JavaApplicationCall(AS400 system,
java.lang.String application)
Constructs a JavaApplicationCall object.
|
JavaApplicationCall(AS400 system,
java.lang.String application,
java.lang.String classPath)
Constructs a JavaApplicationCall object.
|
Modifier and Type | Method and Description |
---|---|
void |
addActionCompletedListener(ActionCompletedListener listener)
Adds an ActionCompletedListener to be notified when the Java application ends.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener to be notified when the value of any bound property
changes.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a listener to be notified when the value of any constrained
property changes.
|
java.lang.String |
getClassPath()
Returns the value of the CLASSPATH environment variable when running
the Java program.
|
CommandCall |
getCommandCall()
Returns the CommandCall object that was used in the most recent invocation of
run() . |
int |
getDefaultPort()
Returns the default port used to transfer stdin, stdout,
and stderr between the client and the IBM i system.
|
int |
getGarbageCollectionFrequency()
Returns the relative frequency that garbage collection runs.
|
int |
getGarbageCollectionInitialSize()
Returns the initial size, in kilobytes, of the garbage collection heap.
|
java.lang.String |
getGarbageCollectionMaximumSize()
Returns the maximum size, in kilobytes, that the garbage
collection heap can grow to.
|
int |
getGarbageCollectionPriority()
Returns the priority of the tasks running garbage collection.
|
java.lang.String |
getInterpret()
Returns whether all Java class files should be run interpretively.
|
java.lang.String |
getJavaApplication()
Returns the name of Java application to be run.
|
java.lang.String |
getJobName()
Returns the name that this job will run under.
|
AS400Message[] |
getMessageList()
Returns the list of IBM i system messages generated if the Java program
cannot be started.
|
java.lang.String |
getOptimization()
Returns the optimization level of IBM i system Java programs that
will be created if no Java program is associated with the Java
class.
|
java.lang.String[] |
getOptions()
Returns a list of special options used when running the Java class.
|
java.lang.String[] |
getParameters()
Returns parameter values that are passed to the Java
application.
|
java.util.Properties |
getProperties()
Returns the properties set on the IBM i system's JVM before running
the Java program.
|
java.lang.String |
getSecurityCheckLevel()
Returns the level of warnings given for directories in the
CLASSPATH that have public write authority.
|
java.lang.String |
getStandardErrorString()
Returns the next string written to stderr by the program
running on the system.
|
java.lang.String |
getStandardOutString()
Returns the next string written to stdout by the application.
|
AS400 |
getSystem()
Returns the system which contains the Java program.
|
boolean |
isFindPort()
Indicates if this class should search for a free port.
|
void |
removeActionCompletedListener(ActionCompletedListener listener)
Removes this ActionCompletedListener from the list of listeners.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a property change listener from the list of listeners.
|
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes a vetoable change listener from the list of listeners.
|
boolean |
run()
Run the Java application.
|
void |
sendStandardInString(java.lang.String data)
Sends the stdin to the application running on the system.
|
void |
setClassPath(java.lang.String classPath)
Sets the value of the CLASSPATH environment variable when running
the Java program.
|
void |
setDefaultPort(int port)
Sets the default port.
|
void |
setFindPort(boolean search)
Sets searching for a free port.
|
void |
setGarbageCollectionFrequency(int frequency)
Sets the relative frequency that garbage collection runs.
|
void |
setGarbageCollectionInitialSize(int size)
Sets the initial size, in kilobytes, of the garbage collection
heap.
|
void |
setGarbageCollectionMaximumSize(java.lang.String size)
Sets the maximum size, in kilobytes, that the garbage
collection heap can grow to.
|
void |
setGarbageCollectionPriority(int priority)
Sets the priority of the tasks running garbage collection.
|
void |
setInterpret(java.lang.String interpret)
Sets whether all Java class files should be run interpretively.
|
void |
setJavaApplication(java.lang.String application)
Sets the Java application to be run.
|
void |
setJobName(java.lang.String jobname)
Sets the name that this job will run under.
|
void |
setOptimization(java.lang.String opt)
Sets the optimization level of the IBM i system Java program that
will be created if no Java program is associated with the Java
class.
|
void |
setOptions(java.lang.String[] option)
Sets special options used when running the Java class.
|
void |
setParameters(java.lang.String[] parameters)
Sets one or more parameter values that are passed to the Java
application.
|
void |
setProperties(java.util.Properties property)
Sets the Java Virtual Machine properties when running the Java Application.
|
void |
setSecurityCheckLevel(java.lang.String chklvl)
Sets the level of warnings given for directories in
CLASSPATH that have public write authority.
|
void |
setSystem(AS400 system)
Sets the system.
|
public JavaApplicationCall()
public JavaApplicationCall(AS400 system)
system
- The system on which contains the Java program.public JavaApplicationCall(AS400 system, java.lang.String application)
system
- The system on which contains the Java program.application
- The name of Java program.public JavaApplicationCall(AS400 system, java.lang.String application, java.lang.String classPath)
system
- The system on which contains the Java program.application
- The name of Java program.classPath
- The value of the environment variable CLASSPATH.public void addActionCompletedListener(ActionCompletedListener listener)
listener
- The ActionCompletedListener.removeActionCompletedListener(com.ibm.as400.access.ActionCompletedListener)
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener.removeVetoableChangeListener(java.beans.VetoableChangeListener)
public java.lang.String getClassPath()
Valid values are:
public CommandCall getCommandCall()
run()
.public int getDefaultPort()
public int getGarbageCollectionFrequency()
public int getGarbageCollectionInitialSize()
Possible values are:
public java.lang.String getGarbageCollectionMaximumSize()
Possible values are:
public int getGarbageCollectionPriority()
public java.lang.String getInterpret()
Possible values are:
public java.lang.String getJavaApplication()
public java.lang.String getJobName()
Possible values are:
public AS400Message[] getMessageList()
public java.lang.String getOptimization()
Possible values are:
public java.lang.String[] getOptions()
The possible values are:
public java.lang.String[] getParameters()
public java.util.Properties getProperties()
public java.lang.String getSecurityCheckLevel()
The possible values are:
public java.lang.String getStandardErrorString()
public java.lang.String getStandardOutString()
public AS400 getSystem()
public boolean isFindPort()
public void removeActionCompletedListener(ActionCompletedListener listener)
listener
- The ActionCompletedListener.addActionCompletedListener(com.ibm.as400.access.ActionCompletedListener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener.addVetoableChangeListener(java.beans.VetoableChangeListener)
public boolean run() throws AS400SecurityException, ConnectionDroppedException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ServerStartupException, java.net.UnknownHostException
AS400SecurityException
- If a security or authority error occurs.ConnectionDroppedException
- If the connection is dropped unexpectedly.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ServerStartupException
- If the host server cannot be started.java.net.UnknownHostException
- If the system cannot be located.public void sendStandardInString(java.lang.String data)
data
- The stdin to the system.public void setClassPath(java.lang.String classPath) throws java.beans.PropertyVetoException
Valid values are:
classPath
- The value of the classpath.java.beans.PropertyVetoException
- If the change is vetoed.public void setDefaultPort(int port) throws java.beans.PropertyVetoException
setFindPort()
can be used to tell this class to search for a free port if these
ports are in use.port
- The default port.java.beans.PropertyVetoException
- If the change is vetoed.public void setFindPort(boolean search) throws java.beans.PropertyVetoException
search
- true to search for a port that is not in use; false to not search.
The default value is true.java.beans.PropertyVetoException
- If the change is vetoed.public void setGarbageCollectionFrequency(int frequency) throws java.beans.PropertyVetoException
frequency
- The relative frequency that garbage collection runs.java.beans.PropertyVetoException
- If the change is vetoed.public void setGarbageCollectionInitialSize(int size) throws java.beans.PropertyVetoException
The possible values are:
size
- The initial size of the garbage collection heap.java.beans.PropertyVetoException
- If the change is vetoed.public void setGarbageCollectionMaximumSize(java.lang.String size) throws java.beans.PropertyVetoException
The possible values are:
size
- The maximum size that the garbage collection heap can grow to.java.beans.PropertyVetoException
- If the change is vetoed.public void setGarbageCollectionPriority(int priority) throws java.beans.PropertyVetoException
priority
- The priority of the tasks running garbage collection.java.beans.PropertyVetoException
- If the change is vetoed.public void setInterpret(java.lang.String interpret) throws java.beans.PropertyVetoException
The possible values are:
interpret
- How all Java class files should be run interpretively.java.beans.PropertyVetoException
- If the change is vetoed.public void setJavaApplication(java.lang.String application) throws java.beans.PropertyVetoException
application
- The Java application to be run.java.beans.PropertyVetoException
- If the change is vetoed.public void setJobName(java.lang.String jobname)
The possible values are:
jobname
- The value of the job name.public void setOptimization(java.lang.String opt) throws java.beans.PropertyVetoException
The possible values are:
opt
- The optimization level of the IBM i system Java program that
will be created if no Java program is associated with
the Java class.java.beans.PropertyVetoException
- If the change is vetoed.public void setOptions(java.lang.String[] option) throws java.beans.PropertyVetoException
The possible values are:
option
- The special options used when running the Java class.java.beans.PropertyVetoException
- If the change is vetoed.public void setParameters(java.lang.String[] parameters) throws java.beans.PropertyVetoException
parameters
- The parameters for the Java application.java.beans.PropertyVetoException
- If the change is vetoed.public void setProperties(java.util.Properties property) throws java.beans.PropertyVetoException
property
- The JVM properties.java.beans.PropertyVetoException
- If the change is vetoed.public void setSecurityCheckLevel(java.lang.String chklvl) throws java.beans.PropertyVetoException
The possible values are:
chklvl
- The level of warnings given for directories in the
CLASSPATH that have public write authority.java.beans.PropertyVetoException
- If the change is vetoed.public void setSystem(AS400 system) throws java.beans.PropertyVetoException
system
- The system.java.beans.PropertyVetoException
- If the change is vetoed.