2 * jFCPlib-high-level-client - HighLevelContinuosResult.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.fcp.highlevel;
23 * Result for operations that send progress messages until they have completed.
24 * The fields of the progress message has to be checked in given order because
25 * if you receive this progress asynchronously via a
26 * {@link HighLevelProgressListener} the progress will not have any state, you
27 * will simply get the latest results, with other fields unset. First you should
28 * check whether {@link #isFinished()} returns <code>true</code>. If it does,
29 * the request is finished and {@link #isFailed()} will tell you whether the
30 * request has failed or succeeded. Other fields are not set. If the request is
31 * not yet finished, {@link #isFetchable()} will tell you whether the request
32 * has progressed to a state that allows other clients to fetch the inserted
33 * data. This is of course only valid for Put and PutDir requests. If none of
34 * those methods return <code>true</code>, you can use the block count
35 * methods to get detailed progress statistics. When progress you received is a
36 * {@link DownloadResult} you do not need to check
38 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
41 public class HighLevelProgress extends HighLevelResult {
43 /** Whether the request is finished. */
44 private boolean finished;
46 /** Whether a Put request should be fetchable now. */
47 private boolean fetchable;
49 /** The number of total blocks. */
50 private int totalBlocks;
52 /** The number of required blocks. */
53 private int requiredBlocks;
55 /** The number of successfully transferred blocks. */
56 private int successfulBlocks;
58 /** The number of failed blocks. */
59 private int failedBlocks;
61 /** The number of fatally failed blocks. */
62 private int fatallyFailedBlocks;
64 /** Whether the total number is finalized. */
65 private boolean totalFinalized;
68 * Package-private constructor.
71 * The identifier of the request
73 public HighLevelProgress(String identifier) {
78 * Creates a new high-level progress for a request that is finished.
81 * The identifier of the request
83 * <code>true</code> if the request finished successfully,
84 * <code>false</code> otherwise
86 public HighLevelProgress(String identifier, boolean successful) {
89 setFailed(!successful);
93 * Creates a new high-level progress with the given values.
96 * The identifier of the request
98 * The total number of blocks
99 * @param requiredBlocks
100 * The number of required blocks
101 * @param successfulBlocks
102 * The number of successful blocks
103 * @param failedBlocks
104 * The number of failed blocks
105 * @param fatallyFailedBlocks
106 * The number of fatally failed blocks
107 * @param totalFinalized
108 * <code>true</code> if the total number of blocks is
109 * finalized, <code>false</code> otherwise
111 public HighLevelProgress(String identifier, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean totalFinalized) {
113 this.totalBlocks = totalBlocks;
114 this.requiredBlocks = requiredBlocks;
115 this.successfulBlocks = successfulBlocks;
116 this.failedBlocks = failedBlocks;
117 this.fatallyFailedBlocks = fatallyFailedBlocks;
118 this.totalFinalized = totalFinalized;
122 * Returns whether this progress means that a request has finished. Use
123 * {@link #isFailed()} to check if the request failed.
126 * @return <code>true</code> if the request has finished
128 public boolean isFinished() {
133 * Sets whether the request described by this progress has finished.
136 * <code>true</code> if the request has finished,
137 * <code>false</code> otherwise
139 void setFinished(boolean finished) {
140 this.finished = finished;
144 * Returns whether the request should be fetchable now, in case it was a Put
147 * @return <code>true</code> if the request should be fetchable now,
148 * <code>false</code> otherwise
150 public boolean isFetchable() {
155 * Sets whether the request should be fetchable now, in case it was a Put
159 * <code>true</code> if the request should be fetchable now,
160 * <code>false</code> otherwise
162 void setFetchable(boolean fetchable) {
163 this.fetchable = fetchable;
167 * Returns the number of total blocks.
169 * @return The number of total blocks
171 public int getTotalBlocks() {
176 * Sets the number of total blocks.
179 * The number of total blocks
181 void setTotalBlocks(int totalBlocks) {
182 this.totalBlocks = totalBlocks;
186 * Returns the number of required blocks. For downloads, this number is
187 * smaller than {@link #getTotalBlocks()}.
189 * @return The number of required blocks
191 public int getRequiredBlocks() {
192 return requiredBlocks;
196 * Sets the number of required blocks.
198 * @param requiredBlocks
199 * The number of required blocks
201 void setRequiredBlocks(int requiredBlocks) {
202 this.requiredBlocks = requiredBlocks;
206 * Returns the number of successfully transferred blocks.
208 * @return The number of successfully transferred blocks
210 public int getSuccessfulBlocks() {
211 return successfulBlocks;
215 * Sets the number of successfully transferred blocks.
217 * @param successfulBlocks
218 * The number of successfully transferred blocks
220 void setSuccessfulBlocks(int successfulBlocks) {
221 this.successfulBlocks = successfulBlocks;
225 * Returns the number of failed blocks. Blocks that have failed can be
228 * @return The number of failed blocks
230 public int getFailedBlocks() {
235 * Sets the number of failed blocks.
237 * @param failedBlocks
238 * The number of failed blocks
240 void setFailedBlocks(int failedBlocks) {
241 this.failedBlocks = failedBlocks;
245 * Returns the number of fatally failed blocks. Fatally failed blocks will
246 * never complete, even with endless retries.
248 * @return The number of fatally failed blocks
250 public int getFatallyFailedBlocks() {
251 return fatallyFailedBlocks;
255 * Sets the number of fatally failed blocks.
257 * @param fatallyFailedBlocks
258 * The number fatally failed blocks
260 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
261 this.fatallyFailedBlocks = fatallyFailedBlocks;
265 * Returns whether the result of {@link #getTotalBlocks()} is final, i.e. it
266 * won’t change anymore.
268 * @return <code>true</code> if the result of {@link #getTotalBlocks()} is
269 * final, <code>false</code> otherwise
271 public boolean isTotalFinalized() {
272 return totalFinalized;
276 * Sets whether the result of {@link #getTotalBlocks()} is final, i.e. it
277 * won’t change anymore.
279 * @param totalFinalized
280 * <code>true</code> if the result of {@link #getTotalBlocks()}
281 * is final, <code>false</code> otherwise
283 void setTotalFinalized(boolean totalFinalized) {
284 this.totalFinalized = totalFinalized;