You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/08/16 11:10:17 UTC

svn commit: r1514626 - in /sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api: Result.java ResultLog.java

Author: cziegeler
Date: Fri Aug 16 09:10:17 2013
New Revision: 1514626

URL: http://svn.apache.org/r1514626
Log:
SLING-3020 - Result is now immutable

Modified:
    sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/Result.java
    sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/ResultLog.java

Modified: sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/Result.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/Result.java?rev=1514626&r1=1514625&r2=1514626&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/Result.java (original)
+++ sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/Result.java Fri Aug 16 09:10:17 2013
@@ -23,7 +23,7 @@ import java.util.Iterator;
 public class Result implements Iterable <ResultLog.Entry> {
 
     private final ResultLog resultLog;
-    
+
     public enum Status {
         DEBUG,              // used by ResultLog for debug messages, not an actual output status
         INFO,               // used by ResultLog for info messages, not an actual output status
@@ -32,33 +32,34 @@ public class Result implements Iterable 
         CRITICAL,           // health check detected a critical problem
         HEALTH_CHECK_ERROR  // health check did not execute properly
     }
-    
-    /** Build a single-value Result 
+
+    /** Build a single-value Result
      *  @param s if lower than OK, our status is set to OK */
-    public Result(Status s, String explanation) {
+    public Result(final Status s, final String explanation) {
         resultLog = new ResultLog().add(new ResultLog.Entry(s, explanation));
     }
 
     /** Build a a Result based on a ResultLog, which can provide
      *  more details than a single-value Result.
      */
-    public Result(ResultLog log) {
-        resultLog = log;
+    public Result(final ResultLog log) {
+        resultLog = new ResultLog(log);
     }
-    
-    /** True if our status is OK - provides a convenient way of 
+
+    /** True if our status is OK - provides a convenient way of
      *  checking that.
      */
     public boolean isOk() {
         return getStatus().equals(Status.OK);
     }
-    
+
     /** Return our Status */
     public Status getStatus() {
         return resultLog.getAggregateStatus();
     }
-    
+
     /** Return an Iterator on the entries of our ResultLog */
+    @Override
     public Iterator<ResultLog.Entry> iterator() {
         return resultLog.iterator();
     }

Modified: sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/ResultLog.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/ResultLog.java?rev=1514626&r1=1514625&r2=1514626&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/ResultLog.java (original)
+++ sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/api/ResultLog.java Fri Aug 16 09:10:17 2013
@@ -17,6 +17,7 @@
  */
 package org.apache.sling.hc.api;
 
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -26,15 +27,15 @@ import org.apache.sling.hc.api.Result.St
 /** The log of a Result, allows for providing multiple lines
  *  of information which are aggregated as a single Result. */
 public class ResultLog implements Iterable<ResultLog.Entry> {
-    
+
     private List<Entry> entries = new LinkedList<Entry>();
     private Status aggregateStatus;
-    
+
     /** An entry in this log */
     public static class Entry {
         private final Status status;
         private final String message;
-        
+
         public Entry(Status s, String message) {
             this.status = s;
             this.message = message;
@@ -44,17 +45,17 @@ public class ResultLog implements Iterab
         public String toString() {
             return new StringBuilder(status.toString()).append(" ").append(message).toString();
         }
-        
+
         public Status getStatus() {
             return status;
         }
-        
+
         public String getMessage() {
             return message;
         }
     }
-    
-    /** Build a log. Initial aggregate status is 
+
+    /** Build a log. Initial aggregate status is
      *  set to WARN, as an empty log is not considered ok.
      *  That's reset to OK before adding the first log entry,
      *  and then the status aggregation rules take over.
@@ -63,7 +64,15 @@ public class ResultLog implements Iterab
         aggregateStatus = Result.Status.WARN;
     }
 
-    /** Add an entry to this log. The aggregate status of 
+    /**
+     * Create a copy of the result log
+     */
+    public ResultLog(final ResultLog log) {
+        this.aggregateStatus = log.aggregateStatus;
+        this.entries = new ArrayList<ResultLog.Entry>(log.entries);
+    }
+
+    /** Add an entry to this log. The aggregate status of
      *  this is set to the highest of the current aggregate status
      *  and the new Entry's status */
     public ResultLog add(Entry e) {
@@ -76,12 +85,13 @@ public class ResultLog implements Iterab
         }
         return this;
     }
-    
+
     /** Return an Iterator on our entries */
+    @Override
     public Iterator<ResultLog.Entry> iterator() {
         return entries.iterator();
     }
-    
+
     /** Return our aggregate status, i.e. the highest status
      *  of the entries added to this log. Starts at OK for an
      *  empty ResultLog, so cannot be lower than that.