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

116
LINES

< > BotCompany Repo | #1001672 // Multi-Port (works, LIVE)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (4898L/33K/110K).

!752

static class Resp {
  long virtualPort;
  S botName;
  O responder;
}

static new List<Resp> responders;
static Android3 android;
static long nextVirtualPort = 1;

p {
  synchronized(getJavaX()) {
    if (!getMultiPorts().isEmpty()) return;
    if (!(boolean) call(getJavaX(), "addMultiPort", main.class)) {
      // XXX - hope this still works
      Android3 android = new Android3("Multi-Port at " + getVMID() + ".");
      android.useMultiPort = false;
      android.incomingSilent = true;
      android.console = false;
      makeAndroid3(android);
    }
  }
  print("Multi-Port registered with VM. Now " + l(getMultiPorts()) + " multi-port(s).");
}

static S answer(S s) {
  new Matches m;
  
  if (match3("list bots", s, m)) {
    ret structure(listBotsWithPort());
  }
  
  if (match3("has bot *", s, m)) {
    S name = m.unq(0);
    ret findResponder(name) != null ? "yes" : "no";
  }
  
  if (match3("silent", s, m)) {
    android.incomingSilent = true;
    ret "OK.";
  }
  
  if (match3("unsilent", s, m)) {
    android.incomingSilent = false;
    ret "OK.";
  }
  
  if (match3("please forward to bot *: *", s, m)) {
    S bot = unquote(m.m[0]);
    S line = unquote(m.m[1]);
    O responder = findResponder(bot);
    if (responder == null)
      ret "Error: bot not found";
    else
      ret (S) call(responder, "answer", line, litlist(s));
  }
  
  ret null;
}

static synchronized L<S> listBots() {
  new L<S> list;
  for (Resp r : responders)
    list.add(r.botName);
  ret list;
}

static synchronized Map<Long,S> listBotsWithPort() {
  new Map<Long,S> map;
  for (Resp r : responders)
    map.put(r.virtualPort, r.botName);
  ret map;
}

static synchronized O findResponder(S botName) {
  if (isInteger(botName)) {
    long vport = parseLong(botName);
    for (Resp r : responders)
      if (r.virtualPort == vport)
        ret r.responder;
  } else {
    for (Resp r : responders)
      if (startsWithIgnoreCase(r.botName, botName))
        ret r.responder;
  }
  ret null;
}
    
static synchronized long addResponder(S botName, O responder) {
  new Resp r;
  r.virtualPort = nextVirtualPort++;
  r.botName = botName;
  r.responder = responder;
  responders.add(r);
  ret r.virtualPort;
}

static synchronized void removeResponder(O responder) {
  for (int i = 0; i < l(responders); i++)
    if (responders.get(i).responder == responder) {
      //print("Responder removed.");
      responders.remove(i);
      ret;
    }
}

static synchronized void removePort(long virtualPort) {
  for (int i = 0; i < l(responders); i++)
    if (responders.get(i).virtualPort == virtualPort) {
      //print("Virtual port " + virtualPort + " removed.");
      responders.remove(i);
      ret;
    }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 151 computer(s): afvcxyesxakz, agxbjmyenqqu, aoiabmzegqzx, bfooyqadtzbb, bhatertpkbcr, bkpbhqsukdzp, brfxcrgsgrhg, cbybwowwnfue, cfunsshuasjs, connxhvfqtma, crvwmplrxojx, dbyzmesgzjrf, ddnzoavkxhuk, dhtvkmknsjym, digkpvzjadop, dlyzodsxvbls, doutfcgsyoqy, dsbpoofgtjnx, dtyaoxivooce, dvxvdlhqlwwc, dyfldxrfteug, ecqjixtmvxlp, egsshdfjpivr, etmzoiygucik, ezeddxofnljr, flwlchajcels, fnmrsykwqckh, funhxakgkfno, fvctnogetyww, gavnqejikrat, gbdqvketdppm, gqhbhyymrpxx, gsrwncdeurkl, gveowxfxqtil, gwrvuhgaqvyk, gzronoodcfmh, hkknpzsgoixq, honjdlwrmtdu, htkmirzsdzmu, hvbppbdwfhjy, idcfvzviszxn, ifxxhhcvckaw, igfbtfetlyvk, inzdgbwbursp, ipcmaqahdjtn, ishmyahliavo, ishqpsrjomds, ivagervvdxrj, jaezsmbrhigw, jgjqzccotruy, jlatgrcjtklg, jlfdhaxjyrpf, jrjpqrqxafhk, jtubtzbbkimh, jtwzfcwerbbv, jwlibnwemntm, kiawvgutsbre, ldywjnwigrac, ledgnsvlgdlr, lgdvxdgcpgrv, liwcxgsjrgqn, lnjhkqwteiwi, lpdgvwnxivlt, lqsqiistucwk, lsgdidgppwqq, lwfphbruhgtm, mdbqpbajgrux, mdefezkwdeup, meaqxkopohqc, mmaxggujatqf, mmmwsgafmleu, mnzieskfvskl, mqqgnosmbjvj, mrmohjpeebfc, nbgitpuheiab, ndavzgiapdkk, nmhwwpuvbanc, nrhsverhnpsn, nysugtttblhj, omkuifhlbvuf, omrbxrqoiqeh, omzkqqnokwlv, onfqjnomoxuw, onxytkatvevr, opsabzhijxss, owkcekpozlzc, pekvfmzvrlzt, pgppnpcqwliz, pidvqqudxurz, pnmttuucjkfb, ppwwtnwhztze, pyentgdyhuwx, pzhvpgtvlbxg, qdihqxvjryuq, qhcvkqotyiga, qhhqrodowzfo, qmupjbhcwcol, qnhezvwmdcbn, quisjpqxfggn, recxuykagbtt, rsdhgwlghzqg, sawdedvomwva, sksrqysvpwbz, skttnvmfkzhq, slhtubpyutdj, tcpfgdjhqqpe, teubizvjbppd, tjmheftkjvzt, tpcbwahvpzrm, tpdfwrfxnmsq, tslmcundralx, tsuzdeebumli, tvejysmllsmz, tvkpfieynkqz, twqnfdxxpuxv, txvdafyrfdei, txzhwycxdpzm, ucpxxyxryupy, umpqpbvfwjre, unkrhppcbqnk, uvkibmskjcsb, uwnvikuolobj, uzhyvevygbcc, uzolovmvtubr, vaduqbtgckcl, vdgqpiitesmp, vgjwidwdhwnw, vouqrxazstgt, vqblocesogdc, vqftxbmjmmzu, vxshqlgoesuw, vzpxdoxhqfnw, wglhsqxgxbdq, whwpvezoxzgq, winwedijdyqq, wltunwwkxhxr, wtjuwcnefrcw, wwghvftpbobq, xhsrmoityime, xprdwmaupziu, yabhydzhqlvs, ybmhnqzijvxm, yjcobudmfboh, yjprkgrpedlo, ymicnlqhuozx, yqkyyimflwur, yuicjtqnulgz, ywixcsqzavbw, zndhoewobdyk, zrzaeipbowrh, ztgjuucfqghy

No comments. add comment

Snippet ID: #1001672
Snippet name: Multi-Port (works, LIVE)
Eternal ID of this version: #1001672/1
Text MD5: 07290b7436bd3464a0dae1afcb2e4efb
Transpilation MD5: b6e5dc5d6f1afaab53ca209032030b93
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-21 11:41:32
Source code size: 2829 bytes / 116 lines
Pitched / IR pitched: No / No
Views / Downloads: 708 / 9065
Referenced in: #1001677 - startMultiPort
#1004182 - x30 for Android [stage 3, Java, LIVE]
#1004183 - Boot-up code for JavaX/Android (backup)
#1006632 - class MultiPort (multi-port as object)
#1007390 - x30 for Android (backup before multiport)
#2000584 - Test input for function finding
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)