lundi 16 mai 2016

Best approach/algorithm for this scenario (Java code)

I have a java project, which acts as a middle ware to two other projects, lets call A and B.

A sends its output to my middleware project which does some processing for each incident that exists, and B consumes the output from my project, and displays each incident. The input/output is in the form of XML across all projects.

A only sends incidents which are currently open from prior connection, then goes on a live mode waiting for new incidents to come in.

The problem is let say if i stopped my project for a while and a few incidents were closed, and then i start my project again, A will only send the currently open ones, and B explicitly requires an input message to remove that incident from display, and if my middlware project was down, it will never receive that input.

My approach was to log all the incidents coming in a database from my project, and when it restarts, compare what comes from A with my database, and if i find any incidents which exists in database but didnt come from A, it means it was closed when my middleware project went down, so I would manually create that XML output and send it off to B to remove it from display.

However, the issue with this approach is, the socket to A is a live connection from my project, meaning first A on connection will dump all the previously open incidents, and then will be waiting live on the new ones. How would i know, at what time it has finished dumping the older ones, as the socket doesnt close, and theres no way of knowing when we connect to A, if the incident coming in belongs to the old dump, or a recently created incident.

Aucun commentaire:

Enregistrer un commentaire