0

I want to write a CommunicationSupervisor for connection to a device with these features.

  1. Outgoing messages should be queued in a data structure.
  2. There is just one Consumer. Consumer should check if there is an element in queue.
  3. Consumer should send the outgoing message and wait for an incoming response.
  4. 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
  5. 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

Govan
  • 2,079
  • 4
  • 31
  • 53
  • This question seems primarily opinion based, which is not a question for SO. Please refer [How to ask](https://stackoverflow.com/help/how-to-ask) – Neijwiert May 07 '18 at 07:59
  • Point 4 is unclear. Do you mean "they will not be handled by _that consumer_ until it gets a response" or "they will not be handled by _any consumer_ until the _previous consumer_ gets a response"? That very strongly determines the choice of the data structure. – Piotr Wilkin May 07 '18 at 08:45
  • Yes @PiotrWilkin It is unclear. I should mention that there is just one cosumer. And Consumer is handling just one element at time. – Govan May 07 '18 at 08:50
  • @Neijwiert I don't think it is opinion based. It is a concrete problem and I wonder if there is a pattern for implementing such situation. – Govan May 07 '18 at 08:52
  • 1
    Then, if you were using Java 7, I'd consider using https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html, but I have no idea what's a reasonable replacement in Java 6. – Piotr Wilkin May 07 '18 at 10:21

0 Answers0