• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Developing a queuing mechanism  RSS feed

 
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Still working out the details of point 4, 5.

Here is the Main with the consumer list:
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added class that will dispatch the event to consumer:


I just need to use a worker pool to connect this dispatcher to queue polling.

Here is an incomplete version of EventHandler with dispatcher:

 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some more update :




I am thinking of making list of available dispatchers. Once they are processing an event, I will remove them from this list. Once the task is done, I will add then again.

Does this look logically correct?
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last piece of puzzle:

EventHandler.java


Main.java



This is my design with a single producer and multiple consumer criterea.
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correction in EventHandler.java

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!