Synchronization problem with IBuildEngine
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:
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...
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.It works fine for a single or sequential executions. However, we run into trouble when executing this snippet in parallel:
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());
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: )The snippet is executed in separate JVMs, so no Java synchronization feature seems to help.
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: )
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
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
you see the same behavior with all the data items
Comments
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?
never seen one.
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.
I think you have to get a fresh working copy.