--- miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/web/ViewCircuitBreaker.java 2015/06/09 07:42:41 2568 +++ miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/web/ViewCircuitBreaker.java 2015/06/09 08:55:10 2569 @@ -7,10 +7,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import dk.thoerup.circuitbreaker.AccountingCircuitBreaker; -import dk.thoerup.circuitbreaker.LoggingCircuitBreaker; import dk.thoerup.circuitbreaker.CircuitBreaker; import dk.thoerup.circuitbreaker.CircuitBreakerManager; +import dk.thoerup.circuitbreaker.statistics.AccountingStatistics; +import dk.thoerup.circuitbreaker.statistics.LoggingStatistics; +import dk.thoerup.circuitbreaker.statistics.Statistics; public class ViewCircuitBreaker implements Command { @@ -63,12 +64,14 @@ if (breaker == null) return "

No breaker named '" + req.getParameter("breaker") + "'

"; + Statistics stats = breaker.getStatistics(); + StringBuilder sb = new StringBuilder(); sb.append("View Circuitbreaker"); sb.append("<<== Back to overview

"); sb.append("

CircuitBreaker

\n"); - + sb.append("Attributes:\n"); sb.append(""); @@ -76,17 +79,20 @@ sb.append("\n"); sb.append("\n"); sb.append("\n"); + sb.append("\n"); sb.append("\n"); sb.append("\n"); sb.append("\n"); sb.append("\n"); - if (breaker instanceof AccountingCircuitBreaker) { - AccountingCircuitBreaker acb = (AccountingCircuitBreaker) breaker; + + + if (stats instanceof AccountingStatistics) { + AccountingStatistics ac = (AccountingStatistics) stats; StringBuilder sbf = new StringBuilder(); - if (acb.getTotalCallCount() > 0) { - double failure_percentage = ((double) acb.getTotalFailureCount()*100) / ((double) acb.getTotalCallCount() ); + if (ac.getTotalCallCount() > 0) { + double failure_percentage = ((double) ac.getTotalFailureCount()*100) / ((double) ac.getTotalCallCount() ); Formatter formatter = new Formatter(sbf); formatter.format("%.2f", failure_percentage); formatter.close(); @@ -96,31 +102,31 @@ sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); - sb.append("\n"); + sb.append("\n"); } - if (breaker instanceof LoggingCircuitBreaker) { - LoggingCircuitBreaker lcb = (LoggingCircuitBreaker) breaker; + if (stats instanceof LoggingStatistics) { + LoggingStatistics ls = (LoggingStatistics) stats; - LinkedList list = lcb.getLog(); + LinkedList list = ls.getLog(); String headerLink = String.format("Logging", req.getRequestURI(), breaker.getName() ); sb.append("\n"); int max = list.size() > 10 ? 10 : list.size(); for (int i=0; i"); @@ -134,10 +140,10 @@ if ( !readOnly ) { sb.append( actionBuilder(uri, "reset", breaker.getName())).append("
\n"); sb.append( actionBuilder(uri, "tripBreaker", breaker.getName())).append("
\n"); - if (breaker instanceof AccountingCircuitBreaker ) { + if (stats instanceof AccountingStatistics ) { sb.append( actionBuilder(uri, "resetCounters", breaker.getName())).append("
\n"); } - if (breaker instanceof LoggingCircuitBreaker ) { + if (stats instanceof LoggingStatistics ) { sb.append( actionBuilder(uri, "clearLog", breaker.getName())).append("
\n"); } } else {
State ").append( getStateBar(breaker) ).append("
Type ").append(breaker.getClass().getSimpleName() ).append("
Notifier ").append(breaker.getNotifierName()).append("
Statistics ").append( stats.getClass().getSimpleName() ).append("
Failure count ").append(breaker.getFailureCount()).append("
Failure threshold ").append(breaker.getThreshold()).append("
Timeout, elapsed").append( breaker.getElapsed() ).append("
Timeout, limit").append( breaker.getTimeout() ).append("
Accounting
Trip count").append( acb.getTripCount() ).append("
Re-trip count").append( acb.getRetripCount() ).append("
Block count").append( acb.getBlockCount() ).append("
Total failure count").append( acb.getTotalFailureCount() ).append("
Total Call count").append( acb.getTotalCallCount() ).append("
Trip count").append( ac.getTripCount() ).append("
Re-trip count").append( ac.getRetripCount() ).append("
Block count").append( ac.getBlockCount() ).append("
Total failure count").append( ac.getTotalFailureCount() ).append("
Total Call count").append( ac.getTotalCallCount() ).append("
Failure Percentage").append( sbf.toString() ).append("%
Last failure").append( formatDate(acb.getLastFailure()) ).append("
Last trip").append( formatDate(acb.getLastTrip()) ).append("
Last re-trip").append( formatDate(acb.getLastRetrip()) ).append("
Last reset").append( formatDate(acb.getLastReset()) ).append("
Last failure").append( formatDate(ac.getLastFailure()) ).append("
Last trip").append( formatDate(ac.getLastTrip()) ).append("
Last re-trip").append( formatDate(ac.getLastRetrip()) ).append("
Last reset").append( formatDate(ac.getLastReset()) ).append("
Last resetCounters").append( formatDate(acb.getLastResetCounters()) ).append("
Last resetCounters").append( formatDate(ac.getLastResetCounters()) ).append("
").append(headerLink).append("
"); sb.append( entry.toString() ); sb.append("