Java Code Examples for org.eclipse.core.runtime.jobs.Job#getState()

The following examples show how to use org.eclipse.core.runtime.jobs.Job#getState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindBugsJob.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void cancelSimilarJobs(FindBugsJob job) {
    if (job.getResource() == null) {
        return;
    }
    Job[] jobs = Job.getJobManager().find(FindbugsPlugin.class);
    for (Job job2 : jobs) {
        if (job2 instanceof FindBugsJob
                && job.getResource().equals(((FindBugsJob) job2).getResource())) {
            if (job2.getState() != Job.RUNNING) {
                job2.cancel();
            }
        }
    }
}
 
Example 2
Source File: ThreadDumpingWatchdog.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
private static void dumpJob(StringBuilder sb, String linePrefix, Job job, Thread thread) {
  String status;
  switch (job.getState()) {
    case Job.RUNNING:
      status = "RUNNING";
      break;
    case Job.WAITING:
      status = "WAITING";
      break;
    case Job.SLEEPING:
      status = "SLEEPING";
      break;
    case Job.NONE:
      status = "NONE";
      break;
    default:
      status = "UNKNOWN(" + job.getState() + ")";
      break;
  }
  Object blockingJob = null;
  try {
    blockingJob = ReflectionUtil.invoke(Job.getJobManager(), "findBlockingJob",
        InternalJob.class, new Class<?>[] {InternalJob.class}, job);
  } catch (NoSuchMethodException | SecurityException | IllegalAccessException
      | IllegalArgumentException | InvocationTargetException ex) {
    System.err.println("Unable to fetch blocking-job: " + ex);
  }
  sb.append("\n").append(linePrefix);
  sb.append(
      String.format(
          "  %s%s{pri=%d%s%s%s%s} %s (%s)%s",
          status,
          (job.isBlocking() ? "<BLOCKING>" : ""),
          job.getPriority(),
          (job.isSystem() ? ",system" : ""),
          (job.isUser() ? ",user" : ""),
          (job.getRule() != null ? ",rule=" + job.getRule() : ""),
          (thread != null ? ",thr=" + thread : ""),
          job,
          job.getClass().getName(),
          (job.getJobGroup() != null ? " [group=" + job.getJobGroup() + "]" : "")));
  if (blockingJob != null) {
    sb.append("\n").append(linePrefix)
        .append(String.format("    - blocked by: %s (%s)", blockingJob, blockingJob.getClass()));
  }
}
 
Example 3
Source File: TexlipseBuilder.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
    * Build the project.
    * 
 * @see IncrementalProjectBuilder.build
 */
   @Override
protected IProject[] build(int kind, Map args,
        IProgressMonitor monitor) throws CoreException {

       final IProject project = getProject();
       final ProjectFileTracking fileTracking = new ProjectFileTracking(project);
       final OutputFileManager fileManager = new OutputFileManager(project, fileTracking);

       Object rebuild = TexlipseProperties.getSessionProperty(project,
               TexlipseProperties.FORCED_REBUILD);

       // Wait for all scheduled parser jobs, since they could change relevant
       // session properties
       for (Job parser : Job.getJobManager().find(TexDocumentModel.PARSER_FAMILY)) {
           int state = parser.getState();
           if (state == Job.WAITING || state == Job.SLEEPING) {
               // If waiting, run immediately
               parser.cancel();
               parser.schedule();
           }
           try {
               parser.join();
           } catch (InterruptedException e) {
           }
       }

       if (rebuild == null && fileManager.isUpToDate()) {
           return null;
       }

       BuilderRegistry.clearConsole();

       Object s = TexlipseProperties.getProjectProperty(project,
               TexlipseProperties.PARTIAL_BUILD_PROPERTY);
	if (s != null) {
		partialBuild(project, fileManager, monitor);
	} else {
		buildFile(project, null, fileManager, monitor);
	}

	TexlipseProperties.setSessionProperty(project,
	        TexlipseProperties.FORCED_REBUILD, null);

	return null;
}