private void scheduleUpdateJob( final Collection<String> filesToUpdate, final Collection<IResource> resourcesToUpdate) { if (!checkRepository()) return; if (reloadJob != null && reloadJobIsInitializing) return; if (updateJob != null) { updateJob.addChanges(filesToUpdate, resourcesToUpdate); return; } updateJob = new IndexDiffUpdateJob(getUpdateJobName(), 400) { @Override protected IStatus updateIndexDiff( Collection<String> files, Collection<IResource> resources, IProgressMonitor monitor) { waitForWorkspaceLock(monitor); if (monitor.isCanceled()) return Status.CANCEL_STATUS; lock.lock(); try { long startTime = System.currentTimeMillis(); IndexDiffData result = calcIndexDiffDataIncremental(monitor, getName(), files, resources); if (monitor.isCanceled() || (result == null)) return Status.CANCEL_STATUS; indexDiffData = result; if (GitTraceLocation.INDEXDIFFCACHE.isActive()) { long time = System.currentTimeMillis() - startTime; StringBuilder message = new StringBuilder( NLS.bind( "Updated IndexDiffData based on resource list (length = {0}) in {1} ms\n", //$NON-NLS-1$ Integer.valueOf(resources.size()), Long.valueOf(time))); GitTraceLocation.getTrace() .trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), message.append(indexDiffData.toString()).toString()); } notifyListeners(); return Status.OK_STATUS; } catch (IOException e) { if (GitTraceLocation.INDEXDIFFCACHE.isActive()) GitTraceLocation.getTrace() .trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), "Calculating IndexDiff failed", e); //$NON-NLS-1$ return Status.OK_STATUS; } finally { lock.unlock(); } } @Override public boolean belongsTo(Object family) { if (JobFamilies.INDEX_DIFF_CACHE_UPDATE.equals(family)) return true; return super.belongsTo(family); } }; updateJob.addChanges(filesToUpdate, resourcesToUpdate); }
private void scheduleReloadJob(final String trigger) { if (reloadJob != null) { if (reloadJobIsInitializing) return; reloadJob.cancel(); } if (updateJob != null) updateJob.cancel(); if (!checkRepository()) return; reloadJob = new Job(getReloadJobName()) { @Override protected IStatus run(IProgressMonitor monitor) { try { reloadJobIsInitializing = true; waitForWorkspaceLock(monitor); } finally { reloadJobIsInitializing = false; } lock.lock(); try { if (monitor.isCanceled()) return Status.CANCEL_STATUS; parallelism.acquire(); long startTime = System.currentTimeMillis(); IndexDiffData result = calcIndexDiffDataFull(monitor, getName()); if (monitor.isCanceled() || (result == null)) return Status.CANCEL_STATUS; indexDiffData = result; if (GitTraceLocation.INDEXDIFFCACHE.isActive()) { long time = System.currentTimeMillis() - startTime; StringBuilder message = new StringBuilder(getTraceMessage(time)); GitTraceLocation.getTrace() .trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), message.append(indexDiffData.toString()).toString()); } notifyListeners(); return Status.OK_STATUS; } catch (IOException e) { if (GitTraceLocation.INDEXDIFFCACHE.isActive()) GitTraceLocation.getTrace() .trace( GitTraceLocation.INDEXDIFFCACHE.getLocation(), "Calculating IndexDiff failed", e); //$NON-NLS-1$ return Status.OK_STATUS; } catch (InterruptedException e) { return Status.CANCEL_STATUS; } finally { lock.unlock(); parallelism.release(); } } private String getTraceMessage(long time) { return NLS.bind( "\nUpdated IndexDiffData in {0} ms\nReason: {1}\nRepository: {2}\n", //$NON-NLS-1$ new Object[] {Long.valueOf(time), trigger, repository.getWorkTree().getName()}); } @Override public boolean belongsTo(Object family) { if (JobFamilies.INDEX_DIFF_CACHE_UPDATE.equals(family)) return true; return super.belongsTo(family); } }; reloadJob.schedule(); }