/*
  * (non-Javadoc)
  *
  * @see org.eclipse.ptp.rtsystem.IMonitoringSystem#stopEvents()
  */
 public void stopEvents() throws CoreException {
   DebugUtil.trace(
       DebugUtil.RTS_TRACING,
       "RTS {0}: stop events",
       getResourceManager().getConfiguration().getName()); // $NON-NLS-1$
   if (periodicMonitorJob != null) {
     periodicMonitorJob.cancel();
   }
   if (continousMonitorJob != null) {
     continousMonitorJob.cancel();
   }
   doStopEvents();
 }
Пример #2
0
  /** Stop background processing, and wait until the current job is completed before returning */
  public void shutdown() {

    if (VERBOSE) Util.verbose("Shutdown"); // $NON-NLS-1$

    disable();
    discardJobs(null); // will wait until current executing job has completed
    Thread thread = this.processingThread;
    try {
      if (thread != null) { // see http://bugs.eclipse.org/bugs/show_bug.cgi?id=31858
        synchronized (this) {
          this.processingThread =
              null; // mark the job manager as shutting down so that the thread will stop by itself
          notifyAll(); // ensure its awake so it can be shutdown
        }
        // in case processing thread is handling a job
        thread.join();
      }
      Job job = this.progressJob;
      if (job != null) {
        job.cancel();
        job.join();
      }
    } catch (InterruptedException e) {
      // ignore
    }
  }
Пример #3
0
  /**
   * Schedule (or postpone) the job to execute after a given delay. Any previous pending job is
   * canceled.
   */
  public final void reschedule(int delay) {
    final Job newJob =
        new Job(actualJob.getName() + " (Delayed)") {
          protected IStatus run(IProgressMonitor monitor) {
            synchronized (jobLock) {
              if (job == this) {
                actualJob.schedule();
                return Status.OK_STATUS;
              } else {
                return Status.CANCEL_STATUS;
              }
            }
          }
        };
    newJob.setPriority(Job.INTERACTIVE);

    // System jobs are not visible in the GUI. I leave it for now, it's quite
    // interesting to see auto update tasks in the jobs panel.
    //
    // newJob.setSystem(true);

    synchronized (jobLock) {
      /*
       * Cancel previous job, but start the new one regardless of the previous job's
       * running state.
       */
      if (job != null && job.getState() == Job.SLEEPING) {
        job.cancel();
      }

      job = newJob;
      job.schedule(delay);
    }
  }
Пример #4
0
 @Override
 public void dispose() {
   for (Job job : jobs) {
     job.cancel();
   }
   super.dispose();
 }
Пример #5
0
  /**
   * Throws away this preview: cancels any pending rendering jobs and disposes of image resources
   * etc
   */
  public void dispose() {
    disposeThumbnail();

    if (mJob != null) {
      mJob.cancel();
      mJob = null;
    }
  }
 void clearResults() {
   if (runningJob != null) {
     runningJob.cancel();
     runningJob = null;
   }
   searchResults.setText("", false, false); // $NON-NLS-1$
   getManagedForm().reflow(true);
 }
