package dk.thoerup.circuitbreaker.web; import java.io.IOException; import java.net.URLEncoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import dk.thoerup.circuitbreaker.CircuitBreaker; import dk.thoerup.circuitbreaker.CircuitBreakerManager; import dk.thoerup.circuitbreaker.statistics.AccountingStatistics; import dk.thoerup.circuitbreaker.statistics.LoggingStatistics; public class ActionCommand implements Command { private boolean readOnly; public ActionCommand(boolean readOnly) { this.readOnly = readOnly; } public String execute(HttpServletRequest req, HttpServletResponse resp) { String action = req.getParameter("action"); String breaker = req.getParameter("breaker"); CircuitBreaker cb = CircuitBreakerManager.getManager().getCircuitBreaker(breaker); if (readOnly == false) { if (action.equalsIgnoreCase("reset")) cb.reset(); if (action.equalsIgnoreCase("tripbreaker")) cb.tripBreaker(); if (action.equalsIgnoreCase("resetcounters")) { AccountingStatistics stats = (AccountingStatistics) cb.getStatistics(); stats.resetCounters(); } if (action.equalsIgnoreCase("clearlog") ) { LoggingStatistics stats = (LoggingStatistics) cb.getStatistics(); stats.clearLog(); } } try { String uri = req.getRequestURI() + "?command=view&breaker=" + URLEncoder.encode(breaker, "UTF-8"); resp.sendRedirect( uri ); } catch(IOException e) { // what should be done here ? } return ""; } }