Platform SDK: Transaction Server |
[This product will work only on Windows NT 4.0 versions and earlier. For Windows 2000 and later, see COM+ (Component Services).]
To implement the scenario for this section, you will add a method similar to Perform, named StatefulPerform, which uses class member variables to set account numbers. Thus, MoveMoney becomes a stateful object when StatefulPerform is called.
To add a new function to the MoveMoney component
Click here to see the StatefulPerform method
The code for StatefulPerform calls the Perform method. The methods differ in how the account numbers are set. Class member variables for each account must be set before calling StatefulPerform, whereas Perform passes the account numbers by value through function parameters.
When you click the MoveMoney option in the Sample Bank client, it calls the following code to initialize the function:
StatefulPerform = Perform(PrimeAccount, SecondAccount, lngAmount, lngTranType)
When you click the Stateful MoveMoney option, the Sample Bank client calls the following code to initialize the function:
obj.PrimeAccount = PrimeAcct obj.SecondAccount = lSecondAcct Res = obj.StatefulPerform(CLng(Amount), TranType)
The PrimeAccount and SecondAccount properties are actually separate class member variables on the MoveMoney object. Note that the PrimeAccount and SecondAccount properties aren't accessed through the Shared Property Manager properties; the MoveMoney object controls getting and setting the account number values, thus making the MoveMoney object stateful.
Run the Bank client with the MoveMoney option. Then run it again with the Stateful MoveMoney option. You should notice that the stateless version is slightly faster. Try running multiple Bank clients with concurrent transactions. You should notice that the stateless version performs significantly better. The next section explains why.
See Also
Transactions, Deactivating Objects, Context Objects, Stateful Components