Resource Management Design Pattern
来源:百度文库 编辑:神马文学网 时间:2024/04/28 18:11:45
Resource Manager Pattern
In Embedded and Realtime Systems, there occur many instances of Resourcemanagement. Most commonly used design pattern to manage resources of a specifictype is the Resource Manager Pattern. This pattern is described using a standardpattern definition template.
This design pattern implementation uses STL (Standard Template Library), soplease review the following articles before this one:
STL Design Patterns
STL Design Patterns II
Intent
The main intention here is to manage multiple resources of the same type. Tomaintain the status of managed resources, a resource manager is implemented thatmaintains two lists of resources. Free list contains all the resources that arefree. Busy list contains all the resources that are busy. A resource allocationrequest is serviced by the resource manager by allocating a resource from thefree list and putting it in the busy list. Similarly, a resource release requestis serviced by the resource manager by inserting the freed resource to the freelist.
Also Known As
Resource Allocator
Resource Pool
Motivation
The resource manager design pattern implements a centralized managementstrategy for resource usage. Looking at the free and busy lists of resourcesgives a clear picture of the current resource usage in the system. Using theresource manager, the application can quickly figure out all allocated resourcesin the system. This information helps in implementing audits also.
Applicability
The resource manager design pattern finds applicability in situations wherecentralized management of multiple resources of same type is involved.
Structure
The resource manager keeps two lists, one for busy resources and one for freeresources. Internally the free list may be maintained as a stack if hottestresource first type of scenario needs to be implemented. If a coldest resourcefirst type of scenario is to be implemented, the free list may be maintained asa queue. The busy list is maintained as a STL map so that resources can bequickly accessed. (The map is keyed with the resource-id, a unique numberassigned to every resource)
Participants
The key actors of this design pattern:
Resource Manager: Manages all free and busy resources using the free queue and busy map.
Free Resource Queue: Keeps track of free resources in a STL queue.
Busy Resource Map: Manages the busy resources in a STL map.
Resource: Defines a resource object with its own resource-id.
Collaboration
The following diagram shows the relationship and collaboration betweenvarious classes involved in the Resource Manager Pattern. Points to note are:
Resource Manager contains the Free Resource Queue and the Busy Resource Map
Free Resource Queue and Busy Resource Map contain Resource objects
Resources are directly allocated from the Resource Manager. The user of the class is not aware of its internal structure as a free and busy lists.
Consequences
When Resource Manager Pattern is used, the programmer always has access toall the resources. Thus any action on resources can be initiated from theResource Manager, instead of handling it separately in all objects that allocateresources.
Implementation
The following scenarios are supported by the Resource Manager:
Allocating a Resource
A system entity sends a request for a resource to resource manager.
The resource manager allocates a resource from the FreeResourceQueue.
The resource manager removes the resource from the FreeResourceQueue.
The resource manager adds the resource to the BusyResourceMap.
The resource manager responds to system entity with the pointer of the allocated resource.
Freeing a Resource
A system entity sends a resource release request to the resource manager.
The resource manager removes the resource from the BusyResourceMap.
The resource manager adds the resource to the FreeResourceQueue.
Adding a Resource
When a resource is created, it is added to the FreeResourceQueue.
Removing a Resource
Check if the resource is present in the BusyResourceMap.
If the resource is present, inform resource about the forced release (if the resource is currently in use, the application using the resource needs to be notified)
Remove the resource from the BusyResourceMap.
If the resource is not present in the BusyResourceMap, remove the resource from the FreeResourceQueue.
Sample Code and Usage
Here is the code for a typical implementation of this pattern using STL:
Resource Manager
#include // STL header file for queue #include
In Embedded and Realtime Systems, there occur many instances of Resourcemanagement. Most commonly used design pattern to manage resources of a specifictype is the Resource Manager Pattern. This pattern is described using a standardpattern definition template.
This design pattern implementation uses STL (Standard Template Library), soplease review the following articles before this one:
STL Design Patterns
STL Design Patterns II
Intent
The main intention here is to manage multiple resources of the same type. Tomaintain the status of managed resources, a resource manager is implemented thatmaintains two lists of resources. Free list contains all the resources that arefree. Busy list contains all the resources that are busy. A resource allocationrequest is serviced by the resource manager by allocating a resource from thefree list and putting it in the busy list. Similarly, a resource release requestis serviced by the resource manager by inserting the freed resource to the freelist.
Also Known As
Resource Allocator
Resource Pool
Motivation
The resource manager design pattern implements a centralized managementstrategy for resource usage. Looking at the free and busy lists of resourcesgives a clear picture of the current resource usage in the system. Using theresource manager, the application can quickly figure out all allocated resourcesin the system. This information helps in implementing audits also.
Applicability
The resource manager design pattern finds applicability in situations wherecentralized management of multiple resources of same type is involved.
Structure
The resource manager keeps two lists, one for busy resources and one for freeresources. Internally the free list may be maintained as a stack if hottestresource first type of scenario needs to be implemented. If a coldest resourcefirst type of scenario is to be implemented, the free list may be maintained asa queue. The busy list is maintained as a STL map so that resources can bequickly accessed. (The map is keyed with the resource-id, a unique numberassigned to every resource)
Participants
The key actors of this design pattern:
Resource Manager: Manages all free and busy resources using the free queue and busy map.
Free Resource Queue: Keeps track of free resources in a STL queue.
Busy Resource Map: Manages the busy resources in a STL map.
Resource: Defines a resource object with its own resource-id.
Collaboration
The following diagram shows the relationship and collaboration betweenvarious classes involved in the Resource Manager Pattern. Points to note are:
Resource Manager contains the Free Resource Queue and the Busy Resource Map
Free Resource Queue and Busy Resource Map contain Resource objects
Resources are directly allocated from the Resource Manager. The user of the class is not aware of its internal structure as a free and busy lists.
Consequences
When Resource Manager Pattern is used, the programmer always has access toall the resources. Thus any action on resources can be initiated from theResource Manager, instead of handling it separately in all objects that allocateresources.
Implementation
The following scenarios are supported by the Resource Manager:
Allocating a Resource
A system entity sends a request for a resource to resource manager.
The resource manager allocates a resource from the FreeResourceQueue.
The resource manager removes the resource from the FreeResourceQueue.
The resource manager adds the resource to the BusyResourceMap.
The resource manager responds to system entity with the pointer of the allocated resource.
Freeing a Resource
A system entity sends a resource release request to the resource manager.
The resource manager removes the resource from the BusyResourceMap.
The resource manager adds the resource to the FreeResourceQueue.
Adding a Resource
When a resource is created, it is added to the FreeResourceQueue.
Removing a Resource
Check if the resource is present in the BusyResourceMap.
If the resource is present, inform resource about the forced release (if the resource is currently in use, the application using the resource needs to be notified)
Remove the resource from the BusyResourceMap.
If the resource is not present in the BusyResourceMap, remove the resource from the FreeResourceQueue.
Sample Code and Usage
Here is the code for a typical implementation of this pattern using STL:
Resource Manager
#include
Resource Management Design Pattern
Design Pattern Summary
Half Call Design Pattern
Protocol Packet Design Pattern
Protocol Layer Design Pattern
Protocol Stack Design Pattern
Resource Allocation and Resource Management Patterns
Timer Management Design Patterns
Hardware/Peripheral Device Design Pattern
Transmit Protocol Handler Design Pattern
Receive Protocol Handler Design Pattern
Glossary of Human Resource Management Terms
Manager Design Pattern in Realtime Systems
Message Factory and Message Interface Design Pattern
Synchronizer Design Pattern for Frame Synchronization
设计与设计管理/Design and Design Management
知识与资源管理(KRM:Konwlege & Resource Management)
知识与资源管理(KRM:Konwlege & Resource Management)
human resource management总结出的面试建议
Project Managing E-Learning A Handbook for Successful Design, Delivery and Management
AJAX resource
OFDMA Resource Allocation
Marathon Press Resource Pages
OFDMA Resource Allocation