/[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 2449 - (hide annotations) (download)
Fri Mar 20 08:58:46 2015 UTC (9 years, 2 months ago) by torben
File size: 1501 byte(s)
switch to maven
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.AccountingCircuitBreaker;
10     import dk.thoerup.circuitbreaker.CircuitBreaker;
11     import dk.thoerup.circuitbreaker.CircuitBreakerManager;
12 torben 1292 import dk.thoerup.circuitbreaker.LoggingCircuitBreaker;
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     AccountingCircuitBreaker acb = (AccountingCircuitBreaker) cb;
37     acb.resetCounters();
38     }
39 torben 1292
40     if (action.equalsIgnoreCase("clearlog") ) {
41     LoggingCircuitBreaker lcb = (LoggingCircuitBreaker) cb;
42     lcb.clearLog();
43     }
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