Announcement Announcement Module
Collapse
No announcement yet.
Actor Model Pattern using applicationevents Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Actor Model Pattern using applicationevents

    Hi ,

    I'm trying to implement the actor model pattern (Somewhat mashed toghter with producer consumer) by using application events and threadpoolexecutors
    my main objective is to decouple each of the layers .
    my architecture is as follows :
    i have a war deployed that trough a rest API receives requests for business transactions , at any given moment there can be X number of transactions alive
    where X is configureable number , the actual execution must be asynchronous and each transaction must be in a different thread .
    the requests themselves are treated in a FIFO manner but there is some complexity to it as some requests must wait for other to complete before they can be processed but that does not mean other requests can't be processed , e.g. : don't process a withdrawal from account 2 if a deposit to account 2 was requested before it , so if i get hits for
    deposit(2)
    withdrawal(2)
    deposit(3)

    where the numbers are account numbers i want to process them in this order:
    deposit(2)
    deposit(3)
    withdrawal(2)

    i've built the architecture is this way :
    i have a rest api that gets the hits and writes them to the DB (distributed system that has to have the state in DB)and publishes
    a clientrequestevent in the application context
    i have singleton bean that is in charge of publishing the producer events and monitoring how many events he has sent (i.e. : he is in charge of limiting the number of concurrent processes and implementing the above logic)
    and i have a few other listeners each for an action (withdrawal deposit etc..) that listen to the events published by the latter and publish a done event.

    every thing works great everything is done is different threads and all flows great but i have
    a problem with the middle layer the one in charge of determing whether or not there is a free slot
    i don't want to have a synchronous method nor do i want to do some tricks around an atomiclong or something like that i would rather use some blockingqueue to publish the events but i can't find a nice way to determine when an event is done so i can put a new one back in .
    the biggest problem is that for requesting a new work i have to go the DB which is a heavy task , as this system should work under heavy load .
    i would like to somehow utilize a blockingqueue and a threadpool so that will take from a size bounded queue with threads the minute one slot is free

    what would be a good way to handle this ?
    thanks in advance
Working...
X