1 |
package dk.thoerup.circuitbreaker.web; |
2 |
|
3 |
import java.util.LinkedList; |
4 |
|
5 |
import javax.servlet.http.HttpServletRequest; |
6 |
import javax.servlet.http.HttpServletResponse; |
7 |
|
8 |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
9 |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
10 |
import dk.thoerup.circuitbreaker.statistics.LoggingStatistics; |
11 |
|
12 |
public class LogViewCommand implements Command{ |
13 |
|
14 |
public String execute(HttpServletRequest req, HttpServletResponse resp) { |
15 |
String breakerName = req.getParameter("breaker"); |
16 |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker(breakerName); |
17 |
|
18 |
if (breaker == null) |
19 |
return "<html><body><h2>No breaker named '" + breakerName + "'</h2></body></html>"; |
20 |
|
21 |
LoggingStatistics stats = (LoggingStatistics) breaker.getStatistics(); |
22 |
|
23 |
|
24 |
StringBuilder sb = new StringBuilder(); |
25 |
|
26 |
sb.append("<html><head><title>Circuitbreaker Log</title></head><body>"); |
27 |
sb.append("<<== <a href=\"").append(req.getRequestURI()).append("?command=view&breaker=").append(breakerName).append("\">Back</a><br><br>"); |
28 |
sb.append("<h2>CircuitBreaker Log : ").append(breakerName).append("</h2>\n"); |
29 |
|
30 |
sb.append("<table border=\"1\" cellspacing=0>"); |
31 |
|
32 |
|
33 |
LinkedList<LoggingStatistics.LogEntry> list = stats.getLog(); |
34 |
for (LoggingStatistics.LogEntry entry : list) { |
35 |
sb.append("<tr><td colspan=\"2\">"); |
36 |
sb.append( entry.toString() ); |
37 |
sb.append("</td></tr>"); |
38 |
} |
39 |
|
40 |
|
41 |
sb.append("</table>"); |
42 |
|
43 |
return sb.toString(); |
44 |
} |
45 |
|
46 |
} |