KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > utils > UpdateChannelInfo


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002-2003 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: UpdateChannelInfo.java,v 1.5 2004/07/01 08:12:58 spyromus Exp $
28

29 package de.nava.informa.utils;
30
31 /**
32  * Metadata class containing properties about channel updates.
33  *
34  * @author Niko Schmuck
35  */

36 public class UpdateChannelInfo {
37
38   private int nrProblemsOccurred;
39   private int deactivateAfterErrors;
40   private boolean formatDetected = false;
41   private Exception JavaDoc lastException;
42   private long lastUpdatedTimestamp = -1;
43
44   /**
45    * Constructor.
46    *
47    * @param deactivateAfterErrors Number of errors after which a channel should
48    * not any longer be parsed periodically. Specify 0, if you do not
49    * want auto-deactivation.
50    */

51   public UpdateChannelInfo(int deactivateAfterErrors) {
52     this.deactivateAfterErrors = deactivateAfterErrors;
53     this.reset();
54   }
55
56   /**
57    * @return Number of times a problem occurred while parsing a channel.
58    */

59   public int getNrProblemsOccurred() {
60     return nrProblemsOccurred;
61   }
62
63   /**
64    * @return Number of errors after a channel should be automatically
65    * deactivated.
66    */

67   public int getDeactivateAfterErrors() {
68     return deactivateAfterErrors;
69   }
70
71   /**
72    * @return The last exception that was captured when a channel problem
73    * occurred. May return null in the case no problem was reported yet.
74    */

75   public Exception JavaDoc getLastException() {
76     return lastException;
77   }
78
79   /**
80    * Resets the state, as if no problems ever occurred.
81    */

82   public void reset() {
83     this.nrProblemsOccurred = 0;
84     this.lastException = null;
85   }
86
87   /**
88    * Increases the number of times a channel could not be read.
89    *
90    * @param e The Exception causing the channel parse problem.
91    */

92   public synchronized void increaseProblemsOccurred(Exception JavaDoc e) {
93     this.lastException = e;
94     this.nrProblemsOccurred++;
95   }
96
97   /**
98    * Should the channel be deactivated?
99    *
100    * @return true in the case auto-deactivation is on and more errors have been
101    * reported than the given threshold.
102    */

103   public boolean shouldDeactivate() {
104     if (deactivateAfterErrors < 1) {
105       return false;
106     }
107     return (nrProblemsOccurred >= deactivateAfterErrors);
108   }
109
110   /**
111    * Has the feed been grabbed for the first time, and successfully parsed?
112    *
113    * @return true if format has been detected, and ChannelIF.getFormat
114    * would return a valid format.
115    */

116   public boolean getFormatDetected() {
117     return formatDetected;
118   }
119
120   public void setFormatDetected(boolean formatDetected) {
121     this.formatDetected = formatDetected;
122   }
123
124   // ===========================================================================
125

126   public String JavaDoc toString() {
127     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(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