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

29
LINES

< > BotCompany Repo | #1018973 // returnCodesOfServers_parallel_withTime

JavaX fragment (include)

1  
static ItIt<T3<S, Int, Long>> returnCodesOfServers_parallel_withTime(int timeout, S... servers) {
2  
  ret returnCodesOfServers_parallel_withTime(timeout, asList(servers));
3  
}
4  
5  
static ItIt<T3<S, Int, Long>> returnCodesOfServers_parallel_withTime(final int timeout, final Collection<S> servers) {
6  
  final Var<Int> counter = new(0);
7  
  final L<T3<S, Int, Long>> results = synchroList();
8  
  
9  
  // Fire up the threads (with timeouts)
10  
  
11  
  for (fS server : servers)
12  
    thread "Server Check" {
13  
      long time = sysTime();
14  
      int result = returnCodeHttpHEADWithTimeout(timeout, server);
15  
      results.add(t3(server, result, sysNow()-time));
16  
      syncIncIntVar(counter);
17  
    }
18  
    
19  
  // Make iterator delivering results as they come in
20  
  ret iteratorFromFunction(new F0<T3<S, Int, Long>>() {
21  
    int n = 0;
22  
    
23  
    public T3<S, Int, Long> get() {
24  
      if (n >= l(servers)) null;
25  
      waitForVarToChange(counter, n);
26  
      ret results.get(n++);
27  
    }
28  
  });
29  
}

Author comment

Began life as a copy of #1018972

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018973
Snippet name: returnCodesOfServers_parallel_withTime
Eternal ID of this version: #1018973/4
Text MD5: 86acf62699759ee09140c90d2332f21b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-18 16:53:51
Source code size: 982 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 342 / 353
Version history: 3 change(s)
Referenced in: [show references]