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 otherwise
137 void setComplete(boolean complete) {
138 this.complete = complete;
142 * Returns whether this request has failed. This method should only be
143 * called if {@link #isComplete()} returns <code>true</code>.
145 * @return <code>true</code> if this request failed, <code>false</code>
148 public boolean hasFailed() {
153 * Sets whether this request has failed.
156 * <code>true</code> if this request failed, <code>false</code>
159 void setFailed(boolean failed) {
160 this.failed = failed;
164 * Returns the length of the data.
166 * @return The length of the data
168 public long getLength() {
173 * Sets the length of the data.
176 * The length of the data
178 void setLength(long length) {
179 this.length = length;
183 * Returns the content type of the data.
185 * @return The content type of the data
187 public String getContentType() {
192 * Sets the content type of the data.
195 * The content type of the data
197 void setContentType(String contentType) {
198 this.contentType = contentType;
202 * Returns the error code. This method should only be called if
203 * {@link #hasFailed()} returns <code>true</code>.
205 * @return The error code
207 public int getErrorCode() {
212 * Sets the error code.
217 void setErrorCode(int errorCode) {
218 this.errorCode = errorCode;
222 * Returns whether this request has fatally failed, i.e. repitition will not
223 * cause the request to succeed.
225 * @return <code>true</code> if this request can not be made succeed by
226 * repeating, <code>false</code> otherwise
228 public boolean isFatal() {
233 * Sets whether this request has fatally failed.
236 * <code>true</code> if this request failed fatally,
237 * <code>false</code> otherwise
239 void setFatal(boolean fatal) {
244 * Returns the total number of blocks of this request.
246 * @return This request’s total number of blocks
248 public int getTotalBlocks() {
253 * Sets the total number of blocks of this request.
256 * This request’s total number of blocks
258 void setTotalBlocks(int totalBlocks) {
259 this.totalBlocks = totalBlocks;
263 * Returns the number of required blocks. Any progress percentages should be
264 * calculated against this value as 100%. Also, as long as
265 * {@link #isFinalizedTotal()} returns {@code false} this value might
268 * @return The number of required blocks
270 public int getRequiredBlocks() {
271 return requiredBlocks;
275 * Sets the number of required blocks.
277 * @param requiredBlocks
278 * The number of required blocks
280 void setRequiredBlocks(int requiredBlocks) {
281 this.requiredBlocks = requiredBlocks;
285 * Returns the number of succeeded blocks.
287 * @return The number of succeeded blocks
289 public int getSucceededBlocks() {
290 return succeededBlocks;
294 * Sets the number of succeeded blocks.
296 * @param succeededBlocks
297 * The number of succeeded blocks
299 void setSucceededBlocks(int succeededBlocks) {
300 this.succeededBlocks = succeededBlocks;
304 * Returns the number of failed blocks. These blocks may be retried untill
305 * the maximum number of retries has been reached.
307 * @return The number of failed blocks
309 public int getFailedBlocks() {
314 * Sets the number of failed blocks.
316 * @param failedBlocks
317 * The number of failed blocks
319 void setFailedBlocks(int failedBlocks) {
320 this.failedBlocks = failedBlocks;
324 * Returns the number of fatally failed blocks.
326 * @return The number of fatally failed blocks
328 public int getFatallyFailedBlocks() {
329 return fatallyFailedBlocks;
333 * Sets the number of fatally failed blocks.
335 * @param fatallyFailedBlocks
336 * The number of fatally failed blocks
338 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
339 this.fatallyFailedBlocks = fatallyFailedBlocks;
343 * Returns whether the number of blocks has been finalized.
345 * @return {@code true} if the number of blocks is finalized, {@code false}
348 public boolean isFinalizedTotal() {
349 return finalizedTotal;
353 * Sets whether the number of blocks has been finalized.
355 * @param finalizedTotal
356 * {@code true} if the number of blocks has been finalized,
357 * {@code false} otherwise
359 void setFinalizedTotal(boolean finalizedTotal) {
360 this.finalizedTotal = finalizedTotal;