1
1
package codeine .servlets ;
2
2
3
+ import codeine .configuration .IConfigurationManager ;
4
+ import codeine .executer .ThreadPoolUtils ;
5
+ import codeine .jsons .global .GlobalConfigurationJsonStore ;
6
+ import codeine .model .Constants .UrlParameters ;
7
+ import codeine .nodes .NodesRunner ;
8
+ import codeine .servlet .AbstractServlet ;
9
+ import com .google .inject .Inject ;
3
10
import java .io .IOException ;
4
11
import java .util .Random ;
5
12
import java .util .concurrent .ExecutorService ;
6
13
import java .util .concurrent .TimeUnit ;
7
-
8
14
import javax .servlet .ServletException ;
9
- import javax .servlet .http .HttpServlet ;
10
15
import javax .servlet .http .HttpServletRequest ;
11
16
import javax .servlet .http .HttpServletResponse ;
12
-
13
- import codeine .executer .ThreadPoolUtils ;
14
17
import org .apache .log4j .Logger ;
15
18
16
- import codeine .configuration .IConfigurationManager ;
17
- import codeine .nodes .NodesRunner ;
18
-
19
- import com .google .inject .Inject ;
20
- import sun .nio .ch .ThreadPool ;
21
-
22
- public class ReloadConfigurationServlet extends HttpServlet {
19
+ public class ReloadConfigurationServlet extends AbstractServlet {
23
20
private static final Logger log = Logger .getLogger (ReloadConfigurationServlet .class );
24
21
private static final long serialVersionUID = 1L ;
25
22
@ Inject
26
23
private NodesRunner nodesRunner ;
27
24
@ Inject
28
25
private IConfigurationManager configurationManager ;
26
+ @ Inject
27
+ private GlobalConfigurationJsonStore globalConfigurationJsonStore ;
29
28
private ExecutorService threadPool = ThreadPoolUtils .newThreadPool (1 , "ReloadConfigurationServlet" );
30
29
31
30
@ Override
32
31
public void doGet (HttpServletRequest req , HttpServletResponse res ) throws ServletException , IOException {
33
32
log .info ("ReloadConfigurationServlet called" );
33
+ String parameter = UrlParameters .SYNC_REQUEST ;
34
+ boolean isSync = Boolean .parseBoolean (getParameter (req , parameter ));
34
35
Runnable thread = new Runnable () {
35
36
@ Override
36
37
public void run () {
37
38
try {
38
- int millis = new Random ().nextInt ((int ) TimeUnit .MINUTES .toMillis (1 ));
39
+ long duration = globalConfigurationJsonStore .get ().large_deployment () ? 60 : 25 ;
40
+ int millis = new Random ().nextInt ((int ) TimeUnit .SECONDS .toMillis (duration ));
39
41
log .info ("ReloadConfigurationServlet going to sleep " + millis );
40
42
Thread .sleep (millis );
41
43
} catch (InterruptedException e ) {
@@ -46,7 +48,18 @@ public void run() {
46
48
log .info ("ReloadConfigurationServlet async finished" );
47
49
}
48
50
};
49
- threadPool .submit (thread );
51
+ if (isSync ) {
52
+ log .info ("Running is sync mode" );
53
+ thread .run ();
54
+ }
55
+ else {
56
+ threadPool .submit (thread );
57
+ }
50
58
res .getWriter ().print ("{result:'OK'}" );
51
59
}
60
+
61
+ @ Override
62
+ protected boolean checkPermissions (HttpServletRequest request ) {
63
+ return true ;
64
+ }
52
65
}
0 commit comments