It's all about the answers!

Ask a question

Synchronization problem with IBuildEngine


Rafael Rezende (431423) | asked Aug 08 '16, 9:13 a.m.
We are using the RTC Plain Client API to automatically generate Build Definitions (BD). In order to associate them to Build Engines (BE), we fetch the BE by name, add the BD and save it.
The exact snippet is as seen below:
    // Build Definition does not know which Build Engines are serving it. Instead, the correct Build Engine should be
    // fetched and the Build Definition added to it.
IBuildEngine engine = ClientFactory.getTeamBuildClient(teamRepository).getBuildEngine(buildEngineName, new NullProgressMonitor());
IBuildEngine engineCopy = (IBuildEngine) engine.getWorkingCopy();
engineCopy.getSupportedBuildDefinitions().add(definition);
engineCopy = ClientFactory.getTeamBuildClient(teamRepository).save(engineCopy, new NullProgressMonitor());
It works fine for a single or sequential executions. However, we run into trouble when executing this snippet in parallel:
    com.ibm.team.repository.common.TeamRepositoryException: CRJAZ0223I The following item has been changed by another operation:
    Input: com.ibm.team.build.internal.common.model.impl.BuildEngineImpl@32c5b5bf (stateId: [UUID _wRzqQFL9Eeavz4w4jk_eAA], itemId: [UUID _xw0rMNWkEeWkosAiU6sYog], origin: <unset>, immutable: true) (contextId: [UUID _CWw8QHUYEeOxidpm0Kiw-w], modified: 2016-07-26 08:54:10.148, workingCopy: <unset>) (mergePredecessor: null, workingCopyPredecessor: <unset>, workingCopyMergePredecessor: <unset>, predecessor: [UUID _uk6DkFL9Eeavz4w4jk_eAA]) (supportsCancellation: false, engineContactInterval: 0, useTeamScheduler: false, id: CI_Engine_Master_04, active: true, description: )
Current: com.ibm.team.build.internal.common.model.impl.BuildEngineImpl@1339f1c1 (stateId: [UUID _vuQRQFL9Eeavz4w4jk_eAA], itemId: [UUID _xw0rMNWkEeWkosAiU6sYog], origin: <unset>, immutable: true) (contextId: [UUID _CWw8QHUYEeOxidpm0Kiw-w], modified: 2016-07-26 08:54:06.42, workingCopy: <unset>) (mergePredecessor: null, workingCopyPredecessor: <unset>, workingCopyMergePredecessor: <unset>, predecessor: [UUID _uk6DkFL9Eeavz4w4jk_eAA]) (supportsCancellation: false, engineContactInterval: 0, useTeamScheduler: false, id: CI_Engine_Master_04, active: true, description: )
The snippet is executed in separate JVMs, so no Java synchronization feature seems to help.
Would anyone have a proposal to solve the issue?

The only one I can think of is to retry (n-bounded loop) fetching a new (hopefully updated) working copy and save again. Still, that sounds quite a workaround rather than a solution...

One answer



permanent link
sam detweiler (12.5k6189201) | answered Aug 08 '16, 10:25 a.m.
But that is the only choice.. the thing you are trying to update has changed..and the data model has some of the data in memory, and it must be refreshed..

you see the same behavior with all the data items

Comments
Rafael Rezende commented Aug 08 '16, 11:14 a.m.

I know that for Work Items there is an IWorkItemWorkingCopyManager available to refresh the state of the local copy. But I cannot find the equivalent for the Build Engine. Is there any?


sam detweiler commented Aug 08 '16, 11:25 a.m.

never seen one.


David Lafreniere commented Aug 08 '16, 3:14 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

I don't think there is one... perhaps try wrapping that code in a try/catch block (for a StaleDataException, which I think is what this is in this case) and re-try x number of times.


sam detweiler commented Aug 08 '16, 3:31 p.m.

I think you have to get a fresh working copy.

Your answer


Register or to post your answer.