-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathJobInitializer.java
125 lines (110 loc) · 2.94 KB
/
JobInitializer.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.util.Random;
import job.Job;
public class JobInitializer {
final Random random;
private Job readConfig;
private Job readFromFile;
private Job readFromDb;
private Job httpReq;
public JobInitializer() {
this.random = new Random();
initJobs();
}
private int timeToWait() {
return random.nextInt(2000) + 1000;
}
private void initJobs() {
readConfig = (Job<String>) params -> {
if (params != null) {
System.out.println("reading config...with param " + params[0]);
} else {
System.out.println("reading config...");
}
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "some configuration";
};
readFromFile = (Job<String>) params -> {
System.out.println("reading File...");
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "some configuration";
};
readFromDb = (Job<String>) params -> {
System.out.println("accessing db...");
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "100 rows from db";
};
httpReq = (Job<String>) params -> {
if (params != null) {
System.out.println("trying to send request...Data = " + params[0]);
} else {
System.out.println("trying to send request...");
}
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "http://vk.com";
};
}
private String readConfig() {
System.out.println("reading config...");
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "some configuration";
}
private String readFromFile(String str) {
System.out.println("reading file." + str + "...");
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "file content";
}
private String readFromDb(String arg) {
System.out.println("accessing db." + arg + "...");
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "100 rows from db";
}
private String httpReq(String str) {
System.out.println("trying to send request." + str + "...");
try {
Thread.currentThread().sleep(timeToWait());
} catch (InterruptedException e) {
e.printStackTrace();
}
return "http://vk.com";
}
public Job getReadConfig() {
return readConfig;
}
public Job getReadFromFile() {
return readFromFile;
}
public Job getReadFromDb() {
return readFromDb;
}
public Job getHttpReq() {
return httpReq;
}
}