You already have the ConcurrentHashMap iDAndStatus
, which stores the identifier and the latest status. However, I would only allow the thread associated with the service to create a new record on this map.
When a message comes from the feed, if the identifier already exists in iDAndStatus
, it simply changes the status. If the key does not exist, simply temporarily store the ID / status updates in another data structure, pendingFeedUpdates
.
Each time a new entry is created in iDAndStatus
, check pendingFeedUpdates
to see if there are any updates for the new identifier.
I'm not sure which synchronized data structure to use for pendingFeedUpdates
: you need to get by ID, but you can have many messages for each identifier, and you want to keep the message order. Maybe a synchronized HashMap that associates each ID with some type of ordered ordered queue?
toto2 source share