当前位置: 首页>>代码示例>>Java>>正文


Java Semaphore.waitFor方法代码示例

本文整理汇总了Java中com.intellij.util.concurrency.Semaphore.waitFor方法的典型用法代码示例。如果您正苦于以下问题:Java Semaphore.waitFor方法的具体用法?Java Semaphore.waitFor怎么用?Java Semaphore.waitFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.util.concurrency.Semaphore的用法示例。


在下文中一共展示了Semaphore.waitFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: smartInvokeAndWait

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public static void smartInvokeAndWait(final Project p, final ModalityState state, final Runnable r) {
    if (isNoBackgroundMode() || ApplicationManager.getApplication().isDispatchThread()) {
        r.run();
    } else {
        final Semaphore semaphore = new Semaphore();
        semaphore.down();
        DumbService.getInstance(p).smartInvokeLater(() -> {
            try {
                r.run();
            } finally {
                semaphore.up();
            }
        }, state);
        semaphore.waitFor();
    }
}
 
开发者ID:seedstack,项目名称:intellij-plugin,代码行数:17,代码来源:NavigatorUtil.java

示例2: SvnCopiesRefreshManager

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public SvnCopiesRefreshManager(final SvnFileUrlMappingImpl mapping) {
  mySemaphore = new Semaphore();
  // svn mappings refresh inside also uses asynchronous pass -> we need to pass callback that will ping our "single-threaded" executor here
  myMappingCallback = new Runnable() {
    @Override
    public void run() {
      mySemaphore.up();
    }
  };
  myRequestsMerger = new RequestsMerger(new Runnable() {
    @Override
    public void run() {
      mySemaphore.down();
      mapping.realRefresh(myMappingCallback);
      mySemaphore.waitFor();
    }
  }, new Consumer<Runnable>() {
    public void consume(final Runnable runnable) {
      ApplicationManager.getApplication().executeOnPooledThread(runnable);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:SvnCopiesRefreshManager.java

示例3: compute

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public T compute() {
  final Semaphore semaphore = new Semaphore();
  semaphore.down();
  final AtomicReference<T> reference = new AtomicReference<T>();
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      try {
        reference.set(runImpl());
      }
      finally {
        semaphore.up();
      }
    }
  });
  semaphore.waitFor();
  return reference.get();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:BackgroundSynchronousInvisibleComputable.java

示例4: waitForCompletion

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public void waitForCompletion() {
  if (isStopped) return;

  if (ApplicationManager.getApplication().isUnitTestMode()) {
    synchronized (myQueue) {
      while (!myQueue.isEmpty()) {
        startProcessing(myQueue.poll());
      }
    }
    return;
  }

  final Semaphore semaphore = new Semaphore();
  semaphore.down();
  scheduleTask(new MavenProjectsProcessorTask() {
    public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator)
      throws MavenProcessCanceledException {
      semaphore.up();
    }
  });

  while (true) {
    if (isStopped || semaphore.waitFor(1000)) return;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:MavenProjectsProcessor.java

示例5: startAndWait

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public void startAndWait(final LineProcessEventListener listener) {
  final Semaphore semaphore = new Semaphore();
  semaphore.down();
  addListener(new LineProcessEventListener() {
    @Override
    public void onLineAvailable(final String s, final Key key) {
      listener.onLineAvailable(s, key);
    }

    @Override
    public void processTerminated(final int i) {
      listener.processTerminated(i);
      semaphore.up();
    }

    @Override
    public void startFailed(final Throwable throwable) {
      listener.startFailed(throwable);
      semaphore.up();
    }
  });
  start();
  semaphore.waitFor();
}
 
开发者ID:irengrig,项目名称:fossil4idea,代码行数:25,代码来源:FossilLineCommand.java

示例6: waitUntilRefreshed

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
@TestOnly
public void waitUntilRefreshed() {
  while (true) {
    final Semaphore semaphore = new Semaphore();
    synchronized (myLock) {
      if (!myRequestSubmitted && !myRequestRunning) {
        return;
      }

      if (!myRequestRunning) {
        myScheduler.submit(new MyRunnable());
      }

      semaphore.down();
      myWaitingUpdateCompletionSemaphores.add(semaphore);
    }
    if (!semaphore.waitFor(100*1000)) {
      LOG.error("Too long VCS update");
      return;
    }
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:23,代码来源:UpdateRequestsQueue.java

示例7: freeze

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public void freeze(@Nonnull String reason) {
  myUpdater.setIgnoreBackgroundOperation(true);
  Semaphore sem = new Semaphore();
  sem.down();

  invokeAfterUpdate(() -> {
    myUpdater.setIgnoreBackgroundOperation(false);
    myUpdater.pause();
    myFreezeName.set(reason);
    sem.up();
  }, InvokeAfterUpdateMode.SILENT_CALLBACK_POOLED, "", ModalityState.defaultModalityState());

  boolean free = false;
  while (!free) {
    ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
    if (pi != null) pi.checkCanceled();
    free = sem.waitFor(500);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:ChangeListManagerImpl.java

示例8: startThread

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
@Override
public Future<?> startThread(final ProgressIndicator progressIndicator, final Runnable runnable) {
  final Semaphore startSemaphore = new Semaphore();
  startSemaphore.down();
  Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(() -> {
    try {
      ApplicationManager.getApplication().runReadAction(() -> {
        startSemaphore.up();
        ProgressManager.checkCanceled();
        runnable.run();
      });
    } catch (ProcessCanceledException ignored) {
    }
  }, progressIndicator));
  startSemaphore.waitFor();
  return future;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:18,代码来源:CompletionThreading.java

示例9: synchronousBackground

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
private static void synchronousBackground(final Runnable runnable) throws InterruptedException {
  final Semaphore semaphore = new Semaphore();
  semaphore.down();
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      try {
        runnable.run();
      } finally {
        semaphore.up();
      }
    }
  });
  semaphore.waitFor();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:SvnAuthenticationTest.java

示例10: getValue

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
@Override
public Value getValue() {
  // the following code makes sense only if we do not use ObjectReference.enableCollection() / disableCollection()
  // to keep temporary objects
  if (Patches.IBM_JDK_DISABLE_COLLECTION_BUG) {
    final EvaluationContextImpl evalContext = myStoredEvaluationContext;
    if (evalContext != null && !evalContext.getSuspendContext().isResumed() &&
      myValue instanceof ObjectReference && VirtualMachineProxyImpl.isCollected((ObjectReference)myValue)) {

      final Semaphore semaphore = new Semaphore();
      semaphore.down();
      evalContext.getDebugProcess().getManagerThread().invoke(new SuspendContextCommandImpl(evalContext.getSuspendContext()) {
        @Override
        public void contextAction() throws Exception {
          // re-setting the context will cause value recalculation
          try {
            setContext(myStoredEvaluationContext);
          }
          finally {
            semaphore.up();
          }
        }

        @Override
        protected void commandCancelled() {
          semaphore.up();
        }
      });
      semaphore.waitFor();
    }
  }

  assertValueReady();
  return myValue; 
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:ValueDescriptorImpl.java

示例11: queueAndWaitTask

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public <V> V queueAndWaitTask(final Callable<V> task) throws Throwable {
  final Ref<V> resultRef = new Ref<V>();
  final Ref<Throwable> throwableRef = new Ref<Throwable>();

  final Semaphore taskSemaphore = new Semaphore();
  taskSemaphore.down();

  queueTask(new Runnable() {

    @Override
    public void run() {
      try {
        resultRef.set(task.call());
      }
      catch (Throwable e) {
        throwableRef.set(e);
        LOG.error(e);
      }
      finally {
        taskSemaphore.up();
      }
    }
  });

  taskSemaphore.waitFor();

  if (!throwableRef.isNull()) {
    throw throwableRef.get();
  }

  return resultRef.get();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:SequentialTaskExecutor.java

示例12: close

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
public static void close(final Process process) {
  final Semaphore outerSemaphore = new Semaphore();
  outerSemaphore.down();

  final Application application = ApplicationManager.getApplication();
  application.executeOnPooledThread(new Runnable() {
    public void run() {
      try {
        final Semaphore semaphore = new Semaphore();
        semaphore.down();

        final Runnable closeRunnable = new Runnable() {
          public void run() {
            try {
              closeProcessImpl(process);
            }
            finally {
              semaphore.up();
            }
          }
        };

        final Future<?> innerFuture = application.executeOnPooledThread(closeRunnable);
        semaphore.waitFor(ourAsynchronousWaitTimeout);
        if ( ! (innerFuture.isDone() || innerFuture.isCancelled())) {
          innerFuture.cancel(true); // will call interrupt()
        }
      }
      finally {
        outerSemaphore.up();
      }
    }
  });

  // just wait
  outerSemaphore.waitFor(ourSynchronousWaitTimeout);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:ProcessCloseUtil.java

示例13: runTasksQueue

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
private boolean runTasksQueue(final Queue<Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings>> tasksQueue) {
  final Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings> pair = tasksQueue.poll();
  if (pair == null) return true;

  final ProjectSystemId systemId = pair.first;
  final ExternalSystemTaskExecutionSettings executionSettings = pair.getSecond();

  final Semaphore targetDone = new Semaphore();
  targetDone.down();
  final Ref<Boolean> result = new Ref<Boolean>(false);
  ExternalSystemUtil.runTask(executionSettings, DefaultRunExecutor.EXECUTOR_ID, myProject, systemId,
                             new TaskCallback() {
                               @Override
                               public void onSuccess() {
                                 result.set(runTasksQueue(tasksQueue));
                                 targetDone.up();
                               }

                               @Override
                               public void onFailure() {
                                 targetDone.up();
                               }
                             },
                             ProgressExecutionMode.IN_BACKGROUND_ASYNC);
  targetDone.waitFor();
  return result.get();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ExternalSystemTaskActivator.java

示例14: synchronousBackground

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
private static void synchronousBackground(final Runnable runnable) throws InterruptedException {
  final Semaphore semaphore = new Semaphore();
  semaphore.down();
  ApplicationManager.getApplication().executeOnPooledThread((Runnable)() -> {
    try {
      runnable.run();
    } finally {
      semaphore.up();
    }
  });
  semaphore.waitFor();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:SvnAuthenticationTest.java

示例15: waitAndPump

import com.intellij.util.concurrency.Semaphore; //导入方法依赖的package包/类
private static void waitAndPump(Semaphore semaphore, int timeout) {
  final long limit = System.currentTimeMillis() + timeout;
  while (System.currentTimeMillis() < limit) {
    if (semaphore.waitFor(10)) return;
    UIUtil.dispatchAllInvocationEvents();
  }
  fail("Timeout");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PsiDocumentManagerImplTest.java


注:本文中的com.intellij.util.concurrency.Semaphore.waitFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。