Java 类com.intellij.util.concurrency.QueueProcessor 实例源码

项目:intellij-ce-playground    文件:BackgroundTaskQueue.java   
public BackgroundTaskQueue(@Nullable final Project project, @NotNull String title, final Boolean forcedHeadlessMode) {
  myMonitor = Boolean.TRUE.equals(Boolean.getBoolean(ourMonitorFlag)) ? new BackgroundTasksMonitor(title) : new PlusMinus.Empty<String>();
  final boolean headless = forcedHeadlessMode != null ? forcedHeadlessMode : ApplicationManager.getApplication().isHeadlessEnvironment();

  final QueueProcessor.ThreadToUse threadToUse = headless ? QueueProcessor.ThreadToUse.POOLED : QueueProcessor.ThreadToUse.AWT;
  final PairConsumer<Pair<Task.Backgroundable, Getter<ProgressIndicator>>, Runnable> consumer
    = headless ? new BackgroundableHeadlessRunner() : new BackgroundableUnderProgressRunner(title, project, myMonitor);

  myProcessor = new QueueProcessor<Pair<Task.Backgroundable, Getter<ProgressIndicator>>>(consumer, true,
                                                                                         threadToUse, new Condition<Object>() {
      @Override public boolean value(Object o) {
        if (project == null) return ApplicationManager.getApplication().isDisposed();
        if (project.isDefault()) {
          return project.isDisposed();
        } else {
          return !ApplicationManager.getApplication().isUnitTestMode() && !project.isOpen() || project.isDisposed();
        }
      }
    });
}
项目:intellij-ce-playground    文件:GitRepositoryUpdater.java   
GitRepositoryUpdater(@NotNull GitRepository repository) {
  myRepository = repository;
  VirtualFile gitDir = repository.getGitDir();
  myWatchRequest = LocalFileSystem.getInstance().addRootToWatch(gitDir.getPath(), true);

  myRepositoryFiles = GitRepositoryFiles.getInstance(gitDir);
  DvcsUtil.visitVcsDirVfs(gitDir, GitRepositoryFiles.getSubDirRelativePaths());
  myHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsHeadsPath());
  myRemotesDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsRemotesPath());
  myTagsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsTagsPath());

  Project project = repository.getProject();
  myUpdateQueue = new QueueProcessor<Object>(new DvcsUtil.Updater(repository), project.getDisposed());
  if (!project.isDisposed()) {
    myMessageBusConnection = project.getMessageBus().connect();
    myMessageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, this);
  }
  else {
    myMessageBusConnection = null;
  }
}
项目:intellij-ce-playground    文件:HgRepositoryUpdater.java   
HgRepositoryUpdater(@NotNull final HgRepository repository) {
  VirtualFile hgDir = repository.getHgDir();
  myWatchRequest = LocalFileSystem.getInstance().addRootToWatch(hgDir.getPath(), true);
  myRepositoryFiles = HgRepositoryFiles.getInstance(hgDir);
  DvcsUtil.visitVcsDirVfs(hgDir, HgRepositoryFiles.getSubDirRelativePaths());

  myBranchHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getBranchHeadsDirPath());
  myMqDir = VcsUtil.getVirtualFile(myRepositoryFiles.getMQDirPath());

  Project project = repository.getProject();
  myUpdateQueue = new QueueProcessor<Object>(new DvcsUtil.Updater(repository), project.getDisposed());
  myUpdateConfigQueue = new QueueProcessor<Object>(new Consumer<Object>() {
    @Override
    public void consume(Object dummy) {
      repository.updateConfig();
    }
  }, project.getDisposed());
  if (!project.isDisposed()) {
    myMessageBusConnection = project.getMessageBus().connect();
    myMessageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, this);
  }
  else {
    myMessageBusConnection = null;
  }
}
项目:tools-idea    文件:BackgroundTaskQueue.java   
public BackgroundTaskQueue(@Nullable final Project project, @NotNull String title, final Boolean forcedHeadlessMode) {
  myMonitor = Boolean.TRUE.equals(Boolean.getBoolean(ourMonitorFlag)) ? new BackgroundTasksMonitor(title) : new PlusMinus.Empty<String>();
  final boolean headless = forcedHeadlessMode != null ? forcedHeadlessMode : ApplicationManager.getApplication().isHeadlessEnvironment();

  final QueueProcessor.ThreadToUse threadToUse = headless ? QueueProcessor.ThreadToUse.POOLED : QueueProcessor.ThreadToUse.AWT;
  final PairConsumer<Pair<Task.Backgroundable, Getter<ProgressIndicator>>, Runnable> consumer
    = headless ? new BackgroundableHeadlessRunner() : new BackgroundableUnderProgressRunner(title, project, myMonitor);

  myProcessor = new QueueProcessor<Pair<Task.Backgroundable, Getter<ProgressIndicator>>>(consumer, true,
                                                                                         threadToUse, new Condition<Object>() {
      @Override public boolean value(Object o) {
        if (project == null) return ApplicationManager.getApplication().isDisposed();
        if (project.isDefault()) {
          return project.isDisposed();
        } else {
          return !ApplicationManager.getApplication().isUnitTestMode() && !project.isOpen() || project.isDisposed();
        }
      }
    });
}
项目:tools-idea    文件:GitRepositoryUpdater.java   
GitRepositoryUpdater(@NotNull GitRepository repository) {
  VirtualFile gitDir = repository.getGitDir();
  myWatchRequest = LocalFileSystem.getInstance().addRootToWatch(gitDir.getPath(), true);

  myRepositoryFiles = GitRepositoryFiles.getInstance(gitDir);
  RepositoryUtil.visitVcsDirVfs(gitDir, GitRepositoryFiles.getSubDirRelativePaths());
  myHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsHeadsPath());
  myRemotesDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsRemotesPath());

  Project project = repository.getProject();
  myUpdateQueue = new QueueProcessor<Object>(new RepositoryUtil.Updater(repository), project.getDisposed());
  if (!project.isDisposed()) {
    myMessageBusConnection = project.getMessageBus().connect();
    myMessageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, this);
  }
  else {
    myMessageBusConnection = null;
  }
}
项目:tools-idea    文件:HgRepositoryUpdater.java   
HgRepositoryUpdater(@NotNull final HgRepository repository) {
  VirtualFile hgDir = repository.getHgDir();
  myWatchRequest = LocalFileSystem.getInstance().addRootToWatch(hgDir.getPath(), true);
  myRepositoryFiles = HgRepositoryFiles.getInstance(hgDir);
  RepositoryUtil.visitVcsDirVfs(hgDir, HgRepositoryFiles.getSubDirRelativePaths());

  myBranchHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getBranchHeadsDirPath());
  Project project = repository.getProject();
  myUpdateQueue = new QueueProcessor<Object>(new RepositoryUtil.Updater(repository), project.getDisposed());
  myUpdateConfigQueue = new QueueProcessor<Object>(new Consumer<Object>() {
    @Override
    public void consume(Object dummy) {
      repository.updateConfig();
    }
  }, project.getDisposed());
  if (!project.isDisposed()) {
    myMessageBusConnection = project.getMessageBus().connect();
    myMessageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, this);
  }
  else {
    myMessageBusConnection = null;
  }
}
项目:intellij-haxe    文件:HaxeDebugRunner.java   
public DebugProcess(@NotNull XDebugSession session,
                    Project project, Module module,
                    int port) throws IOException {
  super(session);
  mClassesWithStatics = new Vector<String>();
  mProject = project;
  mModule = module;
  mDeferredQueue =
    new LinkedList<Pair<debugger.Command, MessageListener>>();
  mListenerQueue = new LinkedList<MessageListener>();
  mServerSocket = new java.net.ServerSocket(port);
  mBreakpointHandlers = this.createBreakpointHandlers();
  mMap =
    new HashMap<XLineBreakpoint<XBreakpointProperties>, Integer>();

  mWriteQueue = QueueProcessor.createRunnableQueueProcessor(QueueProcessor.ThreadToUse.POOLED);
}
项目:lua-for-idea    文件:LuaPsiManager.java   
@Override
public void projectOpened() {
    work = new ArrayListSet<InferenceCapable>();
    inferenceQueueProcessor =
            new QueueProcessor<InferenceCapable>(new InferenceQueue(myProject), myProject.getDisposed(), false);



    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new Runnable() {
        @Override
        public void run() {
            DumbService.getInstance(myProject).runWhenSmart(new InitRunnable());
        }
    });
}
项目:intellij-ce-playground    文件:SequentialLimitedLifoExecutor.java   
public SequentialLimitedLifoExecutor(Disposable parentDisposable, int maxTasks,
                                     @NotNull ThrowableConsumer<Task, ? extends Throwable> loadProcess) {
  myMaxTasks = maxTasks;
  myLoadProcess = loadProcess;
  myLoader = new QueueProcessor<Task>(new DetailsLoadingTask());
  Disposer.register(parentDisposable, this);
}
项目:consulo-lua    文件:LuaPsiManager.java   
@Override
public void projectOpened() {
    work = new ArrayListSet<InferenceCapable>();
    inferenceQueueProcessor =
            new QueueProcessor<InferenceCapable>(new InferenceQueue(myProject), myProject.getDisposed(), false);



    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new Runnable() {
        @Override
        public void run() {
            DumbService.getInstance(myProject).runWhenSmart(new InitRunnable());
        }
    });
}
项目:consulo    文件:Alarm.java   
@Debugger.Insert
private void runSafely(@Nullable Runnable task) {
  try {
    if (!myDisposed && task != null) {
      QueueProcessor.runSafely(task);
    }
  }
  finally {
    // remove from the list after execution to be able for waitForAllExecuted() to wait for completion
    synchronized (LOCK) {
      myRequests.remove(this);
      myFuture = null;
    }
  }
}
项目:consulo    文件:SequentialLimitedLifoExecutor.java   
public SequentialLimitedLifoExecutor(Disposable parentDisposable, int maxTasks,
                                     @Nonnull ThrowableConsumer<Task, ? extends Throwable> loadProcess) {
  myMaxTasks = maxTasks;
  myLoadProcess = loadProcess;
  myLoader = new QueueProcessor<>(new DetailsLoadingTask());
  Disposer.register(parentDisposable, this);
}
项目:intellij-ce-playground    文件:Alarm.java   
@Override
public void run() {
  try {
    if (myDisposed) {
      return;
    }
    synchronized (LOCK) {
      if (myTask == null) {
        return;
      }
    }

    final Runnable scheduledTask = new Runnable() {
      @Override
      public void run() {
        final Runnable task;
        synchronized (LOCK) {
          task = myTask;
          if (task == null) return;
          myTask = null;

          myRequests.remove(Request.this);
          myFuture = null;
        }

        if (myThreadToUse == ThreadToUse.SWING_THREAD && !isEdt()) {
          //noinspection SSBasedInspection
          EdtInvocationManager.getInstance().invokeLater(new Runnable() {
            @Override
            public void run() {
              if (!myDisposed) {
                QueueProcessor.runSafely(task);
              }
            }
          });
        }
        else {
          QueueProcessor.runSafely(task);
        }
      }

      @Override
      public String toString() {
        return "ScheduledTask "+Request.this;
      }
    };

    if (myModalityState == null) {
      Future<?> future = myExecutorService.submit(scheduledTask);
      synchronized (LOCK) {
        myFuture = future;
      }
    }
    else {
      final Application app = ApplicationManager.getApplication();
      if (app == null) {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(scheduledTask);
      }
      else if (app.isDispatchThread() && app.getCurrentModalityState().equals(myModalityState)) {
        scheduledTask.run();
      }
      else {
        app.invokeLater(scheduledTask, myModalityState);
      }
    }
  }
  catch (Throwable e) {
    LOG.error(e);
  }
}
项目:consulo    文件:BackgroundTaskQueue.java   
public BackgroundTaskQueue(@Nullable Project project, @Nonnull String title) {
  myTitle = title;

  Condition disposeCondition = project != null ? project.getDisposed() : ApplicationManager.getApplication().getDisposed();
  myProcessor = new QueueProcessor<>(TaskData::consume, true, ThreadToUse.AWT, disposeCondition);
}