Package org.eclipse.core.runtime.jobs

Examples of org.eclipse.core.runtime.jobs.Job


   */
  public void finish() {

    /* Run Retention since settings changed */
    if (fSettingsChanged) {
      Job retentionJob = new Job(Messages.RetentionPropertyPage_PERFORMING_CLEANUP) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
          try {
            Set<IBookMark> bookmarks = new HashSet<IBookMark>();
            for (IEntity entity : fEntities) {
              if (entity instanceof IBookMark)
                bookmarks.add((IBookMark) entity);
              else if (entity instanceof IFolder)
                CoreUtils.fillBookMarks(bookmarks, Collections.singleton((IFolder) entity));
            }

            monitor.beginTask(Messages.RetentionPropertyPage_PERFORMING_CLEANUP, bookmarks.size());

            for (IBookMark bookmark : bookmarks) {
              if (Controller.getDefault().isShuttingDown() || monitor.isCanceled())
                break;

              monitor.subTask(bookmark.getName());
              RetentionStrategy.process(bookmark);
              monitor.worked(1);
            }
          } finally {
            monitor.done();
          }

          return Status.OK_STATUS;
        }
      };

      retentionJob.schedule();
    }
  }
View Full Code Here


   * @param delay
   * @param runnable
   */
  public static void runInBackgroundThread(int delay, final Runnable runnable) {
    Assert.isNotNull(runnable);
    Job job = new Job("Job Runner") { //$NON-NLS-1$
      @Override
      public IStatus run(IProgressMonitor monitor) {
        runnable.run();
        return Status.OK_STATUS;
      }
    };

    job.setSystem(true);
    job.setUser(false);
    job.schedule(delay);
  }
View Full Code Here

    fTotalWork.set(tasks.size());
    final long start = System.currentTimeMillis();

    /* Start a new Job for each free Slot */
    for (int i = fRunningJobs.get(); i < fMaxConcurrentJobs && tasks.peek() != null; i++) {
      Job job = new Job("") { //$NON-NLS-1$
        @Override
        protected IStatus run(IProgressMonitor monitor) {
          final ITask task = tasks.poll();

          /* Perform the Operation if not yet Canceld */
          try {
            task.run(monitor);
          } catch (Exception e) {
            /* Ignore */
          }

          /* Inform about cancelation if present */
          return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
          return family == TestJobQueue.this;
        }
      };

      /* Listen to Job's Lifecycle */
      job.addJobChangeListener(new JobChangeAdapter() {

        /* Count the number of running Jobs for the Rule */
        @Override
        public void running(IJobChangeEvent event) {
          fRunningJobs.incrementAndGet();
        }

        /* Update Fields when a Job is Done */
        @Override
        public void done(IJobChangeEvent event) {
          fRunningJobs.decrementAndGet();
          fDone.incrementAndGet();

          if (fDone.get() == fTotalWork.get())
            fDuration.set(System.currentTimeMillis() - start);

          /* Re-Schedule this Job if there is work left to do */
          if (tasks.peek() != null)
            event.getJob().schedule();
        }
      });

      /* Apply the internal Rule */
      job.setSystem(true);
      job.schedule();
    }
  }
View Full Code Here

        fScheduledJobs.decrementAndGet();
        break;
      }

      /* Create the Job */
      Job job = createJob();

      /* Listen to Job's Lifecycle */
      job.addJobChangeListener(new JobChangeAdapter() {

        /* Update Fields when a Job is Done */
        @Override
        public void done(IJobChangeEvent event) {

          /* Re-Schedule this Job if there is work left to do */
          if (!fOpenTasksQueue.isEmpty())
            event.getJob().schedule();
          else
            fScheduledJobs.decrementAndGet();
        }
      });

      /* Do not interrupt on any Error */
      job.setProperty(NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE);

      /*
       * Workaround: Since we are using our own Job for displaying Progress, we
       * don't want these Jobs show up in the Progress View. There is currently
       * no bug-free solution of aggregating the Progress of N Jobs into a
       * single Monitor.
       */
      job.setSystem(true);

      /* Schedule it immediately */
      job.schedule();
    }
  }
View Full Code Here

    }
  }

  /* Create a Job for a Task to handle */
  private Job createJob() {
    Job job = new Job("") { //$NON-NLS-1$
      @Override
      protected IStatus run(final IProgressMonitor monitor) {

        /* Poll the next Task */
        final ITask task = fOpenTasksQueue.poll();
View Full Code Here

    fListeners.remove(listener);
  }

  /* Creates the Job for displaying Progress while Tasks are processed */
  private Job createProgressJob() {
    return new Job(fName) {
      private int fLastWorkDone = -1;
      private String fLastTask;

      @Override
      protected IStatus run(IProgressMonitor monitor) {
View Full Code Here

  }

  private void listen() {

    /* Create a Job to listen for Requests */
    fServerJob = new Job("Local News Viewer Server") { //$NON-NLS-1$
      @Override
      protected IStatus run(IProgressMonitor monitor) {

        /* Listen as long not canceled */
        while (!monitor.isCanceled()) {
View Full Code Here

   */
  public void finish() {

    /* Run Retention since settings changed */
    if (fSettingsChanged) {
      Job retentionJob = new Job("Performing clean-up...") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
          try {
            monitor.beginTask("Performing clean-up...", fEntities.size());

            for (IEntity entity : fEntities) {
              if (entity instanceof IBookMark)
                RetentionStrategy.process((IBookMark) entity);
              else if (entity instanceof IFolder)
                RetentionStrategy.process((IFolder) entity);

              monitor.worked(1);
            }
          } finally {
            monitor.done();
          }

          return Status.OK_STATUS;
        }
      };

      retentionJob.schedule();
    }
  }
View Full Code Here

  }

  private void listen() {

    /* Create a Job to listen for Requests */
    fServerJob = new Job("Local News Viewer Server") { //$NON-NLS-1$
      @Override
      protected IStatus run(IProgressMonitor monitor) {

        /* Listen as long not canceled */
        while (!monitor.isCanceled()) {
View Full Code Here

   * @param delay
   * @param runnable
   */
  public static void runInBackgroundThread(int delay, final Runnable runnable) {
    Assert.isNotNull(runnable);
    Job job = new Job("") { //$NON-NLS-1$
      @Override
      public IStatus run(IProgressMonitor monitor) {
        runnable.run();
        return Status.OK_STATUS;
      }
    };

    job.setSystem(true);
    job.setUser(false);
    job.schedule(delay);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.jobs.Job

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.