本文整理汇总了Java中com.intellij.util.concurrency.Semaphore类的典型用法代码示例。如果您正苦于以下问题:Java Semaphore类的具体用法?Java Semaphore怎么用?Java Semaphore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Semaphore类属于com.intellij.util.concurrency包,在下文中一共展示了Semaphore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: run
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
protected void run(final SR serverRuntime, final Semaphore semaphore, final AtomicReference<T> result) {
serverRuntime.getTaskExecutor().submit(new Runnable() {
@Override
public void run() {
try {
result.set(CloudRuntimeTask.this.run(serverRuntime));
mySuccess.set(true);
}
catch (ServerRuntimeException e) {
runtimeErrorOccurred(e.getMessage());
}
finally {
semaphore.up();
}
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:CloudRuntimeTask.java
示例3: waitForSemaphore
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
private int waitForSemaphore(final Semaphore semaphore) {
long timeoutMs = myTimeUnit.toMillis(myTimeout);
long lastActiveMoment = System.currentTimeMillis();
while (true) {
long current = System.currentTimeMillis();
if (myIsTouched) {
myIsTouched = false;
lastActiveMoment = current;
}
long idleTime = current - lastActiveMoment;
if (idleTime > timeoutMs) {
int retCode = processTimeoutInEDT();
return semaphore.waitFor(0) ? 0 : retCode;
}
ProgressManager.checkCanceled();
if (semaphore.waitFor(Math.min(500, timeoutMs - idleTime))) {
return 0;
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:InterruptibleActivity.java
示例4: waitForSmartMode
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
@Override
public void waitForSmartMode() {
if (!isDumb()) {
return;
}
final Application application = ApplicationManager.getApplication();
if (application.isReadAccessAllowed() || application.isDispatchThread()) {
throw new AssertionError("Don't invoke waitForSmartMode from inside read action in dumb mode");
}
final Semaphore semaphore = new Semaphore();
semaphore.down();
runWhenSmart(new Runnable() {
@Override
public void run() {
semaphore.up();
}
});
while (true) {
if (semaphore.waitFor(50)) {
return;
}
ProgressManager.checkCanceled();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:DumbServiceImpl.java
示例5: invokeAndWait
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
static void invokeAndWait(@NotNull final Runnable runnable, @NotNull ModalityState modalityState) {
LOG.assertTrue(!isDispatchThread());
final Semaphore semaphore = new Semaphore();
semaphore.down();
Runnable runnable1 = new Runnable() {
@Override
public void run() {
try {
runnable.run();
}
finally {
semaphore.up();
}
}
@Override
@NonNls
public String toString() {
return "InvokeAndWait[" + runnable + "]";
}
};
invokeLater(runnable1, modalityState);
semaphore.waitFor();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:LaterInvocator.java
示例6: 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
示例7: 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) {
myExecutor.get().schedule(new MyRunnable(), 0, TimeUnit.MILLISECONDS);
}
semaphore.down();
myWaitingUpdateCompletionSemaphores.add(semaphore);
}
if (!semaphore.waitFor(100*1000)) {
LOG.error("Too long VCS update");
return;
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:UpdateRequestsQueue.java
示例8: 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
示例9: 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(new Runnable() {
@Override
public void run() {
try {
r.run();
}
finally {
semaphore.up();
}
}
}, state);
semaphore.waitFor();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MavenUtil.java
示例10: waitForProcess
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
private void waitForProcess(Application application) {
myWaitSemaphore = new Semaphore();
myWaitSemaphore.down();
myWaitForThreadFuture = application.executeOnPooledThread(new Runnable() {
public void run() {
try {
myProcess.waitFor();
}
catch (InterruptedException ignored) {
}
finally {
myWaitSemaphore.up();
}
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ConnectionOnProcess.java
示例11: 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
示例12: 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
示例13: getValue
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
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 && myStoredEvaluationContext != null && !myStoredEvaluationContext.getSuspendContext().isResumed() &&
myValue instanceof ObjectReference && VirtualMachineProxyImpl.isCollected((ObjectReference)myValue)) {
final Semaphore semaphore = new Semaphore();
semaphore.down();
myStoredEvaluationContext.getDebugProcess().getManagerThread().invoke(new SuspendContextCommandImpl(myStoredEvaluationContext.getSuspendContext()) {
public void contextAction() throws Exception {
// re-setting the context will cause value recalculation
try {
setContext(myStoredEvaluationContext);
}
finally {
semaphore.up();
}
}
});
semaphore.waitFor();
}
return myValue;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:ValueDescriptorImpl.java
示例14: invokeAndWait
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
public static void invokeAndWait(@NotNull final Runnable runnable, @NotNull ModalityState modalityState) {
LOG.assertTrue(!isDispatchThread());
final Semaphore semaphore = new Semaphore();
semaphore.down();
Runnable runnable1 = new Runnable() {
@Override
public void run() {
try {
runnable.run();
}
finally {
semaphore.up();
}
}
@NonNls
public String toString() {
return "InvokeAndWait[" + runnable.toString() + "]";
}
};
invokeLater(runnable1, modalityState);
semaphore.waitFor();
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:LaterInvocator.java
示例15: waitUntilRefreshed
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
public void waitUntilRefreshed() {
while (true) {
final Semaphore semaphore = new Semaphore();
synchronized (myLock) {
if (!myRequestSubmitted && !myRequestRunning) {
return;
}
semaphore.down();
myWaitingUpdateCompletionSemaphores.add(semaphore);
}
if (!semaphore.waitFor(100*1000)) {
LOG.error("Too long VCS update");
return;
}
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:UpdateRequestsQueue.java
示例16: impl
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
private void impl(RootsHolder rootsHolder, GitLogFilters filters) {
final GitCommitsSequentialIndex commitsSequentially = new GitCommitsSequentialIndex();
final MediatorImpl mediator = new MediatorImpl(myProject, commitsSequentially);
final LoadController controller = new LoadController(myProject, mediator, null, commitsSequentially);
mediator.setLoader(controller);
final BigTableTableModel tableModel = new BigTableTableModel(Collections.<ColumnInfo>emptyList(), EmptyRunnable.getInstance());
mediator.setTableModel(tableModel);
tableModel.setRootsHolder(rootsHolder);
final Semaphore semaphore = new Semaphore();
final MyUIRefresh refresh = new MyUIRefresh(semaphore);
mediator.setUIRefresh(refresh);
final long start = System.currentTimeMillis();
semaphore.down();
mediator.reload(rootsHolder, Collections.<String>emptyList(), Collections.<String>emptyList(), filters, true);
semaphore.waitFor(300000);
refresh.assertMe();
final long end = System.currentTimeMillis();
System.out.println("Time: " + (end - start));
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:GitLogPerformanceTest.java
示例17: waitFor
import com.intellij.util.concurrency.Semaphore; //导入依赖的package包/类
public boolean waitFor(long msTimeout) {
if (isProcessed()) {
return true;
}
final Semaphore semaphore = new Semaphore();
semaphore.down();
doWhenProcessed(semaphore::up);
try {
if (msTimeout == -1) {
semaphore.waitForUnsafe();
}
else if (!semaphore.waitForUnsafe(msTimeout)) {
reject("Time limit exceeded");
return false;
}
}
catch (InterruptedException e) {
reject(e.getMessage());
return false;
}
return true;
}
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:ActionCallback.java
示例18: 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
示例19: 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
示例20: 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
注:本文中的com.intellij.util.concurrency.Semaphore类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论