0

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?

7
  • 1
    I don't think you need the Command pattern here. I think you just need some ordinary AJAX. MVC distinguishes its commands by having different controller methods to service those commands. To put it another way, MVC probably already has the Command pattern, you just have to understand MVC and write a proper implementation. Commented Jan 11, 2014 at 17:06
  • You didn't understand what I asked. Acknowledgement/Response messages will also pass through the same web socket server (Command pattern based) module. In that scenario how can I fit the asynchronously received ACKs and Response messages ?. Also I am talking about handling messages on Web Socket Server and not on an Asp.Net Web Server.
    – Faisal Mq
    Commented Jan 11, 2014 at 17:13
  • 1
    That's a good question, but I still don't think the Command Pattern has anything to do with it. It has more to do with the fact that, once your controller method executes, it won't have control anymore, so there's no way to process the received messages, unless you want to wait in the controller method for them. Commented Jan 11, 2014 at 17:18
  • All in all, I'm not sure your question is answerable. We don't know enough details about your particular situation to make an educated guess. The answer to your prima facie question is learn the command pattern, and figure out how it fits into your scenario. Commented Jan 11, 2014 at 17:19
  • 1
    I've changed your title to the actual question you appear to be asking. We'll see where it goes. Commented Jan 11, 2014 at 17:41

1 Answer 1

2

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 the Command.

The abstract receiver would have an added ExecuteAndNotify hook method. This method would call the already existing Execute method on the ConcreteCommand and then execute the another added method called Notify. This Notify method would use the callback reference to notify the Invoker of the succesful execution of the command.

The callback reference could be a function pointer if the Invoker and the Receiver are classes in the same application. If they are parts of another service, it could be a URL of a "service".

Hope I helped!

2
  • Good point. "The callback reference could be a function pointer if the Invoker and the Receiver are classes in the same application. If they are parts of another service, it could be a URL of a "service"." Yes, invoker and receiver are different apps in my case, and yes your service URL looks like a good option to tackle the problem in hand. But I guess depending upon the sent command, the receiver can also respond to the appropriate method/URL on service. What if we let the receiver himself choose where to respond with result?
    – Faisal Mq
    Commented Jan 12, 2014 at 19:58
  • Nice idea. Totally oriented to your application... Commented Jan 12, 2014 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.