| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (8 out of 14)

Warmbooting a KB Snapshot File

When loading a KB snapshot file, you must select one of the warmbooting afterwards options on the Load KB dialog to restore the snapshot file to its run-time state.

G2 loads and automatically resumes running the current KB as if it had merely been paused. This is called warmbooting. Loading a KB snapshot file restores both the stored KB's knowledge and the real-time data that existed at the time when the KB snapshot file was saved.

If you do not select the warmbooting afterwards check box when loading a KB snapshot file, G2 discards the run-time data that was loaded. The result is the same as if you had loaded a standard KB file.

To warmboot a KB snapshot file:

To warmboot a KB snapshot file programmatically:

As when loading a KB file, when warmbooting a KB snapshot file, G2 sets the scheduler's current time to the current real time. When G2 resumes processing, G2 schedules its processing according to the value of the Scheduler-mode attribute in the Timing Parameters system table of the loaded KB snapshot file.

After loading a KB snapshot file, G2 runs the current KB somewhat differently from its default behavior, as follows:

  1. After the warmboot, G2 invokes no initially rules.

  2. G2 looks for a procedure named warmboot, and executes it, if it exists.

  3. After G2 has finished executing any warmboot procedure, it resumes executing all scanned rules.

Creating Warmboot Procedures

Warmbooting cannot automatically restore the context of procedures and rules that were executing when a KB snapshot file was written. To restore such context, you can provide one or more procedures called warmboot procedures. For example, you might want restart a procedure that was invoked just before the moment when the KB snapshot file was saved. You can accomplish this by using a warmboot procedure.

When the KB in a snapshot file contains a procedure whose name is warmboot, G2 invokes that procedure before beginning execution of the file. This invocation provides a hook that you can use to take whatever action is necessary to restore the needed context. If no procedure named warmboot exists, G2 continues without error. A modularized KB can also contain warmboot procedures that are not named warmboot, as described under Modular Warmboot Procedures.

Non-Modular Warmboot Procedures

When a KB is not modularized, or when one warmboot procedure suffices for all modules, you can provide a procedure named warmboot that does what is needed. This procedure must take no arguments and return no values.

Code the warmboot procedure so that it specifies a set of actions that are appropriate to execute after the KB snapshot file is warmbooted. For example, the sample warmboot procedure shown below duplicates some operations performed when the KB starts, but performs other operations that depend on state information saved as part of the KB snapshot file.

Modular Warmboot Procedures

When a KB contains modules that need to define their own warmboot procedures, some mechanism is needed that invokes them all in the correct order. You could write a procedure named warmboot that does this, but GFR provides a more general capability: it contains a system-defined procedure named warmboot that automatically executes any other warmboot procedures.

When you warmboot a snapshot of a KB that includes GFR, G2 invokes GFR's warmboot procedure just as it would a user-defined procedure with that name. The GFR procedure scans the KB for items of class GFR-STARTUP-OBJECT, each of which can define a warmboot procedure for a module, and executes the procedures specified by the items in the order defined by the module hierarchy.

A warmboot procedure for use with GFR has a different signature than a procedure named warmboot, but otherwise does the same types of things in the same ways that a non-modular warmboot procedure does, as described under Non-Modular Warmboot Procedures. For further information about modular warmboot procedures, see the chapter on managing modules in the G2 Foundation Resources User's Guide.


Caution: If a KB contains more than one procedure named warmboot, the duplicate names could cause G2 to invoke the wrong one. Therefore, a KB that requires GFR must use GFR to execute any warmboot procedures, and must not contain any procedure named warmboot except the one supplied by GFR.

Warmbooting With Catch-Up

G2's default behavior for initializing a warmbooted KB snapshot file might not be appropriate for a KB that is designed to run continuously. For this reason, you can direct G2 to warmboot a KB so that its processing can catch up from the current time saved in the snapshot file to the current real time.

To catch up to the current real time when warmbooting:

G2 initializes the KB snapshot file as follows:

After warmbooting a KB in this manner, and after the scheduler's current time catches up to become equal to the current real time, your KB should reset the Scheduler-mode attribute to the value real time. If your KB does not reset the Scheduler-mode attribute, then G2 continues to run with a setting of as fast as possible.

To reset the scheduler mode to use real time processing after a warmboot:

  1. Create a procedure that changes the Scheduler-mode attribute in the KB's Timing system table from as fast as possible to real time when the scheduler's current time is greater than or equal to the current real time.

    For example, the following procedure restores the Scheduler-mode attribute to the value at the time the KB snapshot file was saved. This procedure assumes that the warmbooted KB includes a text parameter named text-parameter-holding-saved-scheduler-mode, whose value is equal to the value of the Scheduler-mode attribute in the Timing Parameters system table at the time the KB was saved to its snapshot file.

  2. Create a warmboot procedure so that it starts change-to-real-time-when-caught-up.

    G2 executes warmboot when warmbooting the KB. For example:

  3. Warmboot the KB snapshot file selecting the warmboot afterwards with catch-up feature option.

After G2 warmboots the KB, when the scheduler's current time becomes equal to the current real time, the change-to-real-time-when-caught-up procedure restores the value of the Scheduler-mode attribute in the Timing Parameters system table.

For a KB that is warmbooted in this manner, if you reset the resulting current KB, G2 resets the Scheduler-mode attribute to its value that is saved in the KB snapshot file.


Note: You cannot use the warmboot afterwards with catch-up feature option to warmboot KB snapshot files saved under G2 Version 3.0 revision 0 or earlier.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (8 out of 14)

Copyright © 1997 Gensym Corporation, Inc.