2 * jFCPlib - Request.java - Copyright © 2009 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package net.pterodactylus.fcp.highlevel;
21 import net.pterodactylus.fcp.PersistentGet;
22 import net.pterodactylus.fcp.PersistentPut;
25 * Wrapper class around request responses from the node, such as
26 * {@link PersistentGet} or {@link PersistentPut}.
28 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
30 public abstract class Request {
32 /** The identifier of the request. */
33 private final String identifier;
35 /** The client token of the request. */
36 private final String clientToken;
38 /** Whether the request is on the global queue. */
39 private final boolean global;
41 /** Whether the get request is complete. */
42 private boolean complete;
44 /** Whether the get request has failed. */
45 private boolean failed;
47 /** The data length. */
51 private String contentType;
53 /** The error code in case of failure. */
54 private int errorCode;
56 /** Whether the failure is fatal. */
57 private boolean fatal;
59 /** The total number of blocks. */
60 private int totalBlocks;
62 /** The required number of blocks. */
63 private int requiredBlocks;
65 /** The successfully processed number of blocks. */
66 private int succeededBlocks;
68 /** The number of failed blocks. */
69 private int failedBlocks;
71 /** The number of fatally failed blocks. */
72 private int fatallyFailedBlocks;
74 /** Whether the total number of blocks is finalized. */
75 private boolean finalizedTotal;
78 * Creates a new request with the given identifier and client token.
81 * The identifier of the request
83 * The client token of the request
85 * <code>true</code> if the request is on the global queue,
86 * <code>false</code> otherwise
88 protected Request(String identifier, String clientToken, boolean global) {
89 this.identifier = identifier;
90 this.clientToken = clientToken;
95 * Returns the identifier of the request.
97 * @return The request’s identifier
99 public String getIdentifier() {
104 * Returns the client token of the request.
106 * @return The request’s client token
108 public String getClientToken() {
113 * Returns whether this request is on the global queue.
115 * @return <code>true</code> if the request is on the global queue,
116 * <code>false</code> otherwise
118 public boolean isGlobal() {
123 * Returns whether this request is complete.
125 * @return <code>true</code> if this request is complete, false otherwise
127 public boolean isComplete() {
132 * Sets whether this request is complete.
135 * <code>true</code> if this request is complete, false
138 void setComplete(boolean complete) {
139 this.complete = complete;
143 * Returns whether this request has failed. This method should only be
144 * called if {@link #isComplete()} returns <code>true</code>.
146 * @return <code>true</code> if this request failed, <code>false</code>
149 public boolean hasFailed() {
154 * Sets whether this request has failed.
157 * <code>true</code> if this request failed, <code>false</code>
160 void setFailed(boolean failed) {
161 this.failed = failed;
165 * Returns the length of the data.
167 * @return The length of the data
169 public long getLength() {
174 * Sets the length of the data.
177 * The length of the data
179 void setLength(long length) {
180 this.length = length;
184 * Returns the content type of the data.
186 * @return The content type of the data
188 public String getContentType() {
193 * Sets the content type of the data.
196 * The content type of the data
198 void setContentType(String contentType) {
199 this.contentType = contentType;
203 * Returns the error code. This method should only be called if
204 * {@link #hasFailed()} returns <code>true</code>.
206 * @return The error code
208 public int getErrorCode() {
213 * Sets the error code.
218 void setErrorCode(int errorCode) {
219 this.errorCode = errorCode;
223 * Returns whether this request has fatally failed, i.e. repitition will
224 * not cause the request to succeed.
226 * @return <code>true</code> if this request can not be made succeed by
227 * repeating, <code>false</code> otherwise
229 public boolean isFatal() {
234 * Sets whether this request has fatally failed.
237 * <code>true</code> if this request failed fatally,
238 * <code>false</code> otherwise
240 void setFatal(boolean fatal) {
245 * Returns the total number of blocks of this request.
247 * @return This request’s total number of blocks
249 public int getTotalBlocks() {
254 * Sets the total number of blocks of this request.
257 * This request’s total number of blocks
259 void setTotalBlocks(int totalBlocks) {
260 this.totalBlocks = totalBlocks;
264 * Returns the number of required blocks. Any progress percentages should
265 * be calculated against this value as 100%. Also, as long as
266 * {@link #isFinalizedTotal()} returns {@code false} this value might
269 * @return The number of required blocks
271 public int getRequiredBlocks() {
272 return requiredBlocks;
276 * Sets the number of required blocks.
278 * @param requiredBlocks
279 * The number of required blocks
281 void setRequiredBlocks(int requiredBlocks) {
282 this.requiredBlocks = requiredBlocks;
286 * Returns the number of succeeded blocks.
288 * @return The number of succeeded blocks
290 public int getSucceededBlocks() {
291 return succeededBlocks;
295 * Sets the number of succeeded blocks.
297 * @param succeededBlocks
298 * The number of succeeded blocks
300 void setSucceededBlocks(int succeededBlocks) {
301 this.succeededBlocks = succeededBlocks;
305 * Returns the number of failed blocks. These blocks may be retried untill
306 * the maximum number of retries has been reached.
308 * @return The number of failed blocks
310 public int getFailedBlocks() {
315 * Sets the number of failed blocks.
317 * @param failedBlocks
318 * The number of failed blocks
320 void setFailedBlocks(int failedBlocks) {
321 this.failedBlocks = failedBlocks;
325 * Returns the number of fatally failed blocks.
327 * @return The number of fatally failed blocks
329 public int getFatallyFailedBlocks() {
330 return fatallyFailedBlocks;
334 * Sets the number of fatally failed blocks.
336 * @param fatallyFailedBlocks
337 * The number of fatally failed blocks
339 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
340 this.fatallyFailedBlocks = fatallyFailedBlocks;
344 * Returns whether the number of blocks has been finalized.
346 * @return {@code true} if the number of blocks is finalized, {@code false}
349 public boolean isFinalizedTotal() {
350 return finalizedTotal;
354 * Sets whether the number of blocks has been finalized.
356 * @param finalizedTotal
357 * {@code true} if the number of blocks has been finalized,
358 * {@code false} otherwise
360 void setFinalizedTotal(boolean finalizedTotal) {
361 this.finalizedTotal = finalizedTotal;