Allocating Resources
Each time a resource dispenser chooses to allocate a resource from its holder, the following occurs:
- The resource dispenser declares a resource type identifier (RESTYPID), which describes the type of resource required.
- The resource dispenser calls the holder's IHolder::AllocResource method passing this RESTYPID.
- The holder generates a candidate list from the available resources. Candidates are resources which are either not enlisted in a transaction, or already enlisted in the calling object's transaction.
- These candidates are individually passed to the resource dispenser's IDispenserDriver::RateResource interface where they are rated (on a scale of 0 to 100) by how well the candidate resource matches the desired RESTYPID.
- The holder chooses the resource which the resource dispenser rates as highest.
- The resource dispenser can terminate the rating loop early by assigning the candidate a resource rating of 100 (a perfect fit). A rating of 100 would normally be reserved for candidate resources that are already properly enlisted, unless the resource dispenser concludes that enlistment is an inexpensive operation. If all candidate resources (if any) are rated 0 (unuseable) then a new resource will be created by calling IDispenserDriver::CreateResource.
- If the resource chosen previously is not already enlisted in the calling object's transaction, then the resource dispenser's IDispenserDriver::EnlistResource interface is called.
- The AllocResource method call returns to the resource dispenser with the enlisted resource.