Feature Coordination Realtime Design Patterns

来源:百度文库 编辑:神马文学网 时间:2024/10/02 16:35:32

Feature Coordination Patterns

Feature design involves defining the sequence of messages that will beexchanged between tasks. When designing a feature one of the tasks in thefeature should be identified as the Feature Coordinator. The main role of theFeature Coordinator is to ensure that the feature goes to a logical completion.No feature should be left in suspended animation because of message loss orfailure of a single task involved in the message interactions.

In most cases,the task coordinating the feature will be running a timer to keep track ofprogress of the feature. If the timer times out, the coordinator will takeappropriate recovery action to take the feature execution to a logicalconclusion, i.e. feature success or failure.

Feature coordination can beachieved in several ways. Some of the frequently seen design patterns aredescribed here. The description is in terms of four tasks A, B, C and D that areinvolved in a feature. A is the feature coordinator in all cases.

Cascading Coordination

Here, on receipt of the feature initiation trigger, A handles the message andfurther sends a message trigger to B. As a part of the feature, B sends amessage to C. Again, C does some action and further sends a message to D. Dreplies back to C, C replies back to B and B further replies back to A. Finally, Aindicates about the feature completion.  Most of the times, tasks A, B andC will be keeping a timer to monitor the message interaction. It can be seenthat there is cascade of sub-feature control at tasks C, B and A. The mainadvantage of this scheme is that if any involved task misbehaves, appropriaterecovery action can be taken at points C, B or A, thus isolating the failurecondition. This design however is more complicated to implement because B and Chave to share the coordination role.

Loose Coordination

Here, on receipt of the feature initiation trigger, A handles themessage andsends a message to B. B further sends a message to C and C in turn sendsamessage to D as part of the feature. D takes appropriate action andreplies toA. Here, the feature coordinator task A would be running a timeout. Themainadvantage of this type of coordination is that it involves fewer messageexchanges. The message handling at B and C would be fairlystraightforward. However, it has a disadvantage that if some involvedtask misbehaves,only A would timeout and would know about the failure. But A has nomeans ofisolating it.

Serial Coordination

Here, the feature is initiated by A by sending a message to B. B completesits job and replies back to A. A registers the completion of first phase of thefeature and initiates the second phase by sending a message to C. C takes someaction and replies back to A. A registers the completion of the second phase ofthe feature and initiates the next phase by sending a message to D. D thenperforms its job and replies back to A. Here, A keeps a timer for each phase ofthe feature. This scheme allows the feature coordinator task, A to know aboutthe progress of the feature at all times. Thus the advantage is that A can takeintelligent recovery action if a failure condition hits at some point.The main disadvantage is additional complexity at A.

ParallelCoordination

Here, on receipt of the feature initiation trigger, A sends message triggersto B, C and D tasks. B, C and D perform their jobs and reply back to A. In thiscase A may keep one timer for all the message interactions or it may keepdifferent timers. The main difference of this scheme from the serialcoordination scheme is that there is no dependence of the different phases ofthe feature on each other, so they can be initiated at the same time. Like incase of serial coordination, in this scheme also, intelligent recovery actioncan be taken if a failure condition is hit because A knows about thefeature  progress at all times. In parallel coordination, the delay infeature execution is minimized due to parallel activation of sub-features. Butparallel activation places a higher resource requirement on the system, asmultiple message buffers are acquired at the same time.