The Context Object

[Previous] [Next]

Every object that runs under the control of MTS also runs in a context. Multiple MTS objects can run in the same context, which among other things makes it possible for them to be parts of the same transaction. Whenever MTS creates an object, it either assigns the object to an existing context or creates a new context for the object. To make it possible for the object to query and use its context, MTS also creates a specific context object for every object it creates. Every MTS object has such a context object.

Through its context object, every MTS object knows which Windows NT account created the object and also which Windows NT account called it. The context object also can tell whether the object is running in a transaction, and if so, it also can tell about the present state of that transaction.

In this chapter's sample code, you'll see calls to the following methods of the context object:

  • GetObjectContext returns what might seem to be a reference to the context object but really is a reference to the IObjectContext interface that exposes methods and properties of the object's context. Notice that the GetObjectContext method doesn't create the context object; MTS does that automatically when the MTS object is created.
  • CreateInstance is used to create other MTS objects. When you use the CreateInstance method to create an object, MTS makes sure that the object creating and the object created share the same context. This means, for instance, that if both of them require or support transactions, they'll run in the same transaction.
  • SetComplete uses the reference returned by the GetObjectContext method to tell MTS that "I'm finished now, and all went well."
  • SetAbort uses the reference returned by the GetObjectContext method to tell MTS that "I'm finished now, but I failed!"

We'll show you in a minute how to code against the context object, but first we'll take a look at the IObjectControl interface.



Designing for scalability with Microsoft Windows DNA
Designing for Scalability with Microsoft Windows DNA (DV-MPS Designing)
ISBN: 0735609683
EAN: 2147483647
Year: 2000
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net