X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fext%2Fedu%2Fucsf%2Frbvi%2Fstrucviz2%2FChimeraManager.java;h=2c40e1ce271b60cf181da4b11446da1764b7a4ab;hb=b28bddf12e2791a019fba9c233d46407deb65976;hp=a76c7e0fe69e2f6be247a716b6c40e26dec2ed1c;hpb=81316c6cc11e29c893d55e87ebd16d9ecd09c1f3;p=jalview.git diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java index a76c7e0..2c40e1c 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java @@ -27,15 +27,9 @@ import ext.edu.ucsf.rbvi.strucviz2.port.ListenerThreads; */ public class ChimeraManager { - private static final boolean debug = true; + private static final boolean debug = false; - /* - * true: use REST API (recommended), false: use stdout/stdin (deprecated) - */ - private static final boolean USE_REST = true; - - // Port number for Chimera REST service - private int restPort; + private int chimeraRestPort; private Process chimera; @@ -224,10 +218,14 @@ public class ChimeraManager modelNumbers[0], modelNumbers[1]); currentModelsMap.put(modelNumber, newModel); models.add(newModel); + + // // patch for Jalview - set model name in Chimera + // sendChimeraCommand("setattr M name " + modelName + " #" + modelNumbers[0], false); // end patch for Jalview + modelNumbers = null; } } @@ -370,11 +368,7 @@ public class ChimeraManager { chimera = null; currentModelsMap.clear(); - if (!USE_REST) - { - chimeraListenerThread.requestStop(); - chimeraListenerThread = null; - } + this.chimeraRestPort = 0; structureManager.clearOnChimeraExit(); } @@ -545,13 +539,11 @@ public class ChimeraManager List args = new ArrayList(); args.add(chimeraPath); args.add("--start"); - args.add(USE_REST ? "RESTServer" : "ReadStdin"); + args.add("RESTServer"); ProcessBuilder pb = new ProcessBuilder(args); chimera = pb.start(); error = ""; workingPath = chimeraPath; - logger.info("Starting " + chimeraPath + " with " - + (USE_REST ? "REST API" : "stdin/stdout")); break; } catch (Exception e) { @@ -562,17 +554,9 @@ public class ChimeraManager // If no error, then Chimera was launched successfully if (error.length() == 0) { - if (USE_REST) - { - this.restPort = getPortNumber(); - } - else - { - // Initialize the listener threads - chimeraListenerThread = new ListenerThreads(chimera, - structureManager); - chimeraListenerThread.start(); - } + this.chimeraRestPort = getPortNumber(); + System.out.println("Chimera REST API started on port " + + chimeraRestPort); // structureManager.initChimTable(); structureManager.setChimeraPathProperty(workingPath); // TODO: [Optional] Check Chimera version and show a warning if below 1.8 @@ -603,7 +587,8 @@ public class ChimeraManager String [] tokens = response.split(" "); if (tokens.length == 7 && "port".equals(tokens[5])) { port = Integer.parseInt(tokens[6]); - logger.info("Chimera REST service listening on port " + restPort); + logger.info("Chimera REST service listening on port " + + chimeraRestPort); } } catch (Exception e) { @@ -760,22 +745,17 @@ public class ChimeraManager } catch (InterruptedException q) { } - ; } busy = true; long startTime = System.currentTimeMillis(); try { - if (USE_REST) - { - return sendRestCommand(command); - } - else - { - return sendStdinCommand(command, reply); - } + return sendRestCommand(command); } finally { + /* + * Make sure busy flag is reset come what may! + */ busy = false; if (debug) { @@ -796,7 +776,7 @@ public class ChimeraManager protected List sendRestCommand(String command) { // TODO start a separate thread to do this so we don't block? - String restUrl = "http://127.0.0.1:" + this.restPort + "/run"; + String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run"; List commands = new ArrayList(1); commands.add(new BasicNameValuePair("command", command));