void (@NotNull Callback callback) { final ServerConnection connection = ServerConnectionManager.getInstance().createTemporaryConnection(myServer); final AtomicReference<Boolean> connectedRef = new AtomicReference<>(null); final Semaphore semaphore = new Semaphore(); semaphore.down(); //noinspection unchecked connection.connectIfNeeded(new ServerConnector.ConnectionCallback() { @Override public void connected(@NotNull ServerRuntimeInstance serverRuntimeInstance) { connectedRef.set(true); semaphore.up(); connection.disconnect(); } @Override public void errorOccurred(@NotNull String errorMessage) { connectedRef.set(false); semaphore.up(); } }); new Task.Backgroundable(null, CloudBundle.message("task.title.connecting"), true) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); while (!indicator.isCanceled()) { if (semaphore.waitFor(500)) { break; } } final Boolean connected = connectedRef.get(); if (connected == null) { return; } callback.connectionTested(connected, connection.getStatusText()); } }.queue(); }