Commit 021a6321 authored by Snejana Bisa's avatar Snejana Bisa Committed by Balazs Grill
Browse files

Bug 570596 - Eliminate risk of deadlocks related to


ResourceProblemHandler

Fixed problem marker management by making delegation of handling of
loaded files to ResourceProblemMarkerService asynchronous, and
scheduling MarkerJob after requesting ResourceProblemMarkerService to
handle changed files.

Change-Id: I7286b364ed1356c7583715512337ab28e7a04613
Signed-off-by: default avatarSnejana Bisa <snejana_b@yahoo.com>
parent 9a7ad57d
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
 *     BMW Car IT - [374883] Improve handling of out-of-sync workspace files during descriptor initialization
 *     BMW Car IT - Avoid usage of Object.finalize
 *     itemis - [409014] Listener URIChangeDetector registered for all transactional editing domains
 *     Elektrobit - [570596] - Eliminate risk of deadlocks related to ResourceProblemHandler
 *
 * </copyright>
 */
@@ -52,6 +53,7 @@ import org.eclipse.sphinx.emf.util.EcorePlatformUtil;
import org.eclipse.sphinx.emf.util.WorkspaceEditingDomainUtil;
import org.eclipse.sphinx.platform.IExtendedPlatformConstants;
import org.eclipse.sphinx.platform.resources.DefaultResourceChangeHandler;
import org.eclipse.sphinx.platform.resources.MarkerJob;
import org.eclipse.sphinx.platform.resources.ResourceDeltaVisitor;
import org.eclipse.sphinx.platform.util.ExtendedPlatform;
import org.eclipse.sphinx.platform.util.PlatformLogUtil;
@@ -144,7 +146,39 @@ public class ResourceProblemHandler extends ResourceSetListenerImpl implements I
	}

	protected void handleLoadedResources(Collection<Resource> resources) {
		ResourceProblemMarkerService.INSTANCE.addProblemMarkers(resources, null);
		if (!resources.isEmpty()) {
			Job job = new Job(Messages.job_addingProblemMarkers) {
				@Override
				protected IStatus run(IProgressMonitor monitor) {
					try {
						ResourceProblemMarkerService.INSTANCE.addProblemMarkers(resources, monitor);
						return Status.OK_STATUS;
					} catch (OperationCanceledException ex) {
						return Status.CANCEL_STATUS;
					} catch (Exception ex) {
						return StatusUtil.createErrorStatus(Activator.getPlugin(), ex);
					}
				}

				@Override
				public boolean belongsTo(Object family) {
					return IExtendedPlatformConstants.FAMILY_LONG_RUNNING.equals(family);
				}
			};
			job.setPriority(Job.SHORT);
			job.setRule(ExtendedPlatform.createModifySchedulingRule(getFiles(resources)));
			job.setSystem(true);
			job.schedule();
		}
	}

	private Collection<IFile> getFiles(Collection<Resource> resources) {
		Collection<IFile> files = new ArrayList<>();
		for (Resource resource : resources) {
			IFile file = EcorePlatformUtil.getFile(resource);
			files.add(file);
		}
		return files;
	}

	/*
@@ -209,6 +243,7 @@ public class ResourceProblemHandler extends ResourceSetListenerImpl implements I
				protected IStatus run(IProgressMonitor monitor) {
					try {
						ResourceProblemMarkerService.INSTANCE.removeProblemMarkers(files, monitor);
						MarkerJob.INSTANCE.schedule();
						return Status.OK_STATUS;
					} catch (OperationCanceledException ex) {
						return Status.CANCEL_STATUS;