Пример #7
0
 private void stopJob() {
   job.cancel();
   try {
     job.join();
   } catch (InterruptedException e) {
     // shutting down, ok to ignore
   }
 }
 /*
  * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
  */
 public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
   synchronized (fJobLock) {
     if (fJob != null) {
       fJob.cancel();
       fJob = null;
     }
   }
 }
  private void doUpdateResults(
      String phrase, IContext excludeContext, StringBuffer buff, SearchHit[] hits) {
    if (runningJob != null) {
      runningJob.cancel();
    }
    this.phrase = phrase;
    buff.delete(0, buff.length());
    if (hits.length > 0) {
      buff.append("<form>"); // $NON-NLS-1$
      buff.append("<p><span color=\""); // $NON-NLS-1$
      buff.append(IFormColors.TITLE);
      buff.append("\">"); // $NON-NLS-1$
      buff.append(NLS.bind(Messages.SearchResultsPart_label, phrase));
      buff.append("</span></p>"); // $NON-NLS-1$
      resultSorter.sort(null, hits);
      IHelpResource[] excludedTopics =
          excludeContext != null ? excludeContext.getRelatedTopics() : null;

      for (int i = 0; i < hits.length; i++) {
        SearchHit hit = hits[i];
        if (hit.canOpen()) // Do not list Welcome/Cheatsheets etc.
        continue;
        if (isExcluded(hit.getHref(), excludedTopics)) continue;
        if (i == SHORT_COUNT) break;
        buff.append("<li indent=\"21\" style=\"image\" value=\""); // $NON-NLS-1$
        buff.append(IHelpUIConstants.IMAGE_FILE_F1TOPIC);
        buff.append("\">"); // $NON-NLS-1$
        buff.append("<a href=\""); // $NON-NLS-1$
        String href = hit.getHref();
        buff.append(href);
        buff.append("\""); // $NON-NLS-1$
        if (hit.getToc() != null && !Platform.getWS().equals(Platform.WS_GTK)) {
          buff.append(" alt=\""); // $NON-NLS-1$
          buff.append(EscapeUtils.escapeSpecialChars(hit.getToc().getLabel()));
          buff.append("\""); // $NON-NLS-1$
        }
        buff.append(">"); // $NON-NLS-1$
        buff.append(EscapeUtils.escapeSpecialChars(hit.getLabel()));
        buff.append("</a>"); // $NON-NLS-1$
        buff.append("</li>"); // $NON-NLS-1$
      }
      if (hits.length > 0) {
        buff.append("<p><img href=\""); // $NON-NLS-1$
        buff.append(IHelpUIConstants.IMAGE_HELP_SEARCH);
        buff.append("\"/>"); // $NON-NLS-1$
        buff.append(" <a href=\""); // $NON-NLS-1$
        buff.append(MORE_HREF);
        buff.append("\">"); // $NON-NLS-1$
        buff.append(Messages.SearchResultsPart_moreResults);
        buff.append("</a></p>"); // $NON-NLS-1$
      }
      buff.append("</form>"); // $NON-NLS-1$
      if (!searchResults.isDisposed()) searchResults.setText(buff.toString(), true, false);
    } else if (!searchResults.isDisposed())
      searchResults.setText(NLS.bind(Messages.SearchResultsPart_noHits, phrase), false, false);
    if (!searchResults.isDisposed()) getManagedForm().reflow(true);
  }
 /** @since 3.0 */
 public void terminateJob(String jobId) throws CoreException {
   DebugUtil.trace(
       DebugUtil.JOB_TRACING,
       "RTS {0}: terminate job #{1}",
       getResourceManager().getConfiguration().getName(),
       jobId); //$NON-NLS-1$
   Job job = jobs.get(jobId);
   pendingJobQueue.remove(job);
   job.cancel();
 }
 public void stop() {
   if (runBackup != null) {
     if (!runBackup.cancel()) {
       try {
         runBackup.join();
       } catch (InterruptedException e) {
         // ignore
       }
     }
     runBackup = null;
   }
 }
Пример #12
0
 /** Stop the download manager. */
 public void stop() {
   if (updateJob != null) {
     if (!updateJob.cancel()) {
       try {
         updateJob.join();
       } catch (InterruptedException e) {
         // TODO(pquitslund): sysout for debugging
         e.printStackTrace();
         // ignored since we're tearing down and there may be no log to write to!
       }
     }
   }
 }
Пример #13
0
 @Override
 public void dispose() {
   if (job != null) {
     if (job.getState() == Job.RUNNING) job.cancel();
     job = null;
   }
   getSite().getPage().removePartListener(editorListener);
   if (featureModelEditor != null) {
     featureModelEditor.getOriginalFeatureModel().removeListener(modelListener);
     featureModelEditor.getFeatureModel().removeListener(modelListener);
     featureModelEditor = null;
   }
   super.dispose();
 }
