001: //
002: // Informa -- RSS Library for Java
003: // Copyright (c) 2002-2003 by Niko Schmuck
004: //
005: // Niko Schmuck
006: // http://sourceforge.net/projects/informa
007: // mailto:niko_schmuck@users.sourceforge.net
008: //
009: // This library is free software.
010: //
011: // You may redistribute it and/or modify it under the terms of the GNU
012: // Lesser General Public License as published by the Free Software Foundation.
013: //
014: // Version 2.1 of the license should be included with this distribution in
015: // the file LICENSE. If the license is not included with this distribution,
016: // you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
017: // or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
018: // MA 02139 USA.
019: //
020: // This library is distributed in the hope that it will be useful,
021: // but WITHOUT ANY WARRANTY; without even the implied waranty of
022: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
023: // Lesser General Public License for more details.
024: //
025:
026: // $Id: UpdateChannelInfo.java,v 1.5 2004/07/01 08:12:58 spyromus Exp $
027:
028: package de.nava.informa.utils;
029:
030: /**
031: * Metadata class containing properties about channel updates.
032: *
033: * @author Niko Schmuck
034: */
035: public class UpdateChannelInfo {
036:
037: private int nrProblemsOccurred;
038: private int deactivateAfterErrors;
039: private boolean formatDetected = false;
040: private Exception lastException;
041: private long lastUpdatedTimestamp = -1;
042:
043: /**
044: * Constructor.
045: *
046: * @param deactivateAfterErrors Number of errors after which a channel should
047: * not any longer be parsed periodically. Specify 0, if you do not
048: * want auto-deactivation.
049: */
050: public UpdateChannelInfo(int deactivateAfterErrors) {
051: this .deactivateAfterErrors = deactivateAfterErrors;
052: this .reset();
053: }
054:
055: /**
056: * @return Number of times a problem occurred while parsing a channel.
057: */
058: public int getNrProblemsOccurred() {
059: return nrProblemsOccurred;
060: }
061:
062: /**
063: * @return Number of errors after a channel should be automatically
064: * deactivated.
065: */
066: public int getDeactivateAfterErrors() {
067: return deactivateAfterErrors;
068: }
069:
070: /**
071: * @return The last exception that was captured when a channel problem
072: * occurred. May return null in the case no problem was reported yet.
073: */
074: public Exception getLastException() {
075: return lastException;
076: }
077:
078: /**
079: * Resets the state, as if no problems ever occurred.
080: */
081: public void reset() {
082: this .nrProblemsOccurred = 0;
083: this .lastException = null;
084: }
085:
086: /**
087: * Increases the number of times a channel could not be read.
088: *
089: * @param e The Exception causing the channel parse problem.
090: */
091: public synchronized void increaseProblemsOccurred(Exception e) {
092: this .lastException = e;
093: this .nrProblemsOccurred++;
094: }
095:
096: /**
097: * Should the channel be deactivated?
098: *
099: * @return true in the case auto-deactivation is on and more errors have been
100: * reported than the given threshold.
101: */
102: public boolean shouldDeactivate() {
103: if (deactivateAfterErrors < 1) {
104: return false;
105: }
106: return (nrProblemsOccurred >= deactivateAfterErrors);
107: }
108:
109: /**
110: * Has the feed been grabbed for the first time, and successfully parsed?
111: *
112: * @return true if format has been detected, and ChannelIF.getFormat
113: * would return a valid format.
114: */
115: public boolean getFormatDetected() {
116: return formatDetected;
117: }
118:
119: public void setFormatDetected(boolean formatDetected) {
120: this .formatDetected = formatDetected;
121: }
122:
123: // ===========================================================================
124:
125: public String toString() {
126: StringBuffer sb = new StringBuffer(42);
127: sb.append("nr probs occurred: ").append(nrProblemsOccurred)
128: .append(", deactivate after ").append(
129: deactivateAfterErrors).append(
130: ", format detected: ").append(formatDetected);
131: if (lastException != null) {
132: sb.append(", last exception: ").append(
133: lastException.getMessage());
134: }
135: return sb.toString();
136: }
137:
138: public long getLastUpdatedTimestamp() {
139: return lastUpdatedTimestamp;
140: }
141:
142: public void setLastUpdatedTimestamp(long lastUpdatedTimestamp) {
143: this.lastUpdatedTimestamp = lastUpdatedTimestamp;
144: }
145: }
|