I have a scenario where I will implement Command pattern like described in this article.
Actually from an Asp.Net MVC view, some user will invoke different commands/actions like Start Live Video, Start Live Image, Start Recording etc.
A Web Socket Server will then receive these commands and dispatch them to a Receiver (a Windows based application). The receiver before executing the requested command, will first acknowledge the received command and will confirm back to sender that the sent command has been received for processing.
Note: The acknowledgement and/or the actual response will be returned to the Web Socket Server always in an asynchronous manner and then accordingly dispatched to the sender. Means whole system is event driven based.
So my question is:
Given the Command pattern described in the article, now which best way I could add Command Acknowledgement to it and will the returned acknowledgment and/or actual response be also in the form of some command/message or something else?
If we are to go something different for dispatching the Acknowledgement or response, then which pattern to use for it?
Best Answer
I think that you are on the correct path way. You could modify the command pattern to pass a callback reference which will be used to notify the
Invoker
for the execution of theCommand
.The abstract receiver would have an added
ExecuteAndNotify
hook method. This method would call the already existingExecute
method on theConcreteCommand
and then execute the another added method calledNotify
. ThisNotify
method would use the callback reference to notify theInvoker
of the succesful execution of the command.The callback reference could be a function pointer if the
Invoker
and theReceiver
are classes in the same application. If they are parts of another service, it could be a URL of a "service".Hope I helped!