1 |
package dk.daoas.daoadresseservice; |
package dk.daoas.daoadresseservice; |
2 |
|
|
3 |
import java.io.FileReader; |
import java.io.FileInputStream; |
4 |
import java.io.IOException; |
import java.io.IOException; |
5 |
|
import java.io.InputStreamReader; |
6 |
|
import java.io.Reader; |
7 |
|
import java.nio.charset.Charset; |
8 |
import java.util.Properties; |
import java.util.Properties; |
9 |
|
|
10 |
import javax.servlet.ServletContext; |
import javax.servlet.ServletContext; |
15 |
|
|
16 |
import org.apache.commons.lang3.SystemUtils; |
import org.apache.commons.lang3.SystemUtils; |
17 |
|
|
18 |
|
import com.jcabi.manifests.Manifests; |
19 |
|
import com.jcabi.manifests.ServletMfs; |
20 |
|
|
21 |
import dk.daoas.daoadresseservice.admin.ServiceConfig; |
import dk.daoas.daoadresseservice.admin.ServiceConfig; |
22 |
import dk.thoerup.circuitbreaker.AccountingCircuitBreaker; |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
23 |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
24 |
|
import dk.thoerup.circuitbreaker.statistics.AccountingStatistics; |
25 |
import dk.thoerup.circuitbreaker.web.CircuitBreakerServletBase; |
import dk.thoerup.circuitbreaker.web.CircuitBreakerServletBase; |
26 |
import dk.thoerup.webconfig.ConfigServlet; |
import dk.thoerup.webconfig.ConfigServlet; |
27 |
import dk.thoerup.webconfig.PropertiesConfigLoader; |
import dk.thoerup.webconfig.PropertiesConfigLoader; |
37 |
|
|
38 |
|
|
39 |
public ContextListener() { |
public ContextListener() { |
|
// TODO Auto-generated constructor stub |
|
40 |
} |
} |
41 |
|
|
42 |
public void contextDestroyed(ServletContextEvent ctxtEvt) { |
public void contextDestroyed(ServletContextEvent ctxtEvt) { |
|
// TODO Auto-generated method stub |
|
43 |
} |
} |
44 |
|
|
45 |
|
|
46 |
@Override |
@Override |
47 |
public void contextInitialized(ServletContextEvent ctxtEvt) { |
public void contextInitialized(ServletContextEvent ctxtEvt) { |
48 |
System.out.println("Starting DAO Context"); |
System.out.println("Starting DAO Context"); |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
ServletContext ctxt = ctxtEvt.getServletContext(); |
ServletContext ctxt = ctxtEvt.getServletContext(); |
53 |
|
|
54 |
ServiceConfig conf = null; |
ServiceConfig conf = null; |
62 |
initDataLoader(ctxt, conf); |
initDataLoader(ctxt, conf); |
63 |
|
|
64 |
initCircuitBreakers(ctxt, conf); |
initCircuitBreakers(ctxt, conf); |
65 |
|
|
66 |
|
|
67 |
|
try { |
68 |
|
Manifests.DEFAULT.append(new ServletMfs(ctxt)); |
69 |
|
} catch (Exception e) { |
70 |
|
System.out.println("Error loading config " + e.getMessage()); |
71 |
|
} |
72 |
|
|
73 |
System.out.println("DAO Context done"); |
System.out.println("DAO Context done"); |
74 |
} |
} |
91 |
} |
} |
92 |
|
|
93 |
Properties propsFile = new Properties(); |
Properties propsFile = new Properties(); |
94 |
try (FileReader reader = new FileReader(file) ) { |
try ( Reader reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")) ) { |
95 |
propsFile.load(reader); |
propsFile.load(reader); |
96 |
} |
} |
97 |
|
|
113 |
private void initDataLoader(ServletContext ctxt, ServiceConfig conf) { |
private void initDataLoader(ServletContext ctxt, ServiceConfig conf) { |
114 |
DataLoader load = new DataLoader(ctxt,conf); |
DataLoader load = new DataLoader(ctxt,conf); |
115 |
ctxt.setAttribute("dataloader", load); |
ctxt.setAttribute("dataloader", load); |
116 |
load.doLoad(); |
load.doLoad( "(re) deploy" ); |
117 |
} |
} |
118 |
|
|
119 |
private void initCircuitBreakers(ServletContext ctxt, ServiceConfig conf) { |
private void initCircuitBreakers(ServletContext ctxt, ServiceConfig conf) { |
120 |
CircuitBreakerManager mgr = CircuitBreakerManager.getManager(); |
CircuitBreakerManager mgr = CircuitBreakerManager.getManager(); |
121 |
|
|
122 |
AccountingCircuitBreaker osm = new AccountingCircuitBreaker("osm", conf); |
CircuitBreaker osm = new CircuitBreaker("osm", conf); |
123 |
|
osm.setStatistics( new AccountingStatistics() ); |
124 |
mgr.addCircuitBreaker( osm ); |
mgr.addCircuitBreaker( osm ); |
125 |
|
|
126 |
AccountingCircuitBreaker google = new AccountingCircuitBreaker("google", conf); |
CircuitBreaker google = new CircuitBreaker("google", conf); |
127 |
|
google.setStatistics( new AccountingStatistics() ); |
128 |
mgr.addCircuitBreaker( google ); |
mgr.addCircuitBreaker( google ); |
129 |
|
|
130 |
|
|