-
Notifications
You must be signed in to change notification settings - Fork 2
/
ApplicationInitializer.java
executable file
·103 lines (84 loc) · 3.1 KB
/
ApplicationInitializer.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
package in.eko.service;
import java.util.List;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import org.quartz.JobDetail;
import org.quartz.SchedulerException;
import in.eko.service.hibernate.HibernateDataAccess;
import in.eko.service.model.ConfigurationBO;
import in.eko.service.model.MockConfigBO;
import in.eko.service.model.ResponseCodeBO;
import in.eko.service.model.TaskConfigurationBO;
import in.eko.service.persistence.TransactionPersistence;
import in.eko.service.tasks.TaskSchedulerConstants;
import in.eko.service.tasks.TaskSchedulerService;
import in.eko.service.util.helper.StartupCache;
public class ApplicationInitializer
implements ServletContextListener {
private static Logger logger = Logger
.getLogger(ApplicationInitializer.class);
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
@Override
public void contextInitialized(ServletContextEvent ctx) {
init(ctx);
}
public void init(final ServletContextEvent servletContextEvent) {
try {
synchronized (ApplicationInitializer.class) {
ApplicationInitializer.initializeHibernate();
ApplicationInitializer.initializeConfigurations();
ApplicationInitializer.initializeMockConfig();
ApplicationInitializer.initializeResponseCode();
ApplicationInitializer.initializeTasks();
}
} catch (Exception e) {
throw new Error(e);
}
}
private static void initializeMockConfig() {
List<MockConfigBO> config = TransactionPersistence
.getInstance().getMockConfigurations();
for (MockConfigBO conf : config) {
StartupCache.getInstance().addToMockConfigMap(conf);
}
}
private static void initializeConfigurations() {
List<ConfigurationBO> config = TransactionPersistence.getInstance()
.getConfigurations();
for (ConfigurationBO conf : config) {
StartupCache.getInstance().addToConfigurationMap(conf);
}
}
public static void initializeHibernate() {
logger.info("Initialize hibernate.....logger");
HibernateDataAccess.buildSessionFactory("hibernate.cfg.xml");
}
private static void initializeResponseCode() {
List<ResponseCodeBO> config = TransactionPersistence.getInstance()
.getResponseCodes();
for (ResponseCodeBO conf : config) {
StartupCache.getInstance().addToResponseCodeMap(conf);
}
}
private static void initializeTasks() {
logger.info("Initialize initializeTasks.....");
TaskSchedulerService.getInstance().initializeScheduler();
List<TaskConfigurationBO> tasks = TransactionPersistence.getInstance().getAllTasks();
for(TaskConfigurationBO task : tasks){
StartupCache.getInstance().addToTaskConfigurationMap(task);
if (task.getStatus().intValue() == TaskSchedulerConstants.ACTIVE) {
JobDetail job = TaskSchedulerService.getInstance().getJobDetail(task.getTaskId());
try {
logger.info("Scheduling Task :"+task.getTaskId()+"\t Task Name : "+task.getTaskName());
TaskSchedulerService.getInstance().scheduleJob(job, task);
} catch (SchedulerException e) {
logger.info("Unable to schedule job : " + task.getTaskName());
e.printStackTrace();
}
}
}
}
}