Allocating Resources

Each time a resource dispenser chooses to allocate a resource from its holder, the following occurs:

  1. The resource dispenser declares a resource type identifier (RESTYPID), which describes the type of resource required.
  2. The resource dispenser calls the holder's IHolder::AllocResource method passing this RESTYPID.
  3. 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.
  4. 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.
  5. The holder chooses the resource which the resource dispenser rates as highest.
  6. 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.
  7. 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.
  8. The AllocResource method call returns to the resource dispenser with the enlisted resource.