Пример #14
0
 /**
  * Request a new render after the given delay
  *
  * @param delay the delay to wait before starting the render job
  */
 public void render(long delay) {
   Job job = mJob;
   if (job != null) {
     job.cancel();
   }
   if (RENDER_ASYNC) {
     job = new AsyncRenderJob();
   } else {
     job = new RenderJob();
   }
   job.schedule(delay);
   job.addJobChangeListener(this);
   mJob = job;
 }
  /**
   * Schedule a background job for retrieving the AST and reconciling the Semantic Highlighting
   * model.
   */
  private void scheduleJob() {
    final DartElement element = fEditor.getInputDartElement();

    synchronized (fJobLock) {
      final Job oldJob = fJob;
      if (fJob != null) {
        fJob.cancel();
        fJob = null;
      }

      if (element != null) {
        fJob =
            new Job(DartEditorMessages.SemanticHighlighting_job) {
              @Override
              protected IStatus run(IProgressMonitor monitor) {
                if (oldJob != null) {
                  try {
                    oldJob.join();
                  } catch (InterruptedException e) {
                    DartToolsPlugin.log(e);
                    return Status.CANCEL_STATUS;
                  }
                }
                if (monitor.isCanceled()) {
                  return Status.CANCEL_STATUS;
                }
                DartUnit ast =
                    DartToolsPlugin.getDefault()
                        .getASTProvider()
                        .getAST(element, ASTProvider.WAIT_YES, monitor);
                reconciled(ast, false, monitor);
                synchronized (fJobLock) {
                  // allow the job to be gc'ed
                  if (fJob == this) {
                    fJob = null;
                  }
                }
                return Status.OK_STATUS;
              }
            };
        fJob.setSystem(true);
        fJob.setPriority(Job.DECORATE);
        fJob.schedule();
      }
    }
  }
Пример #16
0
  private void refresh() {
    if (job != null && job.getState() == Job.RUNNING) job.cancel();

    job =
        new Job("Updating Feature Model Edits") {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            if (featureModelEditor == null) contentProvider.defaultContent();
            else
              contentProvider.calculateContent(
                  featureModelEditor.getOriginalFeatureModel(),
                  featureModelEditor.getFeatureModel());
            return Status.OK_STATUS;
          }
        };
    job.setPriority(Job.LONG);
    job.schedule();
  }
Пример #17
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   synchronized (getClass()) {
     if (monitor.isCanceled()) {
       return Status.CANCEL_STATUS;
     }
     Job[] buildJobs = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD);
     for (int i = 0; i < buildJobs.length; i++) {
       Job curr = buildJobs[i];
       if (curr != this && curr instanceof BuildJob) {
         BuildJob job = (BuildJob) curr;
         if (job.isCoveredBy(this)) {
           curr.cancel(); // cancel all other build jobs of
           // our kind
         }
       }
     }
   }
   try {
     if (fProject != null) {
       monitor.beginTask(
           Messages.format(DLTKUIMessages.CoreUtility_buildproject_taskname, fProject.getName()),
           2);
       fProject.build(IncrementalProjectBuilder.FULL_BUILD, new SubProgressMonitor(monitor, 1));
       DLTKUIPlugin.getWorkspace()
           .build(
               IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, 1));
     } else {
       monitor.beginTask(DLTKUIMessages.CoreUtility_buildall_taskname, 2);
       DLTKUIPlugin.getWorkspace()
           .build(IncrementalProjectBuilder.FULL_BUILD, new SubProgressMonitor(monitor, 2));
     }
   } catch (CoreException e) {
     return e.getStatus();
   } catch (OperationCanceledException e) {
     return Status.CANCEL_STATUS;
   } finally {
     monitor.done();
   }
   return Status.OK_STATUS;
 }
