1
|
package eu.dnetlib.data.search.utils.vocabulary;
|
2
|
|
3
|
import org.springframework.beans.factory.annotation.Autowired;
|
4
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
5
|
|
6
|
import javax.servlet.ServletContextEvent;
|
7
|
import javax.servlet.ServletContextListener;
|
8
|
import javax.servlet.annotation.WebListener;
|
9
|
import java.util.concurrent.Executors;
|
10
|
import java.util.concurrent.ScheduledExecutorService;
|
11
|
import java.util.concurrent.ScheduledFuture;
|
12
|
|
13
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
14
|
|
15
|
@WebListener
|
16
|
public class ResetVocabsScheduler implements ServletContextListener {
|
17
|
|
18
|
@Autowired
|
19
|
private String beautySleep;
|
20
|
|
21
|
@Autowired
|
22
|
private String begin;
|
23
|
|
24
|
@Autowired
|
25
|
private VocabularyManager vManager = null;
|
26
|
|
27
|
public VocabularyManager getvManager() {
|
28
|
return vManager;
|
29
|
}
|
30
|
|
31
|
public void setvManager(VocabularyManager vManager) {
|
32
|
this.vManager = vManager;
|
33
|
}
|
34
|
|
35
|
public String getBeautySleep() {
|
36
|
return beautySleep;
|
37
|
}
|
38
|
|
39
|
public void setBeautySleep(String beautySleep) {
|
40
|
this.beautySleep = beautySleep;
|
41
|
}
|
42
|
|
43
|
public String getBegin() {
|
44
|
return begin;
|
45
|
}
|
46
|
|
47
|
public void setBegin(String begin) {
|
48
|
this.begin = begin;
|
49
|
}
|
50
|
|
51
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
52
|
|
53
|
@Override
|
54
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
55
|
WebApplicationContextUtils
|
56
|
.getRequiredWebApplicationContext(servletContextEvent.getServletContext())
|
57
|
.getAutowireCapableBeanFactory()
|
58
|
.autowireBean(this);
|
59
|
|
60
|
final ResetVocabs reseter = new ResetVocabs();
|
61
|
reseter.setvManager(vManager);
|
62
|
final ScheduledFuture<?> resetHandle = scheduler.scheduleAtFixedRate(reseter,Integer.parseInt(begin), Integer.parseInt(beautySleep), SECONDS);
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
67
|
scheduler.shutdown();
|
68
|
}
|
69
|
|
70
|
}
|