Understood, I did not know your level of expertise. You probably already know this, but a simple way to accomplish this (limited threads) is a bounded thread pool processing a central task queue.
When the count of items in a sender queue goes from 0 to 1, a task is inserted in the central task queue (and the worker thread(s) are notified when a task enters the task queue). The task is run by a worker thread and will drain the sender queue encapsulated in the task. Note that the queue can still be filled, so it must be thread safe. Specifically, a mutex must be held during insertion and the check for the 0 to 1 transition. The same mutex must be held during de-queue by the worker thread and its check for the 1 to 0 transition (in which case the task terminates and the worker thread goes back to servicing the next task). That is the general idea, and you probably already know this :) In any case, I have used this basic method many times in the past with very good results. Good luck, Jason On Thu, 2009-05-07 at 10:47 -0500, none none wrote: > Thank you Jason, > > The solution you mention is what I have implemented until now, but as you > said it can be inadequate if thread count matters. > > Unfortunately the system have hundreds of senders, and that means hundreds > of threads, so that is the reason I'm searching for an alternative. > > Currently working on a design to address this, but wanted to know if SNMP4J > already have some mechanism for this kind of situation. > > > > > > On Thu, May 7, 2009 at 5:15 AM, Jason Jeffords > <[email protected]>wrote: > > > When a trap is received, read it immediately and place it in a > > thread safe queue for that sender (i.e. have 1 queue per sender). > > > > Then, have one worker thread per sender queue (if you are not > > worried about thread counts) that blocks waiting on queue insertions. > > > > This will allow you to have multi-threaded and ordered processing of > > traps from each sender. > > > > Jason > > > > On Wed, 2009-05-06 at 11:15 -0500, none none wrote: > > > Hello, > > > > > > I need to create an application that receive and process SNMP v1 traps > > from > > > multiple senders. > > > > > > As there are multiple senders, it seems convenient to use multiple > > threads > > > (maybe a thread pool?) to process the traps. > > > > > > But the hard part is: > > > For each sender, the application must process the traps strictly in the > > > order they were received. > > > > > > For example, if the application receives the traps A, B, C, D from a > > > particular sender, then the application must process first A, then B, > > then C > > > and finally D. > > > > > > It would be great if someone can give any suggestions to do that? > > > > > > Thank you > > > _______________________________________________ > > > SNMP4J mailing list > > > [email protected] > > > http://lists.agentpp.org/mailman/listinfo/snmp4j > > > > > _______________________________________________ > SNMP4J mailing list > [email protected] > http://lists.agentpp.org/mailman/listinfo/snmp4j _______________________________________________ SNMP4J mailing list [email protected] http://lists.agentpp.org/mailman/listinfo/snmp4j
