I have two ideas to support single producer and multiple consumers.
The objective is that whichever consumer gets the data, processes it ( removes the element) and other consumers pick from next available element.
There are the options that I have now:
1. Create a consumer interface. Have all the consumers register themselves to the queue. Use observer pattern to propagate message availability signaled by producer.
2. Create a consumer interface, all consumers register themselves to the queue. Use a thread pool with task to dequeue elements. All threads in the pool will take turn to dequeue elements, each thread representing a consumer.
There is one contention in the dequeue method, I am using lock which will be used by only one thread at a time. If I have to speed up the process, I will have to think of bringing real concurrency to this process.
I am engaged is some other task right now. But I will get on with trying both these approaches once I am free.
Updated the Main class to support multiple consumers.
Here is the idea I have right now:
1. I will have a list of consumers.
2. I will pass this list to EventHandler.
3. Inside EventHandler, I will created thread pool equal to the size of consumer list.
4. Whenever eventhandler finds an elements in the queue, next available consumer thread will pass this element to the consumer.
5. I will update the next available consumer reference.