static int getBotAddress_timeout = 5000; static S getBotAddress(S searchPattern) { S subBot = ""; int i = searchPattern.indexOf('/'); if (i >= 0 && (isJavaIdentifier(searchPattern.substring(0, i)) || isInteger(searchPattern.substring(0, i)))) { subBot = searchPattern.substring(i); searchPattern = searchPattern.substring(0, i); if (!isInteger(searchPattern)) searchPattern = "Multi-Port at " + searchPattern + "."; } // assume it's a port if it's an integer if (isInteger(searchPattern)) ret searchPattern + subBot; Integer port = findBot_cache.get(searchPattern); if (port != null) try { DialogIO io = talkTo("localhost", port); try { io.waitForLine(/*getBotAddress_timeout*/); // TODO: implement S line = io.readLineNoBlock(); if (startsWithIgnoreCase(line, searchPattern)) ret port + subBot; } finally { io.close(); } } catch (Exception e) { e.printStackTrace(); } L bots = quickBotScan(); // find top-level bots for (ProgramScan.Program p : bots) { if (indexOfIgnoreCase(p.helloString, searchPattern) == 0) { // strict matching - start of hello string only, but case-insensitive return p.port + subBot; } } // find sub-bots for (ProgramScan.Program p : bots) { S botName = firstPartOfHelloString(p.helloString); boolean isVM = startsWithIgnoreCase(p.helloString, "This is a JavaX VM."); boolean shouldRecurse = startsWithIgnoreCase(botName, "Multi-Port") || isVM; if (shouldRecurse) try { Map subBots = unstructureMap_verboseError(sendToLocalBot(p.port, "list bots")); for (Number vport : subBots.keySet()) { S name = subBots.get(vport); if (startsWithIgnoreCase(name, searchPattern)) ret p.port + "/" + vport; } } catch (Exception e) { e.printStackTrace(); } } ret null; }