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. Alternatively
34 * {@link #getURI()} can return a non-<code>null</code> value which signals
35 * that the request generated a URI. If none of those methods return
36 * <code>true</code>, you can use the block count methods to get detailed
37 * progress statistics. When progress you received is a {@link DownloadResult}
38 * you do not need to check
40 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
43 public class HighLevelProgress extends HighLevelResult {
45 /** Whether the request is finished. */
46 private boolean finished;
48 /** Whether a Put request should be fetchable now. */
49 private boolean fetchable;
51 /** The generated URI, in case of a Put request. */
54 /** The number of total blocks. */
55 private int totalBlocks;
57 /** The number of required blocks. */
58 private int requiredBlocks;
60 /** The number of successfully transferred blocks. */
61 private int successfulBlocks;
63 /** The number of failed blocks. */
64 private int failedBlocks;
66 /** The number of fatally failed blocks. */
67 private int fatallyFailedBlocks;
69 /** Whether the total number is finalized. */
70 private boolean totalFinalized;
73 * Package-private constructor.
76 * The identifier of the request
78 public HighLevelProgress(String identifier) {
83 * Creates a new high-level progress for a request that is finished.
86 * The identifier of the request
88 * <code>true</code> if the request finished successfully,
89 * <code>false</code> otherwise
91 public HighLevelProgress(String identifier, boolean successful) {
94 setFailed(!successful);
98 * Creates a new high-level progress for a Put or PutDir request that
102 * The identifier of the request
104 * The URI of the request
106 public HighLevelProgress(String identifier, String uri) {
112 * Creates a new high-level progress with the given values.
115 * The identifier of the request
117 * The total number of blocks
118 * @param requiredBlocks
119 * The number of required blocks
120 * @param successfulBlocks
121 * The number of successful blocks
122 * @param failedBlocks
123 * The number of failed blocks
124 * @param fatallyFailedBlocks
125 * The number of fatally failed blocks
126 * @param totalFinalized
127 * <code>true</code> if the total number of blocks is
128 * finalized, <code>false</code> otherwise
130 public HighLevelProgress(String identifier, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean totalFinalized) {
132 this.totalBlocks = totalBlocks;
133 this.requiredBlocks = requiredBlocks;
134 this.successfulBlocks = successfulBlocks;
135 this.failedBlocks = failedBlocks;
136 this.fatallyFailedBlocks = fatallyFailedBlocks;
137 this.totalFinalized = totalFinalized;
141 * Returns whether this progress means that a request has finished. Use
142 * {@link #isFailed()} to check if the request failed.
145 * @return <code>true</code> if the request has finished
147 public boolean isFinished() {
152 * Sets whether the request described by this progress has finished.
155 * <code>true</code> if the request has finished,
156 * <code>false</code> otherwise
158 void setFinished(boolean finished) {
159 this.finished = finished;
163 * Returns whether the request should be fetchable now, in case it was a Put
166 * @return <code>true</code> if the request should be fetchable now,
167 * <code>false</code> otherwise
169 public boolean isFetchable() {
174 * Sets whether the request should be fetchable now, in case it was a Put
178 * <code>true</code> if the request should be fetchable now,
179 * <code>false</code> otherwise
181 void setFetchable(boolean fetchable) {
182 this.fetchable = fetchable;
186 * Returns the URI that was generated by the request. Of course only Put and
187 * PutDir requests will generated URIs.
189 * @return The generated URI
191 public String getURI() {
196 * Sets the URI generated by the request.
201 void setURI(String uri) {
206 * Returns the number of total blocks.
208 * @return The number of total blocks
210 public int getTotalBlocks() {
215 * Sets the number of total blocks.
218 * The number of total blocks
220 void setTotalBlocks(int totalBlocks) {
221 this.totalBlocks = totalBlocks;
225 * Returns the number of required blocks. For downloads, this number is
226 * smaller than {@link #getTotalBlocks()}.
228 * @return The number of required blocks
230 public int getRequiredBlocks() {
231 return requiredBlocks;
235 * Sets the number of required blocks.
237 * @param requiredBlocks
238 * The number of required blocks
240 void setRequiredBlocks(int requiredBlocks) {
241 this.requiredBlocks = requiredBlocks;
245 * Returns the number of successfully transferred blocks.
247 * @return The number of successfully transferred blocks
249 public int getSuccessfulBlocks() {
250 return successfulBlocks;
254 * Sets the number of successfully transferred blocks.
256 * @param successfulBlocks
257 * The number of successfully transferred blocks
259 void setSuccessfulBlocks(int successfulBlocks) {
260 this.successfulBlocks = successfulBlocks;
264 * Returns the number of failed blocks. Blocks that have failed can be
267 * @return The number of failed blocks
269 public int getFailedBlocks() {
274 * Sets the number of failed blocks.
276 * @param failedBlocks
277 * The number of failed blocks
279 void setFailedBlocks(int failedBlocks) {
280 this.failedBlocks = failedBlocks;
284 * Returns the number of fatally failed blocks. Fatally failed blocks will
285 * never complete, even with endless retries.
287 * @return The number of fatally failed blocks
289 public int getFatallyFailedBlocks() {
290 return fatallyFailedBlocks;
294 * Sets the number of fatally failed blocks.
296 * @param fatallyFailedBlocks
297 * The number fatally failed blocks
299 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
300 this.fatallyFailedBlocks = fatallyFailedBlocks;
304 * Returns whether the result of {@link #getTotalBlocks()} is final, i.e. it
305 * won’t change anymore.
307 * @return <code>true</code> if the result of {@link #getTotalBlocks()} is
308 * final, <code>false</code> otherwise
310 public boolean isTotalFinalized() {
311 return totalFinalized;
315 * Sets whether the result of {@link #getTotalBlocks()} is final, i.e. it
316 * won’t change anymore.
318 * @param totalFinalized
319 * <code>true</code> if the result of {@link #getTotalBlocks()}
320 * is final, <code>false</code> otherwise
322 void setTotalFinalized(boolean totalFinalized) {
323 this.totalFinalized = totalFinalized;