Пример #18
0
 void scheduleSearch(Job job) {
   if (runningJob != null) {
     runningJob.cancel();
   }
   StringBuffer buff = new StringBuffer();
   buff.append("<form>"); // $NON-NLS-1$
   buff.append("<p><span color=\""); // $NON-NLS-1$
   buff.append(IFormColors.TITLE);
   buff.append("\">"); // $NON-NLS-1$
   buff.append(Messages.SearchResultsPart_progress);
   buff.append("</span>"); // $NON-NLS-1$
   buff.append("<a href=\""); // $NON-NLS-1$
   buff.append(CANCEL_HREF);
   buff.append("\">"); // $NON-NLS-1$
   buff.append(Messages.SearchResultsPart_cancel);
   buff.append("</a></p>"); // $NON-NLS-1$
   buff.append("</form>"); // $NON-NLS-1$
   searchResults.setText(buff.toString(), true, false);
   getManagedForm().reflow(true);
   runningJob = job;
   job.schedule();
 }
  /**
   * Schedule a background job for retrieving the AST and reconciling the Semantic Highlighting
   * model.
   */
  private void scheduleJob() {
    final ITypeRoot element = fEditor.getInputJavaElement();

    synchronized (fJobLock) {
      final Job oldJob = fJob;
      if (fJob != null) {
        fJob.cancel();
        fJob = null;
      }

      if (element != null) {
        fJob =
            new Job(JavaEditorMessages.SemanticHighlighting_job) {
              protected IStatus run(IProgressMonitor monitor) {
                if (oldJob != null) {
                  try {
                    oldJob.join();
                  } catch (InterruptedException e) {
                    JavaPlugin.log(e);
                    return Status.CANCEL_STATUS;
                  }
                }
                if (monitor.isCanceled()) return Status.CANCEL_STATUS;
                CompilationUnit ast =
                    SharedASTProvider.getAST(element, SharedASTProvider.WAIT_YES, monitor);
                reconciled(ast, false, monitor);
                synchronized (fJobLock) {
                  // allow the job to be gc'ed
                  if (fJob == this) fJob = null;
                }
                return Status.OK_STATUS;
              }
            };
        fJob.setSystem(true);
        fJob.setPriority(Job.DECORATE);
        fJob.schedule();
      }
    }
  }
Пример #20
0
 /** Update the receiver after the text has changed. */
 protected void textChanged() {
   // cancel currently running job first, to prevent unnecessary redraw
   refreshJob.cancel();
   refreshJob.schedule(200);
 }
Пример #21
0
  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();
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ptp.rtsystem.IRuntimeSystem#shutdown()
   */
  public void shutdown() throws CoreException {
    DebugUtil.trace(
        DebugUtil.RTS_TRACING,
        "RTS {0}: shutdown",
        getResourceManager().getConfiguration().getName()); // $NON-NLS-1$

    /*
     * Remove listener to avoid re-entry
     */
    if (connection != null) {
      connection.removeConnectionChangeListener(fConnectionChangeHandler);
    }

    try {
      stopEvents();
    } catch (CoreException e) {
      // Ignore exception and shutdown anyway
      RMCorePlugin.log(e);
    }

    try {
      doShutdown();
    } finally {

      /*
       * Stop jobs that might be in the pending queue. Also stop the
       * thread that dispatches pending jobs.
       */
      if (jobQueueThread != null) {
        jobQueueThread.interrupt();
        for (Job job : pendingJobQueue) {
          job.cancel();
        }
      }

      /*
       * Stop jobs that are running or that already finished.
       */
      Iterator<Job> iterator = jobs.values().iterator();
      while (iterator.hasNext()) {
        Job job = iterator.next();
        job.cancel();
        iterator.remove();
      }

      synchronized (this) {
        if (startupMonitor != null) {
          startupMonitor.setCanceled(true);
        }
      }

      /*
       * Close the the connection.
       */
      if (connection != null) {
        connection.close();
      }

      jobQueueThread = null;
      fireRuntimeShutdownStateEvent(eventFactory.newRuntimeShutdownStateEvent());
    }
  }
Пример #23
0
 public void stop() {
   if (runningJob != null) {
     runningJob.cancel();
     runningJob = null;
   }
 }
Пример #24
0
 public void refresh() {
   refreshJob.cancel();
   refreshJob.schedule(200);
 }