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 public void setTotalBlocks(int totalBlocks) {
259 this.totalBlocks = totalBlocks;
265 * @return the requiredBlocks
267 public int getRequiredBlocks() {
268 return requiredBlocks;
274 * @param requiredBlocks
275 * the requiredBlocks to set
277 public void setRequiredBlocks(int requiredBlocks) {
278 this.requiredBlocks = requiredBlocks;
284 * @return the succeededBlocks
286 public int getSucceededBlocks() {
287 return succeededBlocks;
293 * @param succeededBlocks
294 * the succeededBlocks to set
296 public void setSucceededBlocks(int succeededBlocks) {
297 this.succeededBlocks = succeededBlocks;
303 * @return the failedBlocks
305 public int getFailedBlocks() {
312 * @param failedBlocks
313 * the failedBlocks to set
315 public void setFailedBlocks(int failedBlocks) {
316 this.failedBlocks = failedBlocks;
322 * @return the fatallyFailedBlocks
324 public int getFatallyFailedBlocks() {
325 return fatallyFailedBlocks;
331 * @param fatallyFailedBlocks
332 * the fatallyFailedBlocks to set
334 public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
335 this.fatallyFailedBlocks = fatallyFailedBlocks;
338 public boolean isFinalizedTotal() {
339 return finalizedTotal;
342 void setFinalizedTotal(boolean finalizedTotal) {
343 this.finalizedTotal = finalizedTotal;