Actor model pattern : Limiting number of concurrent running actors
I've designed an application based on the actor model pattern utilizing the spring application context events as the way to pass messages . I have three layers :
- issues a requesttransactionevent
- issues a dotransactionevent <-- should limit the current number of running transactions
- issues a donetransactionevent
layer 1 saves the request to the DB (for distributed arch. monitoring requirements) and issues the clientrequest layer 2 receives it and should check how many a dotransactionevents it has running (issued and not returned donetransaction) if it has a free slot it should issue a dotransaction and it is allso declared as the listener for the donetransactionevent .
what is the most elegant way to implement layer 2 without a synchronous method or something of that sort , the trick here is that it needs to pull the requestparameters saved by layer1 t开发者_C百科o the db for issuing a dotransactionevent .
You could treat the collection of dotransactionevents as a queue, and have a parallel set of queue handlers which each process an item at a time from the queue. By controlling the number of queue handlers you could control the number of running transactions, as you described.
精彩评论