2 * jFCPlib - Request.java -
3 * Copyright © 2009 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;
22 import net.pterodactylus.fcp.PersistentGet;
23 import net.pterodactylus.fcp.PersistentPut;
26 * Wrapper class around request responses from the node, such as
27 * {@link PersistentGet} or {@link PersistentPut}.
29 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
31 public abstract class Request {
33 /** The identifier of the request. */
34 private final String identifier;
36 /** The client token of the request. */
37 private final String clientToken;
39 /** Whether the request is on the global queue. */
40 private final boolean global;
42 /** Whether the get request is complete. */
43 private boolean complete;
45 /** Whether the get request has failed. */
46 private boolean failed;
48 /** The data length. */
52 private String contentType;
54 /** The error code in case of failure. */
55 private int errorCode;
57 /** Whether the failure is fatal. */
58 private boolean fatal;
60 /** The total number of blocks. */
61 private int totalBlocks;
63 /** The required number of blocks. */
64 private int requiredBlocks;
66 /** The successfully processed number of blocks. */
67 private int succeededBlocks;
69 /** The number of failed blocks. */
70 private int failedBlocks;
72 /** The number of fatally failed blocks. */
73 private int fatallyFailedBlocks;
75 /** Whether the total number of blocks is finalized. */
76 private boolean finalizedTotal;
79 * Creates a new request with the given identifier and client token.
82 * The identifier of the request
84 * The client token of the request
86 * <code>true</code> if the request is on the global queue,
87 * <code>false</code> otherwise
89 protected Request(String identifier, String clientToken, boolean global) {
90 this.identifier = identifier;
91 this.clientToken = clientToken;
96 * Returns the identifier of the request.
98 * @return The request’s identifier
100 public String getIdentifier() {
105 * Returns the client token of the request.
107 * @return The request’s client token
109 public String getClientToken() {
114 * Returns whether this request is on the global queue.
116 * @return <code>true</code> if the request is on the global queue,
117 * <code>false</code> otherwise
119 public boolean isGlobal() {
124 * Returns whether this request is complete.
126 * @return <code>true</code> if this request is complete, false otherwise
128 public boolean isComplete() {
133 * Sets whether this request is complete.
136 * <code>true</code> if this request is complete, false otherwise
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 not
224 * 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
241 void setFatal(boolean fatal) {
246 * Returns the total number of blocks of this request.
248 * @return This request’s total number of blocks
250 public int getTotalBlocks() {
255 * Sets the total number of blocks of this request.
258 * This request’s total number of blocks
260 public void setTotalBlocks(int totalBlocks) {
261 this.totalBlocks = totalBlocks;
267 * @return the requiredBlocks
269 public int getRequiredBlocks() {
270 return requiredBlocks;
276 * @param requiredBlocks
277 * the requiredBlocks to set
279 public void setRequiredBlocks(int requiredBlocks) {
280 this.requiredBlocks = requiredBlocks;
286 * @return the succeededBlocks
288 public int getSucceededBlocks() {
289 return succeededBlocks;
295 * @param succeededBlocks
296 * the succeededBlocks to set
298 public void setSucceededBlocks(int succeededBlocks) {
299 this.succeededBlocks = succeededBlocks;
305 * @return the failedBlocks
307 public int getFailedBlocks() {
314 * @param failedBlocks
315 * the failedBlocks to set
317 public void setFailedBlocks(int failedBlocks) {
318 this.failedBlocks = failedBlocks;
324 * @return the fatallyFailedBlocks
326 public int getFatallyFailedBlocks() {
327 return fatallyFailedBlocks;
333 * @param fatallyFailedBlocks
334 * the fatallyFailedBlocks to set
336 public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
337 this.fatallyFailedBlocks = fatallyFailedBlocks;
340 public boolean isFinalizedTotal() {
341 return finalizedTotal;
344 void setFinalizedTotal(boolean finalizedTotal) {
345 this.finalizedTotal = finalizedTotal;