/** * Called when document changes. Marks the document dirty and schedules the parsing job. * * <p>When we return from here this.isDirty must remain true until new parseJob has finished. * * <p>If the previous parseJob is not cancelled immediately (parseJob.cancel() returns false) a * smarter way to calculate the next scheduling delay could be used. However we should not spend * much time in documentChanged() */ public void documentChanged(DocumentEvent event) { // set isDirty true and prevent possibly running parseJob from // changing it back to false // order of acquire, cancel and setDirty matters! try { lock.acquire(); parseJob.cancel(); this.setDirty(true); } finally { lock.release(); } // if parseJob was running, now it is either cancelled or it will // be before it tries setDirty(false) // inform outline that model is dirty TexOutlinePage outline = editor.getOutlinePage(); if (outline != null) { editor.getOutlinePage().modelGotDirty(); } TexOutlineTreeView fullOutline = editor.getFullOutline(); if (fullOutline != null) { fullOutline.modelGotDirty(); } // reschedule parsing with delay if (autoParseEnabled) { parseJob.schedule(parseDelay); } }
public static SymfonyDbFactory getInstance() { if (instance == null) { try { instanceLock.acquire(); instance = new SymfonyDbFactory(); /* * Explicitly register shutdown handler, so it * would be disposed only if class was loaded. * * We don't want static initialization code to * be executed during framework shutdown. */ SymfonyIndex.addShutdownListener( new IShutdownListener() { public void shutdown() { if (instance != null) { try { instance.dispose(); } catch (SQLException e) { Logger.logException(e); } instance = null; } } }); } catch (Exception e) { Logger.logException(e); } finally { instanceLock.release(); } } return instance; }
/** * This is run by the job scheduler. A list of subscribers will be refreshed, errors will not stop * the job and it will continue to refresh the other subscribers. */ @Override public IStatus run(IProgressMonitor monitor) { // Perform a pre-check for auto-build or manual build jobs // when auto-refreshing if (shouldReschedule() && (isJobInFamilyRunning(ResourcesPlugin.FAMILY_AUTO_BUILD) || isJobInFamilyRunning(ResourcesPlugin.FAMILY_MANUAL_BUILD))) { return POSTPONED; } // Only allow one refresh job at a time // NOTE: It would be cleaner if this was done by a scheduling // rule but at the time of writing, it is not possible due to // the scheduling rule containment rules. // Acquiring lock to ensure only one refresh job is running at a particular time boolean acquired = false; try { while (!acquired) { try { acquired = lock.acquire(1000); } catch (InterruptedException e1) { acquired = false; } Policy.checkCanceled(monitor); } IChangeDescription changeDescription = createChangeDescription(); RefreshEvent event = new RefreshEvent( reschedule ? IRefreshEvent.SCHEDULED_REFRESH : IRefreshEvent.USER_REFRESH, participant, changeDescription); IStatus status = null; NonblockingProgressMonitor wrappedMonitor = null; try { event.setStartTime(System.currentTimeMillis()); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } // Pre-Notify notifyListeners(STARTED, event); // Perform the refresh monitor.setTaskName(getName()); wrappedMonitor = new NonblockingProgressMonitor(monitor, this); doRefresh(changeDescription, wrappedMonitor); // Prepare the results setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal())); } catch (OperationCanceledException e2) { if (monitor.isCanceled()) { // The refresh was canceled by the user status = Status.CANCEL_STATUS; } else { // The refresh was canceled due to a blockage or a canceled authentication if (wrappedMonitor != null && wrappedMonitor.wasBlocking()) { status = POSTPONED; } else { status = Status.CANCEL_STATUS; } } } catch (CoreException e) { // Determine the status to be returned and the GOTO action status = e.getStatus(); if (!isUser()) { // Use the GOTO action to show the error and return OK Object prop = getProperty(IProgressConstants.ACTION_PROPERTY); if (prop instanceof GotoActionWrapper) { GotoActionWrapper wrapper = (GotoActionWrapper) prop; wrapper.setStatus(e.getStatus()); status = new Status(IStatus.OK, TeamUIPlugin.ID, IStatus.OK, e.getStatus().getMessage(), e); } } if (!isUser() && status.getSeverity() == IStatus.ERROR) { // Never prompt for errors on non-user jobs setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE); } } finally { event.setStopTime(System.currentTimeMillis()); } // Post-Notify if (status == null) { status = calculateStatus(event); } event.setStatus(status); notifyListeners(DONE, event); if (event.getChangeDescription().getChangeCount() > 0) { if (participant instanceof AbstractSynchronizeParticipant) { AbstractSynchronizeParticipant asp = (AbstractSynchronizeParticipant) participant; asp.firePropertyChange( participant, ISynchronizeParticipant.P_CONTENT, null, event.getChangeDescription()); } } return event.getStatus(); } finally { if (acquired) lock.release(); monitor.done(); } }