Example: List Spooled Files Asynchronously Without Using Listeners
/////////////////////////////////////////////////////////////////////////
// Example that shows listing all spooled files on a system Asynchronously without
// using the PrintObjectListListener interface. After opening the list the caller
// can do some additional work before waiting for the list to complete.
//
// For more information about AS/400 Printing, refer to :
//
// OS/400 Printer Device Programming, SC41-3713
// IBM AS/400 Printing IV Redbook, GG24-4389
//
/////////////////////////////////////////////////////////////////////////
//
// This source is an example of AS/400 Toolbox for Java "PrintObjectList".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// AS/400 Toolbox for Java
// (C) Copyright IBM Corp. 1997
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
/////////////////////////////////////////////////////////////////////////
import java.util.Enumeration;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.SpooledFileList;
import com.ibm.as400.access.SpooledFile;
public class NPExampleListSplfAsynch2 extends Object
{
private AS400 system_;
public NPExampleListSplfAsynch2(AS400 system)
{
system_ = system;
}
// list all spooled files on the system asynchronously
public void listSpooledFiles()
{
try
{
String strSpooledFileName;
int listed, size;
if( system_ == null )
{
system_ = new AS400();
}
System.out.println(" Now receiving all spooled files Asynchronously without using a listener");
SpooledFileList splfList = new SpooledFileList(system_);
// set filters, all users, on all queues
splfList.setUserFilter("*ALL");
splfList.setQueueFilter("/QSYS.LIB/%ALL%.LIB/%ALL%.OUTQ");
// open list, openAsynchronously() returns immediately
// we have not added any listeners...
splfList.openAsynchronously();
System.out.println(" Do some processing before waiting...");
// ... do some processing here while the list is being built....
System.out.println(" Now wait for list to complete.");
// wait for the list to complete
splfList.waitForListToComplete();
Enumeration enum = splfList.getObjects();
// output the name of all objects on the list
while( enum.hasMoreElements() )
{
SpooledFile splf = (SpooledFile)enum.nextElement();
if (splf != null)
{
// output this spooled file's name
strSpooledFileName = splf.getStringAttribute(SpooledFile.ATTR_SPOOLFILE);
System.out.println(" spooled file = " + strSpooledFileName);
}
}
// clean up after we are done with the list
splfList.close();
}
catch( Exception e )
{
// ...handle any exceptions...
e.printStackTrace();
}
}
public static void main( String args[] )
{
NPExampleListSplfAsynch2 list = new NPExampleListSplfAsynch2(new AS400());
try{
list.listSpooledFiles();
}
catch( Exception e )
{
e.printStackTrace();
}
System.exit(0);
}
}