25
Thu, Apr
0 New Articles

Keeping Time with the AS/400

Java
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Let’s face it: Time is important, especially in computer systems. You count on AS/400 jobs to run at certain times. You time stamp almost every event in your physical files. Knowing when something happened is often as important as knowing what happened. Now, take your AS/400 and put it on a network with other AS/400s, PCs, or Microsoft Windows NT servers. Do your two AS/400s sitting in the same computer room have the same time? Now they can, with a Java tool called TimeSync.

TimeSync is a Java application/JavaBean that retrieves the current date and time from the U.S. Naval Observatory’s atomic clock Web site (http://tycho.usno.navy.mil/cgibin/timer.pl) and updates the AS/400 system’s date and time. The USNO Web site indicates Greenwich Mean Time (GMT), also known as Universal Time, based on the atomic clock. TimeSync will properly account for your local time zone, provided your AS/400 system value QUTCOFFSET has the correct offset from GMT. This article is an overview of how to use TimeSync on your AS/400.

How It Works

TimeSync can run on your AS/400 or on any Java platform, such as your PC, that can connect to your AS/400 and to the Internet. If you run it from your PC, for example, TimeSync will connect to the Internet, retrieve the date and time from the USNO Web site, connect to your AS/400, and, finally, update the date and time of your AS/400. Even if your AS/400 is not allowed to connect to the Internet because of firewall issues, TimeSync’s platform flexibility should allow you to come up with a configuration that works for you.

The TimeSync source code and class files for this article can be downloaded from the Midrange Computing Web site at www. midrangecomputing.com/mc. The source files are stored in a .zip file, which you will download. You need an “unzip” utility, such as WinZip, to unpack these files on your PC. When you do, you’ll find three source files:

• TimeSync.java—a class that does all the work

• TimeSyncDriver.java—an example of how to use TimeSync within your own Java applications


• TimeSyncEvent.java—a custom event used by TimeSync to pass time information to registered listeners

You may notice that the .zip file contains more .class files than .java files. This doesn’t mean that you are missing source code; the various .java source files contain some inner classes that end up creating their own .class files when compiled. If the notion of inner classes is new to you, don’t worry. One of the benefits of object-oriented programming (OOP) is that TimeSync hides all of the complexities from you.

Running TimeSync on an AS/400

The following are the minimum requirements for running TimeSync on an AS/400:
• 5769-TC1—TCP/IP Connectivity Utilities for AS/400, installed and configured

• 5769-SS1 Option 12—OS/400-Host Servers, installed, configured, and enabled (start host servers using the command STRHOSTSVR *ALL)

• 5769-JV1—AS/400 Developer Kit for Java, installed

• 5769-JC1—Java Toolbox for the AS/400 (JT400), installed

• A user profile with authority to retrieve and set system values as well as send messages to QSYSOPR

• Internet connectivity for your AS/400

Any firewall between the AS/400 and the Internet must allow the AS/400 to retrieve HTML from the USNO Web site. You must also set up a class path environment variable on your AS/400. This environment variable must specify the JT400 .jar file and the location of the TimeSync class files, as shown in the following command:

ADDENVVAR
ENVVAR(CLASSPATH)VALUE(‘/QIBM/ProdData/HTTP/Public/jt400/lib/jt400.jar:/home:’)

This command adds the class path for the JT400 .jar file as well as the path to the home directory. If you load the TimeSync class files into the home directory on your AS/400 and use this command, the Java Virtual Machine (JVM) on your AS/400 will be able to find it.

Running TimeSync on a PC

The following are the minimum requirements for running TimeSync on a PC:
• The PC must be connected to the Internet.
• Java Development Kit (JDK) 1.1.7 or higher must be installed.
• The JT400 .jar file must be in the PC’s class path environment variable (i.e., CLASSPATH=c:mydirjt400.jar;).

• The PC must be able to make a TCP/IP connection to your AS/400.
• The AS/400 must be configured to run TCP/IP and have the host servers configured. That’s it!

Running TimeSync

TimeSync can be run as a standalone application or used as a component in your own Java application. When run as a standalone application, you must provide a series of parameters to identify which AS/400 it will connect to and how often it will synchronize the time. The


ILE CL program that you can download at www.midrangecomputing.com/mc is an example of how to run the TimeSync class from your AS/400. You could add this program to a subsystem as an Autostart job and let it run continuously. There are many parameters you could pass to this utility, although, in this example, I’m passing only a few of them. Here’s what all the parameters mean:

• AS400NAME—This is the TCP/IP name (or address) of the AS/400 whose time you want to synchronize.

• USERNAME—This is the name of a valid AS/400 user profile.

• PASSWORD—This is the valid password of the user profile used in the previous parameter.

• DLYSEC—This is an optional parameter used to specify the delays between synchronizations. (If the LOOPON parameter is not used, this parameter is ignored.)
• LOOPON—This parameter controls whether synchronization happens one single time or repeats after the value you specify in the DLYSEC parameter. (The default for this value is LOOPOFF.)

• VERBOSEON—This parameter controls whether or not diagnostics are written to the log file. If you specify VERBOSEON, the HTML retrieved will also be placed in the log file. (The default for this parameter is VERBOSEOFF.)

• DEBUGON—This parameter allows the TimeSync class to do everything except actually change the QTIME system value on the AS/400. This is a good way to test everything before you actually start using it. (The default for this parameter is DEBUGOFF.)

• LOGQSYSOPRON—This parameter controls whether a message is written to the QSYSOPR message queue whenever the system time is changed. (The default value for this parameter is LOGQSYSOPROFF.)

If you run the TimeSync CL driver program as a batch program using the Submit job command (SBMJOB), make sure the Allow Multiple Threads (ALWMLTTHD) parameter is set to *YES. When running on the AS/400, any problems or exceptions are written to a QPRINT spool file. You will also get lots of nice diagnostics to this QPRINT spool file if you use the VERBOSEON option.

When testing the utility, I recommend using the DEBUGON parameter to go through the motions of changing the AS/400 date and time without actually changing any system value. You can look at the messages written to QSYSOPR to see if the calculated time is correct for your system. Figure 1 shows you an example of what you’ll see on the AS/400 when running this utility with VERBOSEON specified in the parameters.

TimeSync as Part of Another Java Application

TimeSync may also be used as a class within your own Java applications. TimeSyncDriver.java (provided as part of the source code download from the MC Web site) is a Java GUI application you can run on your PC. To test the TimeSyncDriver GUI, you need to have both JDK 1.1.8 (or higher) and Swing on your PC. TimeSyncDriver will not run from the AS/400, because it has a GUI front-end. The TimeSyncDriver sample application creates a TimeSync object, tells the TimeSync object to set the AS/400 time, and then displays the results in a GUI window.

Before you run the TimeSyncDriver application, you need to edit the source file to qualify your AS/400’s TCP/IP address (domain name) and provide a valid profile and


password. After editing TimeSyncDriver, make sure you recompile it by using the following Java compile command from a command prompt:

javc TimeSyncDriver.java

With the new TimeSyncDriver.class Java class file ready, you can run the TimeSyncDriver application from a command prompt:

java TimeSyncDriver

You should then be presented with a GUI panel, like the one shown in Figure 2.

Running TimeSync from Your Java Application

When running as part of another Java application, TimeSync starts a separate thread to handle all of the synchronization activity. Your application simply uses the mutator methods (like setLoopOn or setDelay) to select the desired behavior and then calls the startSync method to kick off the synchronization process. Don’t forget to use the TimeSync.addActionListener method to register your application with TimeSync. This way you will get a TimeSyncEvent whenever synchronization actually takes place.

The following code snippet shows how to use TimeSync within your own Java application:

TimeSync ts = new TimeSync(“AS400DomainOrIP”, “profile”, “password”);
ts.setDelay(600); //tells TimeSync that we want to resync the time every 10 minutes
ts.setVerboseOn(false); //echo the html and other tidbits to System.out
ts.setDebugOn(true); //just go through the motions. don’t actually change the
sysvals.
ts.addActionListener(this); //we want to know when TimeSync updates AS/400 times
try {

ts.startSync();
}

catch(Exception e){}

The ability to use TimeSync in your own Java application opens up lots of new possibilities. You could, for example, write a Java application that periodically synchronizes the time on a whole group of AS/400s. You could also use TimeSync as part of an application that synchronizes the time on all of the servers in your network.

Sync Up One Last Time

As with any such utility, you should look at the source code carefully to be sure you understand exactly how TimeSync will modify your AS/400. TimeSync will only modify the QDATE and QTIME system values.

QUTCOFFSET and QDATFMT are read to determine how to update the date and time but are not modified themselves. You must ensure that QUTCOFFSET is set with the correct GMT offset for your area (including any daylight saving time offset). I suggest you run the utility, using the DEBUGON parameter until you are satisfied that it performs correctly.

REFERENCES AND RELATED MATERIALS

• IBM AS/400 Toolbox for Java and JT Open Web site: www.as400.ibm.com/toolbox
• Sun Products & APIs Web site: www.javasoft.com/products
• Zappie! Web site (AS/400 Java Tutorials): www.zappie.net


Keeping_Time_with_the_AS-_40005-00.png 400x226

Figure 1: Here’s what you’ll see on the AS/400 when you run the utility.

Keeping_Time_with_the_AS-_40005-01.png 398x66

Figure 2: Run the TimeSyncDriver program on your PC, and you’ll see this GUI.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: