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

61
LINES

< > BotCompany Repo | #1016548 // OS Instances Long Poll Bot [LIVE, but we're using the socket version]

JavaX module [tags: butter use-pretranspiled] - homepage

Download Jar. Libraryless. Click here for Pure Java version (2549L/17K/64K).

1  
!7
2  
3  
set flag ExpiringMap2_debug.
4  
5  
static long timeout = 60000;
6  
static ExpiringMap2<S, Bool> recenctlyConnectedComputers_internal = new ExpiringMap2(5000, f updateValue);
7  
static new MultiSet<S> activeConnections;
8  
static Map<S, Bool> recentlyConnectedComputers = synchroMap(recenctlyConnectedComputers_internal);
9  
static Var<Int> connected2 = new(0);
10  
11  
svoid updateValue {
12  
  Set<S> set1 = keys(activeConnections);
13  
  Set<S> set2 = keys(recentlyConnectedComputers);
14  
  int n = l(mergeSets(set1, set2));
15  
  //int n = l(connectedComputers);
16  
  connected2.set(n);
17  
  print("Updated value to " + n + " (" + l(set1) + "/" + l(set2) + ")");
18  
}
19  
20  
p {  
21  
  // TODO (maybe): add countdown to ExpiringMap instead
22  
  doEvery(1000, r {
23  
    synchronized(recentlyConnectedComputers) {
24  
      recenctlyConnectedComputers_internal.clean();
25  
    }
26  
  });
27  
}
28  
29  
html {
30  
  int count = parseIntOpt(params.get('count));
31  
  fS computerID = or2(subBot_getHeader("X-ComputerID"), "unknown");
32  
  bool longPoll = params.get('count) != null;
33  
  if (computerID != null) {
34  
    activeConnections.add(computerID);
35  
    print("Have active connections from " + computerID + ": " + activeConnections.get(computerID));
36  
    updateValue();
37  
  }
38  
  temp tempAfterwards(r {
39  
    if (computerID != null) {
40  
      activeConnections.remove(computerID);
41  
      print("Disconnected. Have active connections from " + computerID + ": " + activeConnections.get(computerID));
42  
      updateValue();
43  
    }
44  
  });
45  
46  
  if (computerID != null)
47  
    print("Got connection from " + computerID);
48  
  
49  
  temp tempAfterwards(r {
50  
    if (computerID != null) {
51  
      print("Adding recently connected computer: " + computerID);
52  
      recentlyConnectedComputers.put(computerID, true);
53  
    }
54  
  });
55  
  
56  
  if (!longPoll) ret connected2!;
57  
  
58  
  print(connected2! + ", eq: " + eq(connected2!, count));
59  
  waitForVarToChange_withTimeout(connected2, count, timeout);
60  
  ret connected2!;
61  
}

Author comment

Began life as a copy of #1014866

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1016548
Snippet name: OS Instances Long Poll Bot [LIVE, but we're using the socket version]
Eternal ID of this version: #1016548/28
Text MD5: 674eda8b15b5c76457384244a0efb61f
Transpilation MD5: 172061d927da53b9aa7ff7535c1dbd59
Author: stefan
Category: javax / web
Type: JavaX module
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-18 16:51:12
Source code size: 1939 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 443 / 2125
Version history: 27 change(s)
Referenced in: [show references]