יום שני, 5 במאי 2014

Inspecting executing commands for cancelation

Sometimes a New Command Execution should cancel current commands execution or remove older commands from a commands Queue .
For an example:
When a Command is issue to Self driving car to follow a route while other route command is currently executing , the new Route command should cancel the execution of the old one.
There should be a mechanism in the software that its duty is to decide is there a need for canceling a commands before executing the new command ?
The  mechanism should determent:
1.Which commands to cancel ?
2.Can the cancelation process may be invoked in parallel to the execution of the new  command or the new command execution should be blocked until the cancelation process finished .
3.Maybe instead of cancelation of a command execution an execution blocking is needed (in case of resource sharing between the commands and there is a need to boost the current command execution ).
The algorithm for selecting the command should be based on the following parameter's:
1.Commands that are currently executing or in queue .
2.Priority of the current executing commands .
3.Internal concrete state of the current executing commands.
4.Shared resources that are consumed by the current executing commands
5.The period of time left for the old commands to finish it’s duties.
6.System overall state.

One of the architecture dilemmas is where to implement the mechanism  for choosing the commands to be canceled.
Should it be part of the Command ?
Capture46

List <ICommand> GetListOfCommandsToCancel (List <ICommand> pCurrentExecutingCommands).

There is a Single responsibility principle violation in this case I think .And this attitude may lead to DRY violation were each command may implement a similar mechanism .

May be the following implementation :

Capture47

Here there is a decoupling between the command and the commands that should ne canceled.

I think that the return value of the GetListOfCommandsToCancel should be extend to use custom return type

Capture48

The IComamndCancelationInspector may have properties used to query the current domain overall state in order to determent its result.
The recommendation may although contain if the cancel of just postponed the command .

The execution sequence of the process :

Capture49 

Note:
The cancelation process is out of this post scope.

אין תגובות:

הוסף רשומת תגובה