Hi!

I was trying to work around the threading problem with the evals, which we discussed recently. The following patch ensures that only one command is run at the time. If a new commands comes
in during this, it is queued.

Greetings,
Andreas


in org.jmol.viewer :

  /////////////////////////////////////////////////////////////////
  // routines for script support
  /////////////////////////////////////////////////////////////////

  Vector scriptQueue = new Vector();
  boolean scriptProcessing = false;

  private synchronized void startQueueEval(Eval e) {

    if ( scriptProcessing) {
      //System.out.println("adding to queue " + scriptQueue.size());
      scriptQueue.add(e);

      return;
    }
    //System.out.println("start processing");
    scriptProcessing = true;
    e.start();
    eval = e;


  }

  public boolean isEvaluating() {
    return scriptProcessing;
  }

  public synchronized void notifyEvalStop(){
    //System.out.println("notifyEvalStop");
    scriptProcessing = false;
    eval = null;

    if ( scriptQueue.size() > 0){
      //System.out.println("taking first from queue");
      Eval e = (Eval) scriptQueue.get(0);
      scriptQueue.remove(0);
      startQueueEval(e);
    }
  }

  public String evalFile(String strFilename) {
    if (strFilename != null) {
      Eval e = new Eval(this);

      if (! e.loadScriptFile(strFilename, false))
        return e.getErrorMessage();
      startQueueEval(e);
    }
    return null;
  }

  public String evalString(String strScript) {
    if (strScript != null) {
      Eval e = new Eval(this);
      if (! e.loadScriptString(strScript, false))
        return e.getErrorMessage();
      startQueueEval(e);
    }
    return null;
  }

  public String evalStringQuiet(String strScript) {
    if (strScript != null) {

      Eval e = new Eval(this);
      if (! e.loadScriptString(strScript, true))
        return e.getErrorMessage();
      startQueueEval(e);
    }
    return null;
  }





additionally :

* Eval needs a
         viewer.notifyEvalStop();
   in the end of run();

* JmolViewer:
        abstract public boolean isEvaluating();




-----------------------------------------------------------------------

Andreas Prlic      Wellcome Trust Sanger Institute
                              Hinxton, Cambridge CB10 1SA, UK
                         +44 (0) 1223 49 6891



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to