From d372765e32e7f80c619f1bdb52579e0b800a6e8e Mon Sep 17 00:00:00 2001 From: Louis Bergelson Date: Wed, 14 Aug 2024 18:55:16 -0400 Subject: [PATCH] Move the amazon credentials check at startup into an async thread (#1543) * Move the amazon credentials check at startup into an async thread * Profiling showed it was adding about half a second at startup --------- Co-authored-by: jrobinso <933148+jrobinso@users.noreply.github.com> --- .../java/org/broad/igv/ui/IGVMenuBar.java | 20 +++++++++---------- .../java/org/broad/igv/util/AmazonUtils.java | 2 +- .../org/broad/igv/util/LongRunningTask.java | 9 +++++---- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/broad/igv/ui/IGVMenuBar.java b/src/main/java/org/broad/igv/ui/IGVMenuBar.java index ab46607fa1..0d1d91da48 100644 --- a/src/main/java/org/broad/igv/ui/IGVMenuBar.java +++ b/src/main/java/org/broad/igv/ui/IGVMenuBar.java @@ -194,14 +194,14 @@ private List createMenus() { log.error("Error creating google menu: " + e.getMessage()); } - try { - AWSMenu = createAWSMenu(); - AWSMenu.setVisible(AmazonUtils.isAwsProviderPresent()); - menus.add(AWSMenu); - } catch (IOException e) { - log.error("Error creating the Amazon AWS menu: " + e.getMessage()); - AWSMenu.setVisible(false); - } + + AWSMenu = createAWSMenu(); + AWSMenu.setVisible(false); + menus.add(AWSMenu); + //detecting the provider is slow, do it in another thread + LongRunningTask.submit(this::updateAWSMenu); + + menus.add(createHelpMenu()); @@ -211,7 +211,7 @@ private List createMenus() { } public void updateAWSMenu() { - AWSMenu.setVisible(AmazonUtils.isAwsProviderPresent()); + SwingUtilities.invokeLater(() -> AWSMenu.setVisible(AmazonUtils.isAwsProviderPresent())); } /** @@ -963,7 +963,7 @@ public void actionPerformed(ActionEvent actionEvent) { return menu; } - private JMenu createAWSMenu() throws IOException { + private JMenu createAWSMenu() { boolean usingCognito = AmazonUtils.GetCognitoConfig() != null; diff --git a/src/main/java/org/broad/igv/util/AmazonUtils.java b/src/main/java/org/broad/igv/util/AmazonUtils.java index 2df905a817..e832e5a67d 100644 --- a/src/main/java/org/broad/igv/util/AmazonUtils.java +++ b/src/main/java/org/broad/igv/util/AmazonUtils.java @@ -83,7 +83,7 @@ public static JsonObject GetCognitoConfig() { /** - * Test to see if aws credentials are avaialable, either through IGV configuration of Cognito, or from the + * Test to see if aws credentials are available, either through IGV configuration of Cognito, or from the * default provider chain. See https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default * * @return diff --git a/src/main/java/org/broad/igv/util/LongRunningTask.java b/src/main/java/org/broad/igv/util/LongRunningTask.java index c3a64650f9..a37d21804d 100644 --- a/src/main/java/org/broad/igv/util/LongRunningTask.java +++ b/src/main/java/org/broad/igv/util/LongRunningTask.java @@ -40,9 +40,9 @@ * * @author jrobinso */ -public class LongRunningTask implements Callable { +public class LongRunningTask implements Callable { - private static Logger log = LogManager.getLogger(LongRunningTask.class); + private static final Logger log = LogManager.getLogger(LongRunningTask.class); private static final ExecutorService threadExecutor = Executors.newFixedThreadPool(5); @@ -52,7 +52,7 @@ public static Executor getThreadExecutor() { return threadExecutor; } - public static Future submit(Runnable runnable) { + public static Future submit(Runnable runnable) { if (Globals.isBatch()) { runnable.run(); return null; @@ -65,7 +65,8 @@ private LongRunningTask(Runnable runnable) { this.runnable = runnable; } - public Object call() { + @Override + public Void call() { CursorToken token = WaitCursorManager.showWaitCursor(); try {