Implementing iteration in a process model

I would like to take your help to come up with the best way of implementing iteration in a process model.

Let us take an example:

An agent might send a list of applications to be processed. We would need to instantiate a process model which will process the applications. We’ve a flow service, lets say, ‘createApplication’ that can interact with webSphere EJB to create one application at a time. Therefore, either in the model or in a flow service, I need to loop through the input applications and invoke ‘createApplication’ multiple times. I can go forward with the next step in the process only if all the applications are created.
Could you please suggest the best way of doing it. The problem comes when first few applications are created and then server crashes or the service throws an exception because of EJB unavailability(webSphere going down). How can we resume with the non-processed applications?

Service resubmit starts with all the applications again. I’m afraid checkpoint services would be of costly in terms of performance and I’m worried about repository corruption if something goes wrong.

Best Regards
Sivaraj Lenin

I would say that you should implement the logic of iterating over the applications in your flow service. However, I don’t quite understand your ‘createApplication’ service… does it only creates or does it sends the application out too (I am assuming application to be some kind of a message here)? If the createApplication sends the application out- then yes, you should reprocess the applications already out, but otherwise, there shouldn’t be a problem in re doing the applications from the begining.

Anyway… here’s an example that I am gonna use to explain how I would achieve the ‘resume from last processed’.

Let’s say my service (createApplication) is ‘applyInterest’ that applies month-end interest to the saving bank accounts. It get’s the account record of the account holders from the database, ordered by account number and loops over them. Based on the data of each account record, the service calculates the interest and posts it to the account (updates the database). In this scenario, I could use the startTransaction, commitTransaction and rollbackTransaction services to achieve that the interest gets applied to all the accounts or none, but I do not know how feasible is it in your case, so I would go to the alternative -

My service does the following:

  1. Register a repo store and tries to retrieve a value against key ‘AccountNumber’.
  2. If the value is null, form a query ‘Select AccNo, X,Y,Z… order by AccNo’, else form a query ‘Select AccNo, X, Y, X from Table Where AccNo>=AccountNumber (fetched from repo) order by AccNo’
  3. Execute the query.
  4. Loop over the result set.
  5. Save (overwrite) the AccNo from result into the repo (
  6. Process the record - ie calculate the interest and apply it to the account.

This way, even if your service fails while processing an account and you resubmit the step from WmMonitor, it should resume after the last account successfully processed. Of course, if your server crashes after you have processed one and before saving the next AccNo in the store, there still can be duplicate processing. I do not kow if this is doable in your scenario - but its just an approach. Also, there might be a lot of ifs and buts, which will need to be answered based on your business case.

Hope this helps. Rohit