/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/CircuitBreakerListener.java
ViewVC logotype

Contents of /android/TrainInfoService/src/dk/thoerup/traininfoservice/CircuitBreakerListener.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1162 - (show annotations) (download)
Mon Oct 4 17:38:13 2010 UTC (13 years, 7 months ago) by torben
File size: 2082 byte(s)
use the latest change to the circuitbreaker library and use one notifier structure to both circuitbreakers
1 package dk.thoerup.traininfoservice;
2
3 import java.util.logging.Logger;
4
5 import javax.servlet.ServletContextEvent;
6 import javax.servlet.ServletContextListener;
7 import javax.servlet.annotation.WebListener;
8
9 import dk.thoerup.circuitbreaker.AccountingCircuitBreaker;
10 import dk.thoerup.circuitbreaker.CircuitBreakerManager;
11 import dk.thoerup.circuitbreaker.jmx.JMXWrapper;
12 import dk.thoerup.circuitbreaker.notification.*;
13
14
15 /**
16 * Application Lifecycle Listener implementation class JmxListener
17 *
18 */
19 @WebListener
20 public class CircuitBreakerListener implements ServletContextListener {
21
22 Logger logger = Logger.getLogger(CircuitBreakerListener.class.getName());
23
24 public CircuitBreakerListener() {
25 }
26
27 /**
28 * @see ServletContextListener#contextInitialized(ServletContextEvent)
29 */
30 public void contextInitialized(ServletContextEvent sce) {
31 logger.warning("Context Init");
32
33 int threshold = Integer.parseInt(sce.getServletContext().getInitParameter("banedk_threshold") );
34 int timeout = Integer.parseInt( sce.getServletContext().getInitParameter("banedk_timeout") );
35 CircuitBreakerManager mgr = CircuitBreakerManager.getManager();
36
37 CompositeNotifier notif = new CompositeNotifier();
38 notif.addNotifier( new JavaLogNotifier() );
39 notif.addNotifier( new MailNotifier("traininfo@t-hoerup.dk", "torben@t-hoerup.dk", "192.168.10.5") );
40
41
42 AccountingCircuitBreaker banedk = new AccountingCircuitBreaker("banedk", threshold, timeout);
43 banedk.setNotifier(notif);
44 mgr.addCircuitBreaker( banedk );
45
46
47 AccountingCircuitBreaker metro = new AccountingCircuitBreaker("metro", threshold, timeout);
48 metro.setNotifier(notif);
49 mgr.addCircuitBreaker( metro );
50
51 JMXWrapper.registerAllCircuitBreakers();
52 }
53
54 /**
55 * @see ServletContextListener#contextDestroyed(ServletContextEvent)
56 */
57 public void contextDestroyed(ServletContextEvent sce) {
58 logger.warning("Context Destroyed");
59 CircuitBreakerManager.getManager().shutdown();
60
61 JMXWrapper.unregisterAllCircuitBreakers();
62 }
63
64 }

  ViewVC Help
Powered by ViewVC 1.1.20