try { RemoteListenable rl = remoteNode.getRemoteListenable(); if (rl != null) { rl.flushOutput(); remoteNode.destroy(); } } catch (Exception ex) { if(log.isWarnEnabled()) { log.warn("Unable to destroy node, assuming it's dead: ", ex); }   markNodeDead(nodeName); } }
RemoteListenable rl = null; for (int retries = 5; retries > 0; retries--) { try { rl = remoteNode.getRemoteListenable(); if (rl != null) { rl.flushOutput(); remoteNode.destroy(); retries = 0; }      } catch (Exception ex) {         if (rl == null) {      if (log.isWarnEnabled()) log.warn("Never got RemoteListenable. Exception possibly cause of load? Will pause and retry.", ex);   try {  sleep(2000); } catch (InterruptedException ie) {}  continue; } else {   if(log.isWarnEnabled()) { log.warn("Unable to destroy node, assuming it's dead: ", ex); }    markNodeDead(nodeName); retries = 0; } } } }
  private void stopAllNodes() {    // if there's a thread still creating nodes, stop it    stopNodeCreation = true;    // wait for the creating thread to stop    if (nodeCreator != null) {      try {        nodeCreator.join();      } catch (InterruptedException ie) {        if(log.isErrorEnabled()) {          log.error("Exception waiting for node creation thread to die: ", ie);        }      }      nodeCreator = null;    }    // at this point all the nodes have been created, but    // the gui controls for the last node created may not have    // been created (as they're created via a swing-thread-invoke-later)    // so we can no longer assume that a gui (node frame, status button)    // exists for every node    // set a flag indicating that we're stopping the trial    stopping = true;    Enumeration nodeNames;    synchronized (runningNodesLock) {      nodeNames = runningNodes.keys();    } // end synchronized    // before destroying nodes, stop the GLSClient so    // we don't get error messages    if (glsClient != null) {      glsClient.stop();      glsClient = null;    }    if (log.isDebugEnabled()) {      log.debug("About to kill all Nodes");    }    // destroy the nodes by creating a thread to destroy each one    // and then waiting for all those threads to finish    ArrayList destroyerThreads = new ArrayList();    while (nodeNames.hasMoreElements()) {      final String nodeName = (String)nodeNames.nextElement();      Thread nodeDestroyer = new Thread("DestroyNode " + nodeName) {        public void run() {          RemoteProcess remoteNode;          synchronized (runningNodesLock) {            remoteNode = (RemoteProcess)runningNodes.get(nodeName);          } // end synchronized          if (remoteNode == null) {            if(log.isErrorEnabled()) {              log.error("Unknown node name: " + nodeName);            }	    markNodeDead(nodeName);            return;          }          try {            RemoteListenable rl =               remoteNode.getRemoteListenable();	    if (rl != null) {	      rl.flushOutput();	      remoteNode.destroy();	    }          } catch (Exception ex) {            if(log.isWarnEnabled()) {              log.warn("Unable to destroy node, assuming it's dead: ", ex);            }            // call the method that would have been called            // had the node been stopped	    markNodeDead(nodeName);          }        }      }; // end nodeDestroyer thread      destroyerThreads.add(nodeDestroyer);      nodeDestroyer.start();    }    for (int i = 0; i < destroyerThreads.size(); i++) {      try {        Thread destroyer = (Thread)destroyerThreads.get(i);        destroyer.join(); // wait for node destruction to complete      } catch (Exception e) {        if(log.isErrorEnabled()) {          log.error("Exception", e);        }      }    }    if (log.isDebugEnabled()) {      log.debug(".... done killing Nodes");    }  } // end of stopAllNodes