/[projects]/miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/web/ActionCommand.java
ViewVC logotype

Annotation of /miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/web/ActionCommand.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2569 - (hide annotations) (download)
Tue Jun 9 08:55:10 2015 UTC (8 years, 11 months ago) by torben
File size: 1539 byte(s)
Statistics should be added by composition instead of inheritance
1 torben 467 package dk.thoerup.circuitbreaker.web;
2 torben 417
3     import java.io.IOException;
4     import java.net.URLEncoder;
5    
6     import javax.servlet.http.HttpServletRequest;
7     import javax.servlet.http.HttpServletResponse;
8    
9 torben 467 import dk.thoerup.circuitbreaker.CircuitBreaker;
10     import dk.thoerup.circuitbreaker.CircuitBreakerManager;
11 torben 2569 import dk.thoerup.circuitbreaker.statistics.AccountingStatistics;
12     import dk.thoerup.circuitbreaker.statistics.LoggingStatistics;
13 torben 417
14     public class ActionCommand implements Command {
15    
16     private boolean readOnly;
17    
18     public ActionCommand(boolean readOnly) {
19     this.readOnly = readOnly;
20     }
21    
22     public String execute(HttpServletRequest req, HttpServletResponse resp) {
23     String action = req.getParameter("action");
24     String breaker = req.getParameter("breaker");
25    
26     CircuitBreaker cb = CircuitBreakerManager.getManager().getCircuitBreaker(breaker);
27    
28     if (readOnly == false) {
29     if (action.equalsIgnoreCase("reset"))
30     cb.reset();
31    
32     if (action.equalsIgnoreCase("tripbreaker"))
33     cb.tripBreaker();
34    
35     if (action.equalsIgnoreCase("resetcounters")) {
36 torben 2569 AccountingStatistics stats = (AccountingStatistics) cb.getStatistics();
37     stats.resetCounters();
38 torben 417 }
39 torben 1292
40     if (action.equalsIgnoreCase("clearlog") ) {
41 torben 2569 LoggingStatistics stats = (LoggingStatistics) cb.getStatistics();
42     stats.clearLog();
43 torben 1292 }
44 torben 417 }
45    
46     try {
47     String uri = req.getRequestURI() + "?command=view&breaker=" + URLEncoder.encode(breaker, "UTF-8");
48    
49     resp.sendRedirect( uri );
50     } catch(IOException e) {
51     // what should be done here ?
52     }
53     return "";
54     }
55    
56     }

  ViewVC Help
Powered by ViewVC 1.1.20