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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3212 - (show annotations) (download)
Thu Dec 28 09:34:47 2017 UTC (6 years, 4 months ago) by torben
File size: 1542 byte(s)
Use generics to encapsulate returned value
1 package dk.thoerup.circuitbreaker.web;
2
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 import dk.thoerup.circuitbreaker.CircuitBreaker;
10 import dk.thoerup.circuitbreaker.CircuitBreakerManager;
11 import dk.thoerup.circuitbreaker.statistics.AccountingStatistics;
12 import dk.thoerup.circuitbreaker.statistics.LoggingStatistics;
13
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 AccountingStatistics stats = (AccountingStatistics) cb.getStatistics();
37 stats.resetCounters();
38 }
39
40 if (action.equalsIgnoreCase("clearlog") ) {
41 LoggingStatistics stats = (LoggingStatistics) cb.getStatistics();
42 stats.clearLog();
43 }
44 }
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