/[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 417 - (hide annotations) (download)
Thu Oct 8 07:07:14 2009 UTC (14 years, 8 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/curcuitbreaker/web/ActionCommand.java
File size: 1357 byte(s)
Finished v1 of web interface
1 torben 417 package dk.thoerup.curcuitbreaker.web;
2    
3     import java.io.IOException;
4     import java.io.UnsupportedEncodingException;
5     import java.net.URLEncoder;
6    
7     import javax.servlet.http.HttpServletRequest;
8     import javax.servlet.http.HttpServletResponse;
9    
10     import dk.thoerup.curcuitbreaker.AccountingCircuitBreaker;
11     import dk.thoerup.curcuitbreaker.CircuitBreaker;
12     import dk.thoerup.curcuitbreaker.CircuitBreakerManager;
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     AccountingCircuitBreaker acb = (AccountingCircuitBreaker) cb;
37     acb.resetCounters();
38     }
39     }
40    
41     try {
42     String uri = req.getRequestURI() + "?command=view&breaker=" + URLEncoder.encode(breaker, "UTF-8");
43    
44     resp.sendRedirect( uri );
45     } catch(IOException e) {
46     // what should be done here ?
47     }
48     return "";
49     }
50    
51     }

  ViewVC Help
Powered by ViewVC 1.1.20