Resource Manager
This module implements resource management in the MCCS subsystem.
- class HealthfulReadyResourceManager(allocatees, healthful_resource_types, *args, **resources)
A resource manager that manages both allocatee readiness and resource health.
- class ResourceManager(allocatees, **resources)
A generic resource manager / tracker.
This resource manager treats resources as abstract concepts that can be allocated to and deallocated from abstract allocatees.
- __init__(allocatees, **resources)
Initialise a new instance.
- Parameters:
allocatees (
Iterable[Hashable]) – targets for allocation of resources.resources (
Iterable[Hashable]) –keyword args, with each keyword being the name of a resource type, and the value being the set of resources of that type managed by this resource manager. For example, to allocate toys, tools and treasure to boxes:
resource_manager = _ResourceManager( boxes, toys={"teddybears", "lego"}, tools={"hammers", "saws", "drills"} treasure={"diamonds", "rubies", "coins"}, }
The resource types will be maintained as separate namespaces, so you can re-use a resource marker across different types. For example, no problem using the number 2 twice in this example:
resource_manager = _ResourceManager( subarrays, station_ids={1, 2}, channel_blocks={2, 3} }
- _validate_allocatee(allocatee)
Check that the allocatee provided is known to this resource manager.
- Parameters:
allocatee (
Hashable) – the allocatee to check- Raises:
ValueError – if the allocatee is not known to this resource manager
- Return type:
- _validate_allocation(allocatee, **resources)
Check that the specified resources can be allocated to the specified allocatee.
This method assumes that the resources and allocatee have been validated.
- Parameters:
- Raises:
ValueError – if the resources are not available to be allocated to the allocatee
- Return type:
- _validate_resources(**resources)
Check that the resources provided are managed by this resource manager.
- Parameters:
- Raises:
ValueError – if any resources are not managed by this resource manager
- Return type:
- allocate(allocatee, **resources)
Allocate resources to an allocatee.
- Parameters:
allocatee (
Hashable) – the allocatee to which resources are to be allocatedresources (
Iterable[Hashable]) –the resources to allocate. Each keyword specifies a resource type, with the value a list of the resources of that type to be allocated. For example:
resource_manager.allocate( "box_1", toys={"lego"}, tools={"hammers", "saws"} }
- Return type:
- deallocate(**resources)
Deallocate resources.
- deallocate_from(allocatee)
Deallocate all resources from an allocatee.
- get_allocated(allocatee)
Get all allocated resources in resource manager.
- class ResourcePool(**resources)
A manager for a finite pool of resources.
The manager can be queried to get a free resource, which then marks the resource as allocated/locked and prevents it being returned again until it is freed.
- __init__(**resources)
Initialise a pool of resources.
Sets all resources as free (allocatable).
- free_all_resources(resource_type=None)
Free all resources in this Resource Pool.
- free_resources(resources)
Mark a resource as unallocated.
- get_free_resource(resource_type)
Get a free (unallocated) resource from the pool.
- Parameters:
resource_type (
Hashable) – the type of resource- Raises:
ValueError – if there a no free resources.
- Return type:
- Returns:
A free resource of the requested type