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>
42 public class HighLevelProgress extends HighLevelResult {
44 /** Whether the request is finished. */
45 private boolean finished;
47 /** Whether a Put request should be fetchable now. */
48 private boolean fetchable;
50 /** The generated URI, in case of a Put request. */
53 /** The number of total blocks. */
54 private int totalBlocks;
56 /** The number of required blocks. */
57 private int requiredBlocks;
59 /** The number of successfully transferred blocks. */
60 private int successfulBlocks;
62 /** The number of failed blocks. */
63 private int failedBlocks;
65 /** The number of fatally failed blocks. */
66 private int fatallyFailedBlocks;
68 /** Whether the total number is finalized. */
69 private boolean totalFinalized;
72 * Package-private constructor.
75 * The identifier of the request
77 public HighLevelProgress(String identifier) {
82 * Creates a new high-level progress for a request that is finished.
85 * The identifier of the request
87 * <code>true</code> if the request finished successfully,
88 * <code>false</code> otherwise
90 public HighLevelProgress(String identifier, boolean successful) {
93 setFailed(!successful);
97 * Creates a new high-level progress for a Put or PutDir request that
101 * The identifier of the request
103 * The URI of the request
105 public HighLevelProgress(String identifier, String uri) {
111 * Creates a new high-level progress with the given values.
114 * The identifier of the request
116 * The total number of blocks
117 * @param requiredBlocks
118 * The number of required blocks
119 * @param successfulBlocks
120 * The number of successful blocks
121 * @param failedBlocks
122 * The number of failed blocks
123 * @param fatallyFailedBlocks
124 * The number of fatally failed blocks
125 * @param totalFinalized
126 * <code>true</code> if the total number of blocks is
127 * finalized, <code>false</code> otherwise
129 public HighLevelProgress(String identifier, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean totalFinalized) {
131 this.totalBlocks = totalBlocks;
132 this.requiredBlocks = requiredBlocks;
133 this.successfulBlocks = successfulBlocks;
134 this.failedBlocks = failedBlocks;
135 this.fatallyFailedBlocks = fatallyFailedBlocks;
136 this.totalFinalized = totalFinalized;
140 * Returns whether this progress means that a request has finished. Use
141 * {@link #isFailed()} to check if the request failed.
144 * @return <code>true</code> if the request has finished
146 public boolean isFinished() {
151 * Sets whether the request described by this progress has finished.
154 * <code>true</code> if the request has finished,
155 * <code>false</code> otherwise
157 void setFinished(boolean finished) {
158 this.finished = finished;
162 * Returns whether the request should be fetchable now, in case it was a Put
165 * @return <code>true</code> if the request should be fetchable now,
166 * <code>false</code> otherwise
168 public boolean isFetchable() {
173 * Sets whether the request should be fetchable now, in case it was a Put
177 * <code>true</code> if the request should be fetchable now,
178 * <code>false</code> otherwise
180 void setFetchable(boolean fetchable) {
181 this.fetchable = fetchable;
185 * Returns the URI that was generated by the request. Of course only Put and
186 * PutDir requests will generated URIs.
188 * @return The generated URI
190 public String getURI() {
195 * Sets the URI generated by the request.
200 void setURI(String uri) {
205 * Returns the number of total blocks.
207 * @return The number of total blocks
209 public int getTotalBlocks() {
214 * Sets the number of total blocks.
217 * The number of total blocks
219 void setTotalBlocks(int totalBlocks) {
220 this.totalBlocks = totalBlocks;
224 * Returns the number of required blocks. For downloads, this number is
225 * smaller than {@link #getTotalBlocks()}.
227 * @return The number of required blocks
229 public int getRequiredBlocks() {
230 return requiredBlocks;
234 * Sets the number of required blocks.
236 * @param requiredBlocks
237 * The number of required blocks
239 void setRequiredBlocks(int requiredBlocks) {
240 this.requiredBlocks = requiredBlocks;
244 * Returns the number of successfully transferred blocks.
246 * @return The number of successfully transferred blocks
248 public int getSuccessfulBlocks() {
249 return successfulBlocks;
253 * Sets the number of successfully transferred blocks.
255 * @param successfulBlocks
256 * The number of successfully transferred blocks
258 void setSuccessfulBlocks(int successfulBlocks) {
259 this.successfulBlocks = successfulBlocks;
263 * Returns the number of failed blocks. Blocks that have failed can be
266 * @return The number of failed blocks
268 public int getFailedBlocks() {
273 * Sets the number of failed blocks.
275 * @param failedBlocks
276 * The number of failed blocks
278 void setFailedBlocks(int failedBlocks) {
279 this.failedBlocks = failedBlocks;
283 * Returns the number of fatally failed blocks. Fatally failed blocks will
284 * never complete, even with endless retries.
286 * @return The number of fatally failed blocks
288 public int getFatallyFailedBlocks() {
289 return fatallyFailedBlocks;
293 * Sets the number of fatally failed blocks.
295 * @param fatallyFailedBlocks
296 * The number fatally failed blocks
298 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
299 this.fatallyFailedBlocks = fatallyFailedBlocks;
303 * Returns whether the result of {@link #getTotalBlocks()} is final, i.e. it
304 * won’t change anymore.
306 * @return <code>true</code> if the result of {@link #getTotalBlocks()} is
307 * final, <code>false</code> otherwise
309 public boolean isTotalFinalized() {
310 return totalFinalized;
314 * Sets whether the result of {@link #getTotalBlocks()} is final, i.e. it
315 * won’t change anymore.
317 * @param totalFinalized
318 * <code>true</code> if the result of {@link #getTotalBlocks()}
319 * is final, <code>false</code> otherwise
321 void setTotalFinalized(boolean totalFinalized) {
322 this.totalFinalized = totalFinalized;