I want to write a CommunicationSupervisor for connection to a device with these features.
- Outgoing messages should be queued in a data structure.
- There is just one Consumer. Consumer should check if there is an element in queue.
- Consumer should send the outgoing message and wait for an incoming response.
- It is possible to produce new outgoing messages while consumer is waiting for a responce but they will not be handled until consumer is getting a response for first element, then second and so on
- If consumer is getting a timeout for a message an exception should be raised but consumer should proceed with the other outgoing messages in the queue.
My question is what is the best method to implement this? Shall I use a SynchronousQueue as a data structure? Or do we have a pattern example for this? By the way We are using Java 6. So solution for java 8 is not going to work. Thanks for the help