Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

58
LINES

< > BotCompany Repo | #1009722 // getBotAddress - old version

JavaX fragment (include)

1  
static int getBotAddress_timeout = 5000;
2  
3  
static S getBotAddress(S searchPattern) {
4  
  S subBot = "";
5  
  int i = searchPattern.indexOf('/');
6  
  if (i >= 0 && (isJavaIdentifier(searchPattern.substring(0, i)) || isInteger(searchPattern.substring(0, i)))) {
7  
    subBot = searchPattern.substring(i);
8  
    searchPattern = searchPattern.substring(0, i);
9  
    if (!isInteger(searchPattern))
10  
      searchPattern = "Multi-Port at " + searchPattern + ".";
11  
  }
12  
  
13  
  // assume it's a port if it's an integer
14  
  if (isInteger(searchPattern))
15  
    ret searchPattern + subBot;
16  
    
17  
  Integer port = findBot_cache.get(searchPattern);
18  
  if (port != null) try {
19  
    DialogIO io = talkTo("localhost", port);
20  
    try {
21  
      io.waitForLine(/*getBotAddress_timeout*/); // TODO: implement
22  
      S line = io.readLineNoBlock();
23  
      if (startsWithIgnoreCase(line, searchPattern))
24  
        ret port + subBot;
25  
    } finally {
26  
      io.close();
27  
    }
28  
  } catch (Exception e) {
29  
    e.printStackTrace();
30  
  }
31  
  
32  
  L<ProgramScan.Program> bots = quickBotScan();
33  
  
34  
  // find top-level bots
35  
  for (ProgramScan.Program p : bots) {
36  
    if (indexOfIgnoreCase(p.helloString, searchPattern) == 0) { // strict matching - start of hello string only, but case-insensitive
37  
      return p.port + subBot;
38  
    }
39  
  }
40  
  
41  
  // find sub-bots
42  
  for (ProgramScan.Program p : bots) {
43  
    S botName = firstPartOfHelloString(p.helloString);
44  
    boolean isVM = startsWithIgnoreCase(p.helloString, "This is a JavaX VM.");
45  
    boolean shouldRecurse = startsWithIgnoreCase(botName, "Multi-Port") || isVM;
46  
        
47  
    if (shouldRecurse) try {
48  
      Map<Number, S> subBots = unstructureMap_verboseError(sendToLocalBot(p.port, "list bots"));
49  
      for (Number vport : subBots.keySet()) {
50  
        S name = subBots.get(vport);
51  
        if (startsWithIgnoreCase(name, searchPattern))
52  
          ret p.port + "/" + vport;
53  
      }
54  
    } catch (Exception e) { e.printStackTrace(); }
55  
  }
56  
        
57  
  ret null;
58  
}

Author comment

Began life as a copy of #1001767

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009722
Snippet name: getBotAddress - old version
Eternal ID of this version: #1009722/1
Text MD5: 46e9936021000714ce3847b73295c84e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-15 17:08:02
Source code size: 1991 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 409 / 421
Referenced in: [show references]