mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
2004-05-06 Chris Wiebe
Creating a new Job to handle the changes, instead of reusing the same job.
This commit is contained in:
parent
c29caac4d0
commit
37c1ca7b3a
3 changed files with 43 additions and 37 deletions
|
@ -1,6 +1,10 @@
|
|||
2004-04-06 Chris Wiebe
|
||||
initial placement of non-ui code into org.eclipse.cdt.core.browser
|
||||
2004-05-06 Chris Wiebe
|
||||
Creating a new Job to handle the changes, instead
|
||||
of reusing the same job.
|
||||
|
||||
2004-04-20 Chris Wiebe
|
||||
refactored TypeCacheDeltaListener into standalone class
|
||||
added option in Work In Progress prefs page to disable background cache
|
||||
|
||||
2004-04-06 Chris Wiebe
|
||||
initial placement of non-ui code into org.eclipse.cdt.core.browser
|
|
@ -45,7 +45,7 @@ public class AllTypesCache {
|
|||
|
||||
private static final int INITIAL_DELAY= 5000;
|
||||
private static TypeCache fgCache;
|
||||
private static TypeCacherJob fgJob;
|
||||
private static IWorkingCopyProvider fWorkingCopyProvider;
|
||||
private static TypeCacheDeltaListener fgDeltaListener;
|
||||
private static IPropertyChangeListener fgPropertyChangeListener;
|
||||
private static boolean fBackgroundJobEnabled;
|
||||
|
@ -81,8 +81,8 @@ public class AllTypesCache {
|
|||
}
|
||||
|
||||
fgCache= new TypeCache();
|
||||
fgJob= new TypeCacherJob(fgCache, provider);
|
||||
fgDeltaListener= new TypeCacheDeltaListener(fgCache, fBackgroundJobEnabled, fgJob);
|
||||
fWorkingCopyProvider = provider;
|
||||
fgDeltaListener= new TypeCacheDeltaListener(fgCache, fWorkingCopyProvider, fBackgroundJobEnabled);
|
||||
|
||||
fgPropertyChangeListener= new IPropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
|
@ -102,17 +102,14 @@ public class AllTypesCache {
|
|||
// add property change listener
|
||||
prefs.addPropertyChangeListener(fgPropertyChangeListener);
|
||||
|
||||
if (fBackgroundJobEnabled) {
|
||||
TypeCacherJob typeCacherJob = new TypeCacherJob(fgCache, fWorkingCopyProvider);
|
||||
typeCacherJob.setSearchPaths(null);
|
||||
typeCacherJob.setPriority(Job.BUILD);
|
||||
typeCacherJob.schedule(INITIAL_DELAY);
|
||||
}
|
||||
// add delta listener
|
||||
CoreModel.getDefault().addElementChangedListener(fgDeltaListener);
|
||||
|
||||
if (fBackgroundJobEnabled) {
|
||||
// schedule job to run after INITIAL_DELAY
|
||||
if (fgJob.getState() != Job.RUNNING) {
|
||||
fgJob.setSearchPaths(null);
|
||||
fgJob.setPriority(Job.BUILD);
|
||||
fgJob.schedule(INITIAL_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,8 +119,9 @@ public class AllTypesCache {
|
|||
// remove delta listener
|
||||
CoreModel.getDefault().removeElementChangedListener(fgDeltaListener);
|
||||
|
||||
// terminate background job
|
||||
fgJob.cancel();
|
||||
// terminate all background jobs
|
||||
IJobManager jobMgr = Platform.getJobManager();
|
||||
jobMgr.cancel(TypeCacherJob.FAMILY);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -151,16 +149,23 @@ public class AllTypesCache {
|
|||
public static void getTypes(ICSearchScope scope, int[] kinds, IProgressMonitor monitor, Collection typesFound) {
|
||||
if (!isCacheUpToDate()) {
|
||||
// start job if not already running
|
||||
if (fgJob.getState() != Job.RUNNING) {
|
||||
IJobManager jobMgr = Platform.getJobManager();
|
||||
Job[] jobs = jobMgr.find(TypeCacherJob.FAMILY);
|
||||
if (jobs.length == 0) {
|
||||
// boost priority since action was user-initiated
|
||||
fgJob.setSearchPaths(null);
|
||||
fgJob.setPriority(Job.SHORT);
|
||||
fgJob.schedule();
|
||||
TypeCacherJob typeCacherJob = new TypeCacherJob(fgCache, fWorkingCopyProvider);
|
||||
typeCacherJob.setSearchPaths(null);
|
||||
typeCacherJob.setPriority(Job.SHORT);
|
||||
typeCacherJob.schedule();
|
||||
}
|
||||
|
||||
// wait for job to finish
|
||||
jobs = jobMgr.find(TypeCacherJob.FAMILY);
|
||||
try {
|
||||
fgJob.join(monitor);
|
||||
for (int i = 0; i < jobs.length; ++i) {
|
||||
TypeCacherJob job = (TypeCacherJob) jobs[i];
|
||||
job.join(monitor);
|
||||
}
|
||||
if (monitor != null)
|
||||
monitor.done();
|
||||
} catch (InterruptedException ex) {
|
||||
|
|
|
@ -10,11 +10,14 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.browser.AllTypesCache.IWorkingCopyProvider;
|
||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.jobs.IJobManager;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
|
||||
|
@ -26,15 +29,15 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
public class TypeCacheDeltaListener implements IElementChangedListener {
|
||||
|
||||
private TypeCache fTypeCache;
|
||||
private TypeCacherJob fTypeCacherJob;
|
||||
private IWorkingCopyProvider fWorkingCopyProvider;
|
||||
private Set fPaths= new HashSet(5);
|
||||
private Set fPrefixes= new HashSet(5);
|
||||
private boolean fFlushAll= false;
|
||||
private boolean fCreateBackgroundJob= true;
|
||||
|
||||
public TypeCacheDeltaListener(TypeCache cache, boolean createBackgroundJob, TypeCacherJob job) {
|
||||
public TypeCacheDeltaListener(TypeCache cache, IWorkingCopyProvider workingCopyProvider, boolean createBackgroundJob) {
|
||||
fTypeCache= cache;
|
||||
fTypeCacherJob= job;
|
||||
fWorkingCopyProvider = workingCopyProvider;
|
||||
fCreateBackgroundJob= createBackgroundJob;
|
||||
}
|
||||
|
||||
|
@ -53,32 +56,26 @@ public class TypeCacheDeltaListener implements IElementChangedListener {
|
|||
boolean needsFlushing= processDelta(event.getDelta());
|
||||
if (needsFlushing) {
|
||||
// cancel background job
|
||||
if (fTypeCacherJob.getState() == Job.RUNNING) {
|
||||
// wait for job to finish?
|
||||
try {
|
||||
fTypeCacherJob.cancel();
|
||||
fTypeCacherJob.join();
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
IJobManager jobMgr = Platform.getJobManager();
|
||||
jobMgr.cancel(TypeCacherJob.FAMILY);
|
||||
TypeCacherJob typeCacherJob = new TypeCacherJob(fTypeCache, fWorkingCopyProvider);
|
||||
if (fFlushAll) {
|
||||
// flush the entire cache
|
||||
fTypeCacherJob.setSearchPaths(null);
|
||||
typeCacherJob.setSearchPaths(null);
|
||||
fTypeCache.flushAll();
|
||||
} else {
|
||||
// flush affected files from cache
|
||||
Set searchPaths= new HashSet(10);
|
||||
getPrefixMatches(fPrefixes, searchPaths);
|
||||
searchPaths.addAll(fPaths);
|
||||
fTypeCacherJob.setSearchPaths(searchPaths);
|
||||
typeCacherJob.setSearchPaths(searchPaths);
|
||||
fTypeCache.flush(searchPaths);
|
||||
}
|
||||
|
||||
// restart the background job
|
||||
if (fCreateBackgroundJob) {
|
||||
fTypeCacherJob.setPriority(Job.BUILD);
|
||||
fTypeCacherJob.schedule();
|
||||
typeCacherJob.setPriority(Job.BUILD);
|
||||
typeCacherJob.schedule();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue