172 lines
7.0 KiB
HTML
172 lines
7.0 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 DataQueue classes to read entries off a data queue" />
|
|
<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="dqconsumerexample" />
|
|
<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 DataQueue classes to read entries off a data queue</title>
|
|
</head>
|
|
<body id="dqconsumerexample"><a name="dqconsumerexample"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Example: Using DataQueue classes to read entries off a data queue</h1>
|
|
<div><p></p>
|
|
<div class="section"><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>///////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Data Queue example. This program uses the Data Queue classes to read
|
|
// entries off a data queue on the server. The entries were put on the
|
|
// queue with the DQProducer example program.
|
|
//
|
|
// This is the consumer side of the producer/consumer example. It reads
|
|
// entries off the queue and process them.
|
|
//
|
|
// Command syntax:
|
|
// DQConsumerExample system
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
import java.io.*;
|
|
import java.util.*;
|
|
import java.net.*;
|
|
import com.ibm.as400.access.*;
|
|
|
|
public class DQConsumerExample extends Object
|
|
{
|
|
public static void main(String[] parameters)
|
|
{
|
|
System.out.println( " " );
|
|
|
|
// if a system name was not specified, display help text and exit.
|
|
if (parameters.length >= 1)
|
|
{
|
|
try
|
|
{
|
|
|
|
// The first parameter is the system that contains the data queue.
|
|
String system = parameters[0];
|
|
|
|
// Create an AS400 object for the server that has the data queue.
|
|
AS400 as400 = new AS400(system);
|
|
|
|
|
|
// Build a record format for the format of the data queue entry.
|
|
// This format matches the format in the DQProducer class. A
|
|
// record consists of:
|
|
// - a four byte number -- the customer number
|
|
// - a four byte number -- the part number
|
|
// - a 20 character string -- the part description
|
|
// - a four byte number -- the number of parts in this order
|
|
|
|
// First create the base data types.
|
|
BinaryFieldDescription customerNumber =
|
|
new BinaryFieldDescription(new AS400Bin4(), "CUSTOMER_NUMBER");
|
|
|
|
BinaryFieldDescription partNumber =
|
|
new BinaryFieldDescription(new AS400Bin4(), "PART_NUMBER");
|
|
|
|
CharacterFieldDescription partName =
|
|
new CharacterFieldDescription(new AS400Text(20, as400), "PART_NAME"
|
|
|
|
BinaryFieldDescription quantity =
|
|
new BinaryFieldDescription(new AS400Bin4(), "QUANTITY"
|
|
|
|
// Build a record format and fill it with the base data types.
|
|
RecordFormat dataFormat = new RecordFormat();
|
|
|
|
dataFormat.addFieldDescription(customerNumber);
|
|
dataFormat.addFieldDescription(partNumber);
|
|
dataFormat.addFieldDescription(partName);
|
|
dataFormat.addFieldDescription(quantity);
|
|
|
|
// Create the data queue object that represents the data queue on
|
|
// the server.
|
|
DataQueue dq = new DataQueue(as400, "/QSYS.LIB/JAVADEMO.LIB/PRODCONS.DTAQ");
|
|
|
|
boolean Continue = true;
|
|
|
|
// Read the first entry off the queue. The timeout value is
|
|
// set to -1 so this program will wait forever for an entry.
|
|
System.out.println("*** Waiting for an entry for process ***");
|
|
|
|
DataQueueEntry DQData = dq.read(-1);
|
|
|
|
while (Continue)
|
|
{
|
|
|
|
// We just read an entry off the queue. Put the data into
|
|
// a record object so the program can access the fields of
|
|
// the data by name. The Record object will also convert
|
|
// the data from server format to Java format.
|
|
Record data = dataFormat.getNewRecord(DQData.getData());
|
|
|
|
// Get two values out of the record and display them.
|
|
Integer amountOrdered = (Integer) data.getField("QUANTITY");
|
|
String partOrdered = (String) data.getField("PART_NAME");
|
|
|
|
System.out.println("Need " + amountOrdered + " of "
|
|
+ partOrdered);
|
|
System.out.println(" ");
|
|
System.out.println("*** Waiting for an entry for process ***");
|
|
|
|
// Wait for the next entry.
|
|
DQData = dq.read(-1);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// If any of the above operations failed say the data queue
|
|
// operation failed and output the exception.
|
|
System.out.println("Data Queue operation failed");
|
|
System.out.println(e);
|
|
}
|
|
}
|
|
|
|
// Display help text when parameters are incorrect.
|
|
else
|
|
{
|
|
System.out.println("");
|
|
System.out.println("");
|
|
System.out.println("");
|
|
System.out.println("Parameters are not correct. Command syntax is:");
|
|
System.out.println("");
|
|
System.out.println(" DQConsumerExample system");
|
|
System.out.println("");
|
|
System.out.println("Where");
|
|
System.out.println("");
|
|
System.out.println(" system = Server that has the data queue");
|
|
System.out.println("");
|
|
System.out.println("For example:");
|
|
System.out.println("");
|
|
System.out.println(" DQConsumerExample mySystem");
|
|
System.out.println("");
|
|
System.out.println("");
|
|
}
|
|
|
|
System.exit(0);
|
|
}
|
|
}</pre>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |