beautypg.com

Monitoring and transactions, Using transactions with collections – Echelon LNS User Manual

Page 80

background image

LNS Programmer's Guide

66

To explicitly start a transaction, call the System object’s StartTransaction() method.

Once a transaction is started for an application, all network modifications invoked by
that application will be considered part of the transaction. To end the transaction and
save the changes, call the CommitTransaction() method.

To abort the transaction and cause the LNS database to revert to its state prior to the
start of the transaction, the application can use the CancelTransaction() method.

Explicit transactions and some implicit transactions can be canceled while they are in
progress from within the OnSystemNssIdle event handler. For more information on the
OnSystemNssIdle event handler, see Using the OnSystemNssIdleEvent on page 316.

If a transaction is interrupted prior to completion for any reason, the LNS databases and

the network are returned to their states prior to the start of the transaction. If an

application starts a transaction, then it should commit or cancel the transaction within a

reasonable time to avoid hanging other applications. No application can start a new
transaction until the current one is committed or cancelled. While a transaction is in

progress, LNS automatically queues requests to start either additional implicit or explicit
transactions. If an application shuts down while it has an outstanding transaction, and

another application attempts to start a transaction, the LNS Object Server will abort the

abandoned transaction within 30 seconds. Once a transaction is committed or canceled,
other transactions on the system can begin.

This behavior can cause problems when debugging your application. For example, LNS

may cancel a transaction because your application has started a transaction and is

halted in a breakpoint. You can disable this behavior by setting the following Windows

Registry DWORD entry to a non-zero value:

HKEY_LOCAL_MACHINE\SOFTWARE\LonWorks\NSS\Configuration\Transaction

Debugging

Set its value to 0 (zero), or remove the entry, to disable the transaction debugging mode.

You should only modify this Registry entry for debugging purposes, since disabling this
feature may cause all LNS clients to lock up if the value is changed, and an application

running a transaction is improperly terminated.

Monitoring and Transactions

Transactions may be used when working with monitor and control-related methods and

properties, just as with other LNS operations. However, it is important to realize that
some properties used for monitor and control operations are not stored in the LNS

database persistently. As a result, it is not possible for the LNS Object Server to rollback

changes to these properties if a transaction is cancelled.

For more information on monitor and control, see Chapter 9 of this document.

Using Transactions With Collections

In many cases, you will need to iterate through the objects in a collection. LNS provides

several methods and properties you can use to do so for most collections, such as the
Item property and the ItemByHandle() method. The Item property allows you to

retrieve an object by specifying the object’s name or collection index, and the
ItemByHandle() method allows you to retrieve an object by specifying its handle.