I am coding a Java EE application that provides REST services via JAX-RS resource classes, the application makes extensive use of CDI. My resource classes are @RequestScoped, the application returns HTTP Status 202 Accepted to the caller and executes the work asynchronously.
I would like to return a "process ID" so the caller can periodically request the overall status of the long running "process" that I am executing on their behalf.
While processing these requests my application also interacts asynchronously with other systems via REST by supplying a "callback URL" that these remote servers POST back (along with results and status) to my application when the assigned task is complete.
I am looking for a way for all the beans involved in the execution of a "process" to share a common status for that "process id". My initial thought was to inject a status bean with a new @ProcessScoped CDI scope to form a common bean pool for any given process.
The crux of my problem is where to store these beans and how to group them? It seems like a chicken and egg situation because CDI is going to need to know the process id for any given bean in order to pool them together.
I have read articles on how CDI does this for it's standard scopes; and I have looked at sample code for creating custom CDI scopes. For example, @SessionContext uses the HttpSession from the Servlet specification to store the bean instances. Because our "process" is somewhat arbitrary, I am struggling to come up with something that is common that I can use to index or store these beans.
Ideally the @ProcessScope would work transparently to the application code, i.e. the process id can be queried but is created and maintained by the CDI extension alone.
Thanks for any help or advice or inspiration you can offer.