116 lines
4.7 KiB
HTML
116 lines
4.7 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="Example: Using message queues (part 3 of 3)" />
|
||
|
<meta name="abstract" content="" />
|
||
|
<meta name="description" content="" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="tutorl3" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Example: Using message queues (part 3 of 3)</title>
|
||
|
</head>
|
||
|
<body id="tutorl3"><a name="tutorl3"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example: Using message queues (part 3 of 3)</h1>
|
||
|
<div><p></p>
|
||
|
<div class="section"><p>[ <a href="tutorl2.htm#tutorl2">Previous part</a> ]</p>
|
||
|
<p>Use
|
||
|
the following as an example for your program.</p>
|
||
|
<div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
|
||
|
example disclaimer</a> for important legal information.</div>
|
||
|
<pre>//////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Example using the Message Queue function of the IBM Toolbox for Java
|
||
|
//
|
||
|
// This source is an example of IBM Toolbox for Java "Message Queue".
|
||
|
//
|
||
|
//////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
package examples;
|
||
|
|
||
|
|
||
|
import java.io.*;
|
||
|
import java.util.*;
|
||
|
import com.ibm.as400.access.*;
|
||
|
|
||
|
public class displayMessages extends Object
|
||
|
{
|
||
|
|
||
|
public static void main(String[] parameters)
|
||
|
{
|
||
|
displayMessages me = new displayMessages();
|
||
|
|
||
|
me.Main(parameters);
|
||
|
|
||
|
System.exit(0);
|
||
|
}
|
||
|
|
||
|
|
||
|
void displayMessage()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void Main(String[] parms)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
AS400 system = new AS400();
|
||
|
|
||
|
if (parms.length > 0)
|
||
|
system.setSystemName(parms[0]);
|
||
|
|
||
|
MessageQueue queue = new MessageQueue(system, MessageQueue.CURRENT); <a href="#tutorl3__dup0009">Note 1 </a>
|
||
|
|
||
|
|
||
|
Enumeration e = queue.getMessages(); <a href="#tutorl3__dup0010">Note 2 </a>
|
||
|
|
||
|
while (e.hasMoreElements())
|
||
|
{
|
||
|
|
||
|
QueuedMessage message = (QueuedMessage) e.nextElement(); <a href="#tutorl3__dup0011">Note 3 </a>
|
||
|
System.out.println(message.getText()); <a href="#tutorl3__dup0012">Note 4 </a>
|
||
|
}
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}</pre>
|
||
|
</div>
|
||
|
<div class="section"><ol><li id="tutorl3__dup0009"><a name="tutorl3__dup0009"><!-- --></a>The purpose of this program is to display messages in a server
|
||
|
message queue. The <strong>MessageQueue</strong> object of the IBM<sup>®</sup> Toolbox for Java™ is used for this task. When the message
|
||
|
queue object is constructed, the parameters are the AS400 object and the message
|
||
|
queue name. The AS400 object indicates which server contains the resource,
|
||
|
and the message queue name identifies which message queue on the server.
|
||
|
In this case, a constant is used, which tells the message queue object to
|
||
|
access the queue of the signed-on user.</li>
|
||
|
<li id="tutorl3__dup0010"><a name="tutorl3__dup0010"><!-- --></a>The message queue object gets a list of messages from the
|
||
|
server. A connection to the server is made at this point.</li>
|
||
|
<li id="tutorl3__dup0011"><a name="tutorl3__dup0011"><!-- --></a>Remove a message from the list. The message is in the IBM Toolbox
|
||
|
for Java program's
|
||
|
QueuedMessage object.</li>
|
||
|
<li id="tutorl3__dup0012"><a name="tutorl3__dup0012"><!-- --></a>Print the text of the message.</li>
|
||
|
</ol>
|
||
|
<p>[ <a href="tutorl2.htm#tutorl2">Previous part</a> ]</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|