RemoteListenable rl = remoteNode.getRemoteListenable(); if (log.isDebugEnabled()) log.debug("Adding listener: " + CSMART.getNodeListenerId() + " for: " + nodeInfo.processName); rl.addListener(nci.listener, CSMART.getNodeListenerId());
if (remoteNode != null) { RemoteListenable rl = remoteNode.getRemoteListenable(); if (log.isDebugEnabled()) log.debug("Adding listener: " + CSMART.getNodeListenerId() + " for: " + nodeInfo.processName); rl.addListener(nci.listener, CSMART.getNodeListenerId()); } else { if (log.isWarnEnabled()) log.warn("Got null process from AppServer for node to attach to: " + name); throw new Exception("Null RemoteProcess for " + nodeInfo.processName); }
  private void attachButton_actionPerformed() {    attachButton.setSelected(false);    // Before getting this list, make sure our list of possible    // things to attach to is up-to-date    appServerSupport.refreshAppServers();    ArrayList nodesToAttach = appServerSupport.getNodesToAttach();    if (nodesToAttach == null) {      // There were no Nodes to attach to      JOptionPane.showMessageDialog(this, "No new Nodes to Attach to.", 				    "Attach", JOptionPane.PLAIN_MESSAGE);      return;    } else if  (nodesToAttach.isEmpty()) {      // User just selected none to attach to      return;    }    // Loop over nodes to attach to    for (int i = 0; i < nodesToAttach.size(); i++) {      NodeInfo nodeInfo = (NodeInfo)nodesToAttach.get(i);      boolean haveAlready = false;      String name = nodeInfo.nodeName;      synchronized (runningNodesLock) {	if (runningNodes.get(nodeInfo.nodeName) != null) {	  haveAlready = true;	}      }      // Are we already atached to a node of that name?      if (haveAlready) {	if (log.isDebugEnabled()) {	  log.debug("Already have attached node of name " + nodeInfo.nodeName);	}	// So how do I get the old process name?	NodeInfo old = (NodeInfo)nodeToNodeInfo.get(nodeInfo.nodeName);	if (old.processName.equals(nodeInfo.processName)) {	  if (log.isDebugEnabled()) {	    log.debug("They have the same process name: " + nodeInfo.processName);	  }	  // FIXME: Maybe compare nodeInfo.properties too?	  if (log.isDebugEnabled()) {	    log.debug("Asked to attach to already attached node " + nodeInfo.nodeName);	  }	  continue;	} else {	  // Going to allow attaching	  // But need to pretend it has a different name or else	  // I'll have trouble stopping it and whatnot	  // Must effectively reset nodeInfo.nodeName	  name = name + "-attached";	}      } // end of block to see if this Node already attached      runStart = new Date();      NodeCreationInfo nci = prepareToCreateNode(nodeInfo.appServer,                                                 name,                                                 nodeInfo.hostName,                                                 nodeInfo.properties,                                                 nodeInfo.args);      nodeToNodeInfo.put(name, nodeInfo);      RemoteProcess remoteNode = null;      // add listener to node      try {        remoteNode =          nodeInfo.appServer.getRemoteProcess(nodeInfo.processName);        RemoteListenable rl =          remoteNode.getRemoteListenable();        if (log.isDebugEnabled())	  log.debug("Adding listener: " +                           CSMART.getNodeListenerId() +                           " for: " +                           nodeInfo.processName);        rl.addListener(nci.listener,                        CSMART.getNodeListenerId());      } catch (Exception e) {        if (log.isErrorEnabled()) {          log.error("Exception attaching to: " + nodeInfo.processName, e);        }	NodeInfo invalid = (NodeInfo) nodeToNodeInfo.remove(name);	// remove status button	// kill doc, textPane, listener	// remove from nodeListeners and nodePanes	((ConsoleNodeListener)nci.listener).cleanUp();	nodeListeners.remove(name);	ConsoleTextPane textPane = (ConsoleTextPane)nodePanes.remove(name);	if (textPane != null)	  textPane.cleanUp();	//	removeStatusButton(nci.statusButton);        continue;      }      synchronized (runningNodesLock) {        runningNodes.put(name, remoteNode);      }      addStatusButton(nci.statusButton);      ConsoleInternalFrame frame =         new ConsoleInternalFrame(nci.nodeName,                                 nci.hostName,                                 nci.properties,                                 nci.args,                                 (ConsoleNodeListener)nci.listener,                                 nci.scrollPane,                                 nci.statusButton,                                 nci.logFileName,                                 remoteNode,                                 console);      frame.addInternalFrameListener(new NodeFrameListener());      desktop.addNodeFrame(frame, nci.nodeName);    }    updateControls(true);    // If have an experiment to run    // but have not run it yet, make that possible still    if (! usingExperiment && experiment != null) {      runButton.setEnabled(true);      runButton.setSelected(false);    }  }