MessagesAS400MessageAS400 Message object allows the Java program to retrieve an AS/400 message that is generated from a previous operation (for example, from a command call). From a message object, the Java program can retrieve the following:
The following example shows how to use the AS/400 Message object: |
// Create a command call object. CommandCall cmd = new CommandCall(sys, "myCommand"); // Run the command cmd.run(); // Get the list of messages that are // the result of the command that I // just ran AS400Message[] messageList = cmd.getMessageList(); // Iterate through the list // displaying the messages for (int i = 0; i < messageList.length; i++) { System.out.println(messageList[i].getText()); }
ExamplesThe CommandCall example shows how a message list is used with CommandCall. The ProgramCall example shows how a message list is used with ProgramCall. QueuedMessageThe QueuedMessage class extends the AS400Message class. The QueuedMessage class accesses information about a message on an AS/400 message queue. With this class, a Java program can retrieve:
The following example prints all messages in the message queue of the current (signed-on) user: |
// The message queue is on this as400. AS400 sys = new AS400(mySystem.myCompany.com); // Create the message queue object. // This object will represent the // queue for the current user. MessageQueue queue = new MessageQueue(sys, MessageQueue.CURRENT); // Get the list of messages currently // in this user's queue. Enumeration e = queue.getMessages(); // Print each message in the queue. while (e.hasMoreElements()) { QueuedMessage msg = e.getNextElement(); System.out.println(msg.getText()); }
MessageQueueThe MessageQueue class allows a Java program to interact with an AS/400 message queue. It acts as a container for the QueuedMessage class. The getMessages() method, in particular, returns a list of QueuedMessage objects. The MessageQueue class can do the following:
The following example lists messages in the message queue for the current user: |
// The message queue is on this as400. AS400 sys = new AS400(mySystem.myCompany.com); // Create the message queue object. // This object will represent the // queue for the current user. MessageQueue queue = new MessageQueue(sys, MessageQueue.CURRENT); // Get the list of messages currently // in this user's queue. Enumeration e = queue.getMessages(); // Print each message in the queue. while (e.hasMoreElements()) { QueuedMessage msg = e.getNextElement(); System.out.println(msg.getText()); }
[ Legal | AS/400 Glossary ] |