1 26 27 29 package de.nava.informa.utils; 30 31 36 public class UpdateChannelInfo { 37 38 private int nrProblemsOccurred; 39 private int deactivateAfterErrors; 40 private boolean formatDetected = false; 41 private Exception lastException; 42 private long lastUpdatedTimestamp = -1; 43 44 51 public UpdateChannelInfo(int deactivateAfterErrors) { 52 this.deactivateAfterErrors = deactivateAfterErrors; 53 this.reset(); 54 } 55 56 59 public int getNrProblemsOccurred() { 60 return nrProblemsOccurred; 61 } 62 63 67 public int getDeactivateAfterErrors() { 68 return deactivateAfterErrors; 69 } 70 71 75 public Exception getLastException() { 76 return lastException; 77 } 78 79 82 public void reset() { 83 this.nrProblemsOccurred = 0; 84 this.lastException = null; 85 } 86 87 92 public synchronized void increaseProblemsOccurred(Exception e) { 93 this.lastException = e; 94 this.nrProblemsOccurred++; 95 } 96 97 103 public boolean shouldDeactivate() { 104 if (deactivateAfterErrors < 1) { 105 return false; 106 } 107 return (nrProblemsOccurred >= deactivateAfterErrors); 108 } 109 110 116 public boolean getFormatDetected() { 117 return formatDetected; 118 } 119 120 public void setFormatDetected(boolean formatDetected) { 121 this.formatDetected = formatDetected; 122 } 123 124 126 public String toString() { 127 StringBuffer sb = new StringBuffer (42); 128 sb.append("nr probs occurred: ").append(nrProblemsOccurred) 129 .append(", deactivate after ").append(deactivateAfterErrors) 130 .append(", format detected: ").append(formatDetected); 131 if (lastException != null) { 132 sb.append(", last exception: ").append(lastException.getMessage()); 133 } 134 return sb.toString(); 135 } 136 137 public long getLastUpdatedTimestamp() { 138 return lastUpdatedTimestamp; 139 } 140 141 public void setLastUpdatedTimestamp(long lastUpdatedTimestamp) { 142 this.lastUpdatedTimestamp = lastUpdatedTimestamp; 143 } 144 } 145 | Popular Tags |