Guild Companies, Inc.  
 
Midrange Programmer - How-To Advice & Free Code
OS/400 Edition
Volume 1, Number 7 - April 11, 2002

Tools from iSeries Java Toolbox: Pinging iSeries Services

by Kevin Vandever

[The code for this article is available for download.]

If your IT shop is anything like the one I work in, the iSeries is only one of many platforms used to run the business. However, it is still probably the primary platform in your shop, and as such it contains the bulk of the business data and logic. Applications on other platforms depend on that business data and logic, so they require the iSeries to be available as much as possible. I'm going to show you a simple way, using Java, to monitor iSeries services, which will help you to discover potential connectivity and resource availability problems before your production applications do.

The Toolbox

IBM's iSeries Toolbox for Java is a set of Java classes used to access a variety of iSeries services. For a detailed explanation of the toolbox, check out my article "Calling a Program Using the iSeries Toolbox for Java" or visit the IBM Toolbox for Java site. In this article, I am going to focus on one of the classes contained within the toolbox. This class allows you to ping, or check, iSeries services to see if they are available. This class is a new feature that was added to the V5R1 release of the toolbox, so you will need that version to use this technique.

An Ounce of Prevention

Say you use the iSeries toolbox to send requests to, and receive responses from, the iSeries via a data queue. If the iSeries is down for some reason, if the communication link is broken, or the specific port used to listen for data queue traffic is inactive, your production application probably traps for errors and handles them in an appropriate fashion. Maybe it writes to a log file, tries the request again, or attempts to contact a support person. Whatever the case, the customer has been affected because the transaction was not completed and, depending on how long it takes for someone to react to the problem, additional customers could be affected without your knowledge. Using the AS400 Java Ping (AS400Jping) class, you can set up a monitoring system that will tell you when the iSeries, or any one of the iSeries services, is unavailable.

Ping400 is a simple Java class that I wrote to ping every iSeries service and display a message telling me if that service is available or not. The class accepts an IP address or host name of the iSeries you want to ping. To run Ping400, use the following Java command:

java Ping400 myas400

A Little Code Goes a Long Way

Ping400 is the class name and myas400 is the host name of the iSeries you want to ping. You can also use an IP address if you don't know or have a host name. Let's take a look at the code. I am going to assume some Java knowledge while explaining this code; if you are not that familiar with Java but still want to use this tool, refer to my article "Java Concepts for iSeries Programmers" for an introduction on installing and using the Java language.

Back to the code. The AS400JPing class and necessary constants reside in the com.ibm.as400.access package, so that package must be imported to the application. I have defined a main method that allows me to call this class from the command line and accept an array of string objects. (A string object is simply some text. Each string is separated by white space.) The following "if" logic ensures that I enter at least one parameter from the command line:

