-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckHealth.java
81 lines (64 loc) · 2.16 KB
/
CheckHealth.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.*;
import java.util.concurrent.*;
import java.io.*;
import java.time.*;
import java.time.format.DateTimeFormatter;
//import static avi.quit;
class CheckHealth {
static class Avi implements Runnable {
private int quit = 0;
public int getQuit(){
return quit;
}
Scanner sc = new Scanner(System.in);
@Override
public void run() {
String msg = "";
while(!(msg.toLowerCase().equals("q"))) {
try{
msg = sc.nextLine();
} catch(Exception e){
//
}
}
quit = 1;
}
}
private static ArrayList<Target> servers = new ArrayList<>();
private static Properties prop;
private static DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
private static int TIMEOUT = 5000;
private static int DELAY_SESSION = 15;
private static String DOMAINS_FILE_PATH = "domains.properties";
public static void main(String[] args) throws InterruptedException, IOException {
HealthConfig cfg = new HealthConfig();
prop = cfg.getProperties();
FORMATTER = DateTimeFormatter.ofPattern(prop.getProperty("formatter"));
TIMEOUT = Integer.parseInt(prop.getProperty("timeout"));
DELAY_SESSION = Integer.parseInt(prop.getProperty("delay"));
DOMAINS_FILE_PATH = prop.getProperty("domains");
FillDomains fill = new FillDomains();
fill.fill(servers, DOMAINS_FILE_PATH);
PingAction mainTask;
int proc_cores = Runtime.getRuntime().availableProcessors();
System.out.println("Available processors: " + proc_cores);
ForkJoinPool pool = new ForkJoinPool(proc_cores); // set values of parallelism
Avi avi = new Avi();
Thread mt = new Thread(avi);
mt.start();
while(true) {
mainTask = new PingAction(servers, 0, servers.size(), TIMEOUT);
System.out.printf( "%s - New session started (domains %d)%n", LocalDateTime.now().format(FORMATTER), servers.size() );
pool.invoke(mainTask);
System.out.printf(
"%s - All servers checked. Will wait for %d seconds until next round%n",
LocalDateTime.now().format(FORMATTER), DELAY_SESSION );
Thread.sleep(DELAY_SESSION * 1000);
// mt.sleep(1);
if(avi.getQuit() == 1) {
System.out.println("Quiting...");
break;
}
}
}
}