From 54ac8fefd93757ecc1f69a91032381bea3cdabe7 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 29 Nov 2023 16:21:08 +0000 Subject: [PATCH] JAL-4344 Some fixes of waiting blocks, and headless mode for export. Control logging of Jmol. --- src/jalview/bin/Commands.java | 21 ++++++++++------ src/jalview/bin/Console.java | 29 ++++++++++++++++++++++ src/jalview/gui/AppJmol.java | 55 ++++++++++++++++++++++------------------- 3 files changed, 72 insertions(+), 33 deletions(-) diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 475eba2..6aab95b 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -657,18 +657,19 @@ public class Commands } try { - long tries = 1000; - while (structureViewer.isBusy() && tries > 0) + int tries = 0; + int maxTries = 1000; + while (structureViewer.isBusy() && tries < maxTries) { - Thread.sleep(25); - if (structureViewer.isBusy()) + if (tries % 100 == 0) { - tries--; Console.debug( "Waiting for viewer for " + structureFilepath); } + Thread.sleep(10); + tries++; } - if (tries == 0 && structureViewer.isBusy()) + if (tries >= maxTries && structureViewer.isBusy()) { addWarn("Gave up waiting for structure viewer to load file '" + structureFile @@ -823,6 +824,7 @@ public class Commands // we can do this with every viewer // + boolean doContinue = false; try { // We don't expect class cast exception @@ -847,11 +849,12 @@ public class Commands addError( "Unexpected error when restoring structure viewer session after custom view operations."); isError = true; - continue; + doContinue = true; } finally { try { + // restore colour scheme this.colourAlignFrame(af, originalColourScheme); } catch (Exception t) { @@ -859,6 +862,10 @@ public class Commands "Unexpected error when restoring colourscheme to alignment after temporary change for export.", t); } + if (doContinue) + { + continue; + } } } } diff --git a/src/jalview/bin/Console.java b/src/jalview/bin/Console.java index 1bb8162..cd5683c 100644 --- a/src/jalview/bin/Console.java +++ b/src/jalview/bin/Console.java @@ -264,6 +264,35 @@ public class Console // The main application logger log = JLoggerLog4j.getLogger(Cache.JALVIEW_LOGGER_NAME, logLevel); + + // Jmol logging. Reduce logging level for INFO. + int jmolLogLevel = org.jmol.util.Logger.LEVEL_INFO; + switch (logLevel) + { + case FATAL: + jmolLogLevel = org.jmol.util.Logger.LEVEL_FATAL; + break; + case ERROR: + jmolLogLevel = org.jmol.util.Logger.LEVEL_ERROR; + break; + case WARN: + jmolLogLevel = org.jmol.util.Logger.LEVEL_ERROR; + break; + case INFO: + jmolLogLevel = org.jmol.util.Logger.LEVEL_ERROR; + break; + case DEBUG: + jmolLogLevel = org.jmol.util.Logger.LEVEL_INFO; + break; + case TRACE: + jmolLogLevel = org.jmol.util.Logger.LEVEL_DEBUGHIGH; + break; + case ALL: + jmolLogLevel = org.jmol.util.Logger.LEVEL_MAX; + break; + } + org.jmol.util.Logger.setLogLevel(jmolLogLevel); + // org.jmol.util.Logger.setLogLevel(org.jmol.util.Logger.LEVEL_ERROR); } catch (NoClassDefFoundError e) { jalview.bin.Console diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 0aa4878..cb6aa13 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -41,6 +41,7 @@ import javax.swing.event.InternalFrameEvent; import jalview.api.AlignmentViewPanel; import jalview.bin.Console; +import jalview.bin.Jalview; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.datamodel.StructureViewerModel; @@ -453,7 +454,6 @@ public class AppJmol extends StructureViewerBase float usescale = bis.scale(); int usewidth = bis.width(); int useheight = bis.height(); - ImageWriterI writer = new ImageWriterI() { @Override @@ -484,35 +484,38 @@ public class AppJmol extends StructureViewerBase final Throwable[] exceptions = new Throwable[1]; exceptions[0] = null; final AppJmol us = this; + Runnable exportRunnable = () -> { + try + { + exporter.doExport(file, us, width, height, view, renderer, userBis); + } catch (Throwable t) + { + Console.debug("Problem when exporting structure image", t); + exceptions[0] = t; + } + }; try { - Thread runner = Executors.defaultThreadFactory() - .newThread(new Runnable() - { - @Override - public void run() - { - try - { - exporter.doExport(file, us, width, height, view, - renderer, userBis); - } catch (Throwable t) - { - exceptions[0] = t; - } - } - }); - runner.start(); - long time = 0; - do + if (Jalview.isHeadlessMode()) { - Thread.sleep(25); - } while (runner.isAlive() && time++ < 4000); - if (time >= 4000) + exportRunnable.run(); + } + else { - runner.interrupt(); - throw new ImageOutputException( - "Jmol took too long to export. Waited for 100 seconds."); + Thread runner = Executors.defaultThreadFactory() + .newThread(exportRunnable); + runner.start(); + long time = 0; + do + { + Thread.sleep(25); + } while (runner.isAlive() && time++ < 4000); + if (time >= 4000) + { + runner.interrupt(); + throw new ImageOutputException( + "Jmol took too long to export. Waited for 100 seconds."); + } } } catch (Throwable e) { -- 1.7.10.2