if (args.length == 0)
        {
          System.out.println("Come on, throw me a bone here! I need an 
IP                                                          
          address or system name.");
          return;
        }

If I don't type a parameter after the class name on the command line, the above message will display and the application will end.

Now take a look at the "try" block. The first thing I do is to create an AS400JPing object called pingobj and instantiate it with the iSeries name or IP address entered on the command line. The following line of code takes care of that for me:

AS400JPing pingObj = new AS400JPing(args[0]); 

The AS400JPing class accepts two additional, optional parameters. The first optional parameter is the iSeries service you want to ping, and the second is whether or not you want to use secure sockets to do the pinging. The iSeries service parameter is in the form of an integer constant, and the secure sockets parameter is a Boolean true or false. It defaults to false.

Now it's time to ping the services. There are eight services that handle all the different iSeries service requests. They are represented by constants in the toolbox, and each constant corresponds to a specific service on the iSeries. Let's take a look at the logic used to ping the data queue service:

if (pingObj.ping(AS400.DATAQUEUE))
            System.out.println("The AS/400 Data Queue Service.... on " 
+ 
            args[0] + " is AVAILABLE!");
else
            System.out.println("The AS/400 Data Queue Service.... on " 
+ 
            args[0] + " is NOT Available!");

I call the ping method from the pingobj object I created earlier and pass it the AS400.DATAQUEUE constant to ping the data queue service on my iSeries. It returns a Boolean true or false, and that is why I can call the ping method as a part of the "if" statement. I then display a message based on whether or not the ping was successful. I then perform a ping to the other services (there are seven) and display appropriate messages for each service. If I call the ping method and pass it no parameter, it pings all the services and returns a true value only if all services are available.

Most of the service constants, such as AS400.DATAQUEUE and AS400.SIGNON, are self-explanatory, but others might not be as obvious, so allow me to provide a brief explanation of each service:

  • AS400.COMMAND--batch command submit service
  • AS400.DATAQUEUE--data queue service
  • AS400.DATABASE--DB2 UDB access service
  • AS400.FILE--Integrated File System access service
  • AS400.RECORDACCESS--DB2 record level access service
  • AS400.PRINT--print service
  • AS400.SIGNON--iSeries sign-on service
  • AS400.CENTRAL--all the rest of the services such as program calls, data area access, system values, user information, and a whole lot more
  • Only the Beginning

    I have shown you a simple example of how to ping iSeries services using Java. You may want to kick this technique up a few notches and display the information in HTML or in JavaServer Pages. If so, check out one of Shannon O'Donnell's or Richard Shaler's articles from previous issues. Once you're displaying the information in a Web page, you may then want to refresh the information every so often to get a dynamic picture of your iSeries status. The options are endless. Enjoy!

    Sponsored By
    WORKSRIGHT SOFTWARE

    CASS Certification

    What is it?

    Why do you need it?

    CASS stands for Coding Accuracy Support System. This is a test developed by the US Postal Service to determine whether ZIP Code software can accurately assign ZIP Codes to mailing addresses. CASS-certified software is intended to improve the accuracy of carrier route, 5-digit ZIP, ZIP+4, and delivery point codes.

    CASS certified means the software has passed the test. When you use CASS software to update and maintain your mailing file, your mailing file becomes CASS certified. What does this mean to you?

    CASS certification is the first step in qualifying for postage discounts. Look at the mail you receive at home and at work; you will see that a lot of it was mailed for less than the regular 34-cent rate.

    If your company sends out a lot of mail, there is a good chance CASS certification can cut your postage expense. There are other steps you must perform to get these discounts, but CASS is the first step.

    Exactly what happens when you process your mailing files with CASS software? The software breaks the address down into its individual elements: state, city, street name, and so forth. Then the information is compared to the national ZIP+4 database. If a match is found, the ZIP Code, ZIP+4, delivery point, and carrier route are assigned. Also the delivery line is standardized to comply with Postal Service preferences.

    If an address can't be matched, no action is taken. This has the positive effect of allowing you to identify addresses in your mailing files which possibly can't be delivered, will be delayed in delivery, or at the very minimum need some minor correction to one of the address elements.

    Using CASS certified software has many side benefits. You will be able to identify addresses that are potentially undeliverable. It has been estimated that as much as 30 percent of all advertising mail is never delivered.

    That means the costs of postage, printing, paper, and overhead for the undelivered mail are wasted. If you spend $100,000 on a direct mail campaign, as much as $30,000 could be completely wasted.

    CASS software provides a number of intangible benefits. With CASS certification and barcoding there is a good likelihood that that your mail will be delivered sooner. If your invoices are delivered one day sooner, you may receive payment one day sooner.

    The bottom line is that using CASS software will help you keep your customers' address information in much better shape than they would be otherwise. Your mail may be delivered sooner at less cost, and that means more bottom-line dollars for your company.

    If you would like more information about CASS and CASS software visit our Web site or contact WorksRight Software, Inc. at 601-856-8337.

    THIS ISSUE
    SPONSORED BY:
    Aldon Computer Group
    Midrange Blue Book
    Tramenco
    ASNA
    Profound Logic Software
    WorksRight Software
    BACK ISSUES
    TABLE OF CONTENTS
    VisualAge for RPG: Who Knew It Was So Much Fun?
    Run SQL Scripts Using Operations Navigator
    Success or Failure in Qshell Scripts
    Simplify JSP Applications with JavaBeans, Part 1
    JavaScript: Back to Basics
    Tools from iSeries Java Toolbox: Pinging iSeries Services
      Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
      Last Updated: 4/10/02
    Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.