Libraryless. Click here for Pure Java version (4898L/33K/110K).
1 | !752 |
2 | |
3 | static class Resp { |
4 | long virtualPort; |
5 | S botName; |
6 | O responder; |
7 | } |
8 | |
9 | static new List<Resp> responders; |
10 | static Android3 android; |
11 | static long nextVirtualPort = 1; |
12 | |
13 | p { |
14 | synchronized(getJavaX()) { |
15 | if (!getMultiPorts().isEmpty()) return; |
16 | if (!(boolean) call(getJavaX(), "addMultiPort", main.class)) { |
17 | // XXX - hope this still works |
18 | Android3 android = new Android3("Multi-Port at " + getVMID() + "."); |
19 | android.useMultiPort = false; |
20 | android.incomingSilent = true; |
21 | android.console = false; |
22 | makeAndroid3(android); |
23 | } |
24 | } |
25 | print("Multi-Port registered with VM. Now " + l(getMultiPorts()) + " multi-port(s)."); |
26 | } |
27 | |
28 | static S answer(S s) { |
29 | new Matches m; |
30 | |
31 | if (match3("list bots", s, m)) { |
32 | ret structure(listBotsWithPort()); |
33 | } |
34 | |
35 | if (match3("has bot *", s, m)) { |
36 | S name = m.unq(0); |
37 | ret findResponder(name) != null ? "yes" : "no"; |
38 | } |
39 | |
40 | if (match3("silent", s, m)) { |
41 | android.incomingSilent = true; |
42 | ret "OK."; |
43 | } |
44 | |
45 | if (match3("unsilent", s, m)) { |
46 | android.incomingSilent = false; |
47 | ret "OK."; |
48 | } |
49 | |
50 | if (match3("please forward to bot *: *", s, m)) { |
51 | S bot = unquote(m.m[0]); |
52 | S line = unquote(m.m[1]); |
53 | O responder = findResponder(bot); |
54 | if (responder == null) |
55 | ret "Error: bot not found"; |
56 | else |
57 | ret (S) call(responder, "answer", line, litlist(s)); |
58 | } |
59 | |
60 | ret null; |
61 | } |
62 | |
63 | static synchronized L<S> listBots() { |
64 | new L<S> list; |
65 | for (Resp r : responders) |
66 | list.add(r.botName); |
67 | ret list; |
68 | } |
69 | |
70 | static synchronized Map<Long,S> listBotsWithPort() { |
71 | new Map<Long,S> map; |
72 | for (Resp r : responders) |
73 | map.put(r.virtualPort, r.botName); |
74 | ret map; |
75 | } |
76 | |
77 | static synchronized O findResponder(S botName) { |
78 | if (isInteger(botName)) { |
79 | long vport = parseLong(botName); |
80 | for (Resp r : responders) |
81 | if (r.virtualPort == vport) |
82 | ret r.responder; |
83 | } else { |
84 | for (Resp r : responders) |
85 | if (startsWithIgnoreCase(r.botName, botName)) |
86 | ret r.responder; |
87 | } |
88 | ret null; |
89 | } |
90 | |
91 | static synchronized long addResponder(S botName, O responder) { |
92 | new Resp r; |
93 | r.virtualPort = nextVirtualPort++; |
94 | r.botName = botName; |
95 | r.responder = responder; |
96 | responders.add(r); |
97 | ret r.virtualPort; |
98 | } |
99 | |
100 | static synchronized void removeResponder(O responder) { |
101 | for (int i = 0; i < l(responders); i++) |
102 | if (responders.get(i).responder == responder) { |
103 | //print("Responder removed."); |
104 | responders.remove(i); |
105 | ret; |
106 | } |
107 | } |
108 | |
109 | static synchronized void removePort(long virtualPort) { |
110 | for (int i = 0; i < l(responders); i++) |
111 | if (responders.get(i).virtualPort == virtualPort) { |
112 | //print("Virtual port " + virtualPort + " removed."); |
113 | responders.remove(i); |
114 | ret; |
115 | } |
116 | } |
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: | 709 / 9066 |
Referenced in: | [show references] |