I need to write my own version of a bounded queue. It must be thread safe. The consumption of this queue is based on a priority system, where a consumer makes a request for an object in the queue.
The queue can have many producers and many consumers. Consumers come and register their requests based on a certain criteria around the object. When an objects is put on the queue, the Consumers who register the request first should get priority to receive the object. If a consumer thread tries to get an object it has registered an interest in but that object is not there, then the consumer blocks until the producer puts the object in and notifies the consumer.
I have made my attempt below, but my implementation so far is just an ArrayBlockingQueue implementation. it doesn't cover the registering of types of objects.
https://stackoverflow.com/questions/40533143/single-producer-multiple-consumer-queue-contains-null
Do I need some sort of observer pattern?