Client Server Command Design pattern with variable delays

I am writing a client program to control a server which is in turn controlling some large hardware. The server needs to receive commands to initialize, start, stop and control the hardware.

The connection from the client to the server is via a TCP or UDP socket. Each command is encapsulated in an appropriate message using a SCADA protocol (e.g. Modbus or DNP3).

Part of the initialization phase involves sending a sequence of commands from the client to the server. In some cases there must be a delay in seconds between the commands to prevent multiple sub-systems being initialized at the same time. The value of the delay depends on the type of command.

I'm thinking that the Command Design Pattern is a good approach to follow here. The client instantiates ConcreteCommands and the Invoker places it in a queue. I'm not sure how to incorporate the variable delay and whether there's a better pattern which involves a timer and a queue to handle sending messages with variable delays.

I'm using C# but this is probably irrelevant since it's more of a design pattern question.

Answers


It sounds like you need to store a mapping of types to delay. When your server starts, could you cache those delay times? Then call a method that processes the command after a specified delay?

When the server starts:

Dictionary<Type, int> typeToDelayMapping = GetTypeToDelayMapping();

When a command reaches the server, the server can call this:

InvokeCommand(ICommand command, int delayTimeInMilliseconds)

Like so:

InvokeCommand(command, typeToDelayMapping[type]);

Need Your Help

Groovy & Java MongoDB Driver bulk insertion throws exception

java mongodb groovy

the following groovy scripts use the Java MongoDB Driver and try to run a bulk insertion in a separate thread by using GPars.

CUDA 6.5 complains about not supporting gcc 4.9 - what to do?

c++ gcc cuda compatibility

I've just dist-upgraded from Kubuntu 12.04 to 14.04. Now, when I want to compile CUDA code (with CUDA 6.5), I get:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.