p4java api requires double refresh to get a new changelist description

168 Views Asked by At

In my application, I have a part where I want to automatically request a Swarm review. To do that, I put a #review tag in changelist description and shelve the files (after that, the Swarm review number appears after the tag in the description). Everything works as it should, except that I need to double refresh the changelist after shelving to get an updated description and extract the review ID. If I use only one refresh, or don't refresh at all, the extracted description doesn't contain the review ID. What's more, it works well with a single refresh when debugging step-by-step, but not in real time.

client.shelveChangelist(changelist);
IChangelist cl = server.getChangelist(changelist.getId());
cl.refresh();
cl.refresh();
String description = cl.getDescription;

(In fact, the refresh is performed 3 times, as the getDescription() method is also invoked in the refresh() method). Do you have any idea why is it so? I tried digging deep into the methods, and looking for new threads, or synchronizing the code, but neither worked.

1

There are 1 best solutions below

0
On

This is a timing issue.

What happens on the server side: A trigger on your shelve command fires and it asynchronously calls Swarm to create a review. Your shelveChangelist() completes. Swarm now creates the review. Then Swarm updates the original changelist description.

Sleep for a second or two before you refresh. Of course, if Swarm is super-busy it may take a more than a second or two. Or if the Swarm site is down in may not happen at all.