Lets 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 Observatorys atomic clock Web site (http://tycho.usno.navy.mil/cgibin/timer.pl) and updates the AS/400 systems 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, TimeSyncs 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, youll find three source files:
TimeSync.javaa class that does all the work
TimeSyncDriver.javaan example of how to use TimeSync within your own Java applications
TimeSyncEvent.javaa 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 doesnt 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, dont 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-TC1TCP/IP Connectivity Utilities for AS/400, installed and configured
5769-SS1 Option 12OS/400-Host Servers, installed, configured, and enabled (start host servers using the command STRHOSTSVR *ALL)
5769-JV1AS/400 Developer Kit for Java, installed
5769-JC1Java 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 PCs 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. Thats 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, Im passing only a few of them. Heres what all the parameters mean:
AS400NAMEThis is the TCP/IP name (or address) of the AS/400 whose time you want to synchronize.
USERNAMEThis is the name of a valid AS/400 user profile.
PASSWORDThis is the valid password of the user profile used in the previous parameter.
DLYSECThis is an optional parameter used to specify the delays between synchronizations. (If the LOOPON parameter is not used, this parameter is ignored.)
LOOPONThis 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.)
VERBOSEONThis 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.)
DEBUGONThis 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.)
LOGQSYSOPRONThis 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 youll 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/400s 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. Dont 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. dont 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
Figure 1: Heres what youll see on the AS/400 when you run the utility.
Figure 2: Run the TimeSyncDriver program on your PC, and youll see this GUI.
LATEST COMMENTS
MC Press Online