Skip to content

Instantly share code, notes, and snippets.

@jeffmaury
Created February 25, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffmaury/a521e79ff4300fc6bd685a36099c1892 to your computer and use it in GitHub Desktop.
Save jeffmaury/a521e79ff4300fc6bd685a36099c1892 to your computer and use it in GitHub Desktop.
private void waitForPortAvailable(int port, IProgressMonitor monitor) throws CoreException{
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 60_000 && !monitor.isCanceled()) {
try (Socket socket = new Socket("localhost", port)) {
return;
} catch (ConnectException e) {
try {
Thread.sleep(1000L);
} catch (InterruptedException e1) {
throw new CoreException(new Status(IStatus.ERROR, QuarkusCorePlugin.PLUGIN_ID, e.getLocalizedMessage()));
}
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, QuarkusCorePlugin.PLUGIN_ID, e.getLocalizedMessage()));
}
}
throw new CoreException(new Status(IStatus.ERROR, QuarkusCorePlugin.PLUGIN_ID, "Can't connect to JVM"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment