Manager Design Pattern in Realtime Systems

来源:百度文库 编辑:神马文学网 时间:2024/05/24 03:29:16
Manager Design Pattern
Realtime software generally manages multiple entities of the same type. Herewe introduce the Manager Design Pattern to control multiple entities. TheManager design pattern is described using a standard pattern definitiontemplate.
Intent
The main intention here is to manage multiple entities of same type. Forexample, a Terminal Manager will manage all the Terminal objects under itscontrol. This will involve Terminal creation, Terminal deletion, message routingto the Terminal and coordination of activities like switchover between twoTerminals.
Also Known As
Manager-Managed Design Pattern
Managed Object Design Pattern
Motivation
Consider the case where no Manager object is defined. Each Terminal objecthas to know about all other Terminal objects for purposes of message routing andcoordination. Also, in the absence of a Manager there will be no single pointfor Terminal object creation and deletion.
Applicability
This design pattern can be applied whenever a system needs to support manyentities of same or similar type. The Manager object is designed to keep trackof all the entities. In many cases, the Manager will also route messages toindividual entities.
Structure
The Manager object may manage all the entity objects by implementing standarddata structures like array or STL map. The idea is to have a quick way ofindexing to get to a particular entity. This indexing capability is required toquickly access an entity from a numerical id assigned to the entity. Thisnumerical id will be typically included in all the messages received for theseentities.
Participants
The Manager object and the Managed Entities are the main actors in thisdesign pattern. A single Manager object manages multiple entity objects.
Collaboration
Manager to Managed Entity communication is typically done via managerinvoking methods for the individual entities. The return value of a method isused by the entity to communicate with the manager. The routing of messages isalso achieved by invoking the message handler for the entity object.
In more complicated designs, the Manager and entity may communicate via localmessages. In such cases, the variouscoordinationdesign patterns like parallel and serial coordination may be used.
Consequences
The Manager object introduces a clean interface for communicating with any ofthe managed entities. It also provides a centralized point for coordinatingoperations on multiple entity objects.
Implementation
As mentioned earlier, the Manager object contains an array or STL map of allthe entities under its control. The entity collection may be maintained aspointers to the entity objects or entity objects themselves.
Sample Code and Usage
The actions involved in a call processing or maintenance module in a typicalSwitch can bevisualized as a Manager managing many entities of the same type. Consider,V5.2Manager in Xenon. V5.2 Managermanages various V5.2 interfaces for a XEN. ConsiderISUPCall Manager inXenon. ISUP CallManager manages all the ISUP incoming and ISUP outgoing call objects for a XEN.
The code below gives an example of a Terminal Manager which managesTerminal objects. The example covers the message routing, creation and deletionof terminals. An interaction involving multiple terminals is also shown(Terminal Switchover). Also note that the terminal object methods communicate with theTerminal Manager by returning a status value.
Terminal Manager and Terminal
class TerminalManager { Terminal* terminals[MAX_TERMINALS]; public: void handleMessage(Msg* pMsg) { switch (pMsg->getType()) { case CREATE_TERMINAL: terminals[pMsg->getTerminalId()] = new Terminal(pMsg->getTerminalId()); break; case DELETE_TERMINAL: delete terminals[pMsg->getTerminalId()]; break; case RUN_DIAGNOSTICS: status = terminals[pMsg->getTerminalId()]->handleRunDiagnostics(); break; case PERFORM_SWITCHOVER: status1 = terminals[pMsg->getTerminalId1()]->handleOutOfService(); status2 = terminals[pMsg->getTerminalId2()]->handleInService(); break; } } }; class Terminal { TerminalId terminalId; public: Terminal(TerminalID terminalId); ~Terminal(); Status handleRunDiagnostics(); Status handleOutOfService(); Status handleInService(); };
Known Uses
The manager design pattern is used wherever there is a need to managemultiple objects of same or similar behavior.
Related Patterns
Feature Design Patterns likeparallel and serial coordination