[duplicates] enable duplicates analysis in PyCharm/WebStorm/PhpStorm/RubyMine
[idea/community.git] / platform / core-api / src / com / intellij / util / concurrency / EdtScheduledExecutorServiceImpl.java
1 // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.util.concurrency;
3
4 import com.intellij.openapi.application.ModalityState;
5 import org.jetbrains.annotations.NotNull;
6
7 import java.util.List;
8 import java.util.concurrent.ExecutorService;
9 import java.util.concurrent.ScheduledFuture;
10 import java.util.concurrent.TimeUnit;
11
12 /**
13  * An {@link ExecutorService} implementation which
14  * delegates tasks to the EDT for execution.
15  */
16 class EdtScheduledExecutorServiceImpl extends SchedulingWrapper implements EdtScheduledExecutorService {
17   private EdtScheduledExecutorServiceImpl() {
18     super(EdtExecutorServiceImpl.INSTANCE, ((AppScheduledExecutorService)AppExecutorUtil.getAppScheduledExecutorService()).delayQueue);
19   }
20
21
22   @NotNull
23   @Override
24   public ScheduledFuture<?> schedule(@NotNull Runnable command, @NotNull ModalityState modalityState, long delay, TimeUnit unit) {
25     MyScheduledFutureTask<?> task = new MyScheduledFutureTask<Void>(command, null, triggerTime(delayQueue, delay, unit)){
26       @Override
27       void executeMeInBackendExecutor() {
28         EdtExecutorService.getInstance().execute(this, modalityState);
29       }
30     };
31     return delayedExecute(task);
32   }
33
34   // stubs
35   @Override
36   public void shutdown() {
37     AppScheduledExecutorService.error();
38   }
39
40   @NotNull
41   @Override
42   public List<Runnable> shutdownNow() {
43     return AppScheduledExecutorService.error();
44   }
45
46   @Override
47   public boolean isShutdown() {
48     return false;
49   }
50
51   @Override
52   public boolean isTerminated() {
53     return false;
54   }
55
56   @Override
57   public boolean awaitTermination(long timeout, @NotNull TimeUnit unit) {
58     AppScheduledExecutorService.error();
59     return false;
60   }
61
62   static final EdtScheduledExecutorService INSTANCE = new EdtScheduledExecutorServiceImpl();
63
64 }