public void resume() { if (skipAnimation()) { animationDone(); return; } if (myCycleDuration == 0) { myCurrentFrame = myTotalFrames - 1; paint(); animationDone(); } else if (myTicker == null) { myTicker = EdtExecutorService.getScheduledExecutorInstance().scheduleWithFixedDelay(new Runnable() { @Override public void run() { onTick(); } @Override public String toString() { return "Scheduled "+Animator.this; } }, 0, myCycleDuration * 1000 / myTotalFrames, TimeUnit.MICROSECONDS); } }
public Alarm(@NotNull ThreadToUse threadToUse, @Nullable Disposable parentDisposable) { myThreadToUse = threadToUse; myExecutorService = threadToUse == ThreadToUse.SWING_THREAD ? // pass straight to EDT EdtExecutorService.getScheduledExecutorInstance() : // or pass to app pooled thread. // have to restrict the number of running tasks because otherwise the (implicit) contract of // "addRequests with the same delay are executed in order" will be broken Executors.newSingleThreadScheduledExecutor(); if (parentDisposable != null) { Disposer.register(parentDisposable, this); } }
public void onCurrentSchemeChanged() { myLayout.show(mySettingsPanel, WAIT_CARD); final Runnable replaceLayout = new Runnable() { @Override public void run() { if (!myIsDisposed) { ensureCurrentPanel().onSomethingChanged(); String schemeName = myModel.getSelectedScheme().getName(); updateSetFrom(); myLayout.show(mySettingsPanel, schemeName); } } }; if (ApplicationManager.getApplication().isHeadlessEnvironment()) { replaceLayout.run(); } else { myAlarm.cancel(false); myAlarm = EdtExecutorService.getScheduledExecutorInstance().schedule(replaceLayout, 200, TimeUnit.MILLISECONDS); } }
public void update(final String scanningPackagesMessage, final boolean indeterminate, final double ffraction) { if (myPaintInQueue) return; checkCanceled(); myPaintInQueue = true; myAlarm.cancel(false); myAlarm = EdtExecutorService.getScheduledExecutorInstance().schedule(() -> { myPaintInQueue = false; myProgressPanel.myTextLabel.setText(scanningPackagesMessage); int fraction = (int)(ffraction * 99 + 0.5); myProgressPanel.myFractionLabel.setText(fraction + "%"); if (fraction != -1) { myProgressPanel.myFractionProgress.setValue(fraction); } myProgressPanel.myFractionProgress.setIndeterminate(indeterminate); }, 10, TimeUnit.MILLISECONDS); }
@Override public void dispose() { if (!myDisposed) { myDisposed = true; cancelAllRequests(); if (myExecutorService != EdtExecutorService.getScheduledExecutorInstance()) { myExecutorService.shutdownNow(); } } }
public Alarm(@Nonnull ThreadToUse threadToUse, @Nullable Disposable parentDisposable) { myThreadToUse = threadToUse; myExecutorService = threadToUse == ThreadToUse.SWING_THREAD ? // pass straight to EDT EdtExecutorService.getScheduledExecutorInstance() : // or pass to app pooled thread. // have to restrict the number of running tasks because otherwise the (implicit) contract of // "addRequests with the same delay are executed in order" will be broken AppExecutorUtil.createBoundedScheduledExecutorService("Alarm pool",1); if (parentDisposable == null) { if (threadToUse == ThreadToUse.POOLED_THREAD || threadToUse != ThreadToUse.SWING_THREAD) { boolean crash = threadToUse == ThreadToUse.POOLED_THREAD || ApplicationManager.getApplication().isUnitTestMode(); IllegalArgumentException t = new IllegalArgumentException("You must provide parent Disposable for non-swing thread Alarm"); if (crash) { throw t; } // do not crash yet in case of deprecated SHARED_THREAD LOG.warn(t); } } else { Disposer.register(parentDisposable, this); } }
private static void cancelAndRestartDaemonLater(@Nonnull ProgressIndicator progress, @Nonnull final Project project) throws ProcessCanceledException { progress.cancel(); Application application = ApplicationManager.getApplication(); int delay = application.isUnitTestMode() ? 0 : RESTART_DAEMON_RANDOM.nextInt(100); EdtExecutorService.getScheduledExecutorInstance().schedule(() -> { if (!project.isDisposed()) { DaemonCodeAnalyzer.getInstance(project).restart(); } }, delay, TimeUnit.MILLISECONDS); throw new ProcessCanceledException(); }
private synchronized void setRunning(boolean running) { if (!this.running && running) { if (state.pauseOtherTrackerInstances) { synchronized (ALL_OPENED_TRACKERS_LOCK) { for (TimeTrackerWidget tracker : ALL_OPENED_TRACKERS) { if (tracker != this && tracker.running) { tracker.setRunning(false); tracker.idle = true; } } } } repaint(); this.idle = false; this.running = true; this.startedAtMs = System.currentTimeMillis(); if (ticker != null) { ticker.cancel(false); } lastTickAt = System.currentTimeMillis(); final long tickDelay = 1; final TimeUnit tickDelayUnit = TimeUnit.SECONDS; tickTooLongMs = tickDelayUnit.toMillis(tickDelay) * 20;//20 sec is too long ticker = EdtExecutorService.getScheduledExecutorInstance().scheduleWithFixedDelay(() -> UIUtil.invokeLaterIfNeeded(() -> { checkForTimeJump(true); lastTickAt = System.currentTimeMillis(); if (System.currentTimeMillis() - lastActivityAtMs > state.idleThresholdMs) { if (this.running) { setRunning(false); idle = true; } } repaint(); }), tickDelay, tickDelay, tickDelayUnit); } else if(this.running && !running) { checkForTimeJump(false); final long runningForSeconds = runningForSeconds(); state.totalTimeSeconds += runningForSeconds; addVersionTime(runningForSeconds); this.running = false; if (ticker != null) { ticker.cancel(false); ticker = null; } repaint(); } }
public void addRequest(@Nonnull EdtRunnable runnable, int delay) { myRequests.add(runnable); EdtExecutorService.getScheduledExecutorInstance().schedule(runnable, delay, TimeUnit.MILLISECONDS); }
public void start() { if (mySchedulerHandle != null) { mySchedulerHandle.cancel(false); } mySchedulerHandle = EdtExecutorService.getScheduledExecutorInstance().scheduleWithFixedDelay(this, mySleepTime, mySleepTime, TimeUnit.MILLISECONDS); }