/** * Blocks current thread until Cloud SDK is ready for all operations. If process results in error * or user cancel, calls {@link CloudSdkStatusHandler} methods to notify about errors and shows * notifications. This method is expected to be called from non-UI background thread. * * @param project Project to which SDK operation belongs. * @param progressMessage Message to show in progress dialog to identify which process is * starting, i.e. deployment or local server. * @param sdkStatusHandler Callback to log errors and progress. */ public void blockUntilSdkReady( @Nullable Project project, String progressMessage, CloudSdkStatusHandler sdkStatusHandler) throws InterruptedException { CountDownLatch blockingCompletedLatch = new CountDownLatch(1); ApplicationManager.getApplication() .invokeLater( () -> doWait( project, blockingCompletedLatch::countDown, progressMessage, sdkStatusHandler)); blockingCompletedLatch.await(); }
/** * Waits in background for Cloud SDK to be ready for all operations and then runs the given * runnable. If process results in error or user cancel, shows notification and does not run. This * method does not block and must be called from application UI thread. * * @param project Project to which runnable belongs. * @param afterSdkReady Runnable to execute after Cloud SDK is ready. This runnable will be * executed on the application UI thread. * @param progressMessage Message to show in progress dialog to identify which process is * starting, i.e. deployment or local server. * @param sdkStatusHandler Logger for errors etc. */ public void runWhenSdkReady( @Nullable Project project, @NotNull Runnable afterSdkReady, String progressMessage, CloudSdkStatusHandler sdkStatusHandler) { doWait( project, () -> { // at this point the installation should be either ready, failed or user cancelled. // run only if ready. if (CloudSdkService.getInstance().getStatus() == SdkStatus.READY) { ApplicationManager.getApplication().invokeLater(afterSdkReady); } }, progressMessage, sdkStatusHandler); }