4e24b0272fb886e568ac71cc9434a5222e3a1150
[jFCPlib.git] / src / net / pterodactylus / fcp / highlevel / Request.java
1 /*
2  * jFCPlib - Request.java -
3  * Copyright © 2009 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package net.pterodactylus.fcp.highlevel;
21
22 import net.pterodactylus.fcp.PersistentGet;
23 import net.pterodactylus.fcp.PersistentPut;
24
25 /**
26  * Wrapper class around request responses from the node, such as
27  * {@link PersistentGet} or {@link PersistentPut}.
28  *
29  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
30  */
31 public abstract class Request {
32
33         /** The identifier of the request. */
34         private final String identifier;
35
36         /** The client token of the request. */
37         private final String clientToken;
38
39         /** Whether the request is on the global queue. */
40         private final boolean global;
41
42         /** Whether the get request is complete. */
43         private boolean complete;
44
45         /** Whether the get request has failed. */
46         private boolean failed;
47
48         /** The data length. */
49         private long length;
50
51         /** The mime type. */
52         private String contentType;
53
54         /** The error code in case of failure. */
55         private int errorCode;
56
57         /** Whether the failure is fatal. */
58         private boolean fatal;
59
60         /** The total number of blocks. */
61         private int totalBlocks;
62
63         /** The required number of blocks. */
64         private int requiredBlocks;
65
66         /** The successfully processed number of blocks. */
67         private int succeededBlocks;
68
69         /** The number of failed blocks. */
70         private int failedBlocks;
71
72         /** The number of fatally failed blocks. */
73         private int fatallyFailedBlocks;
74
75         /** Whether the total number of blocks is finalized. */
76         private boolean finalizedTotal;
77
78         /**
79          * Creates a new request with the given identifier and client token.
80          *
81          * @param identifier
82          *            The identifier of the request
83          * @param clientToken
84          *            The client token of the request
85          * @param global
86          *            <code>true</code> if the request is on the global queue,
87          *            <code>false</code> otherwise
88          */
89         protected Request(String identifier, String clientToken, boolean global) {
90                 this.identifier = identifier;
91                 this.clientToken = clientToken;
92                 this.global = global;
93         }
94
95         /**
96          * Returns the identifier of the request.
97          *
98          * @return The request’s identifier
99          */
100         public String getIdentifier() {
101                 return identifier;
102         }
103
104         /**
105          * Returns the client token of the request.
106          *
107          * @return The request’s client token
108          */
109         public String getClientToken() {
110                 return clientToken;
111         }
112
113         /**
114          * Returns whether this request is on the global queue.
115          *
116          * @return <code>true</code> if the request is on the global queue,
117          *         <code>false</code> otherwise
118          */
119         public boolean isGlobal() {
120                 return global;
121         }
122
123         /**
124          * Returns whether this request is complete.
125          *
126          * @return <code>true</code> if this request is complete, false otherwise
127          */
128         public boolean isComplete() {
129                 return complete;
130         }
131
132         /**
133          * Sets whether this request is complete.
134          *
135          * @param complete
136          *            <code>true</code> if this request is complete, false otherwise
137          */
138         void setComplete(boolean complete) {
139                 this.complete = complete;
140         }
141
142         /**
143          * Returns whether this request has failed. This method should only be
144          * called if {@link #isComplete()} returns <code>true</code>.
145          *
146          * @return <code>true</code> if this request failed, <code>false</code>
147          *         otherwise
148          */
149         public boolean hasFailed() {
150                 return failed;
151         }
152
153         /**
154          * Sets whether this request has failed.
155          *
156          * @param failed
157          *            <code>true</code> if this request failed, <code>false</code>
158          *            otherwise
159          */
160         void setFailed(boolean failed) {
161                 this.failed = failed;
162         }
163
164         /**
165          * Returns the length of the data.
166          *
167          * @return The length of the data
168          */
169         public long getLength() {
170                 return length;
171         }
172
173         /**
174          * Sets the length of the data.
175          *
176          * @param length
177          *            The length of the data
178          */
179         void setLength(long length) {
180                 this.length = length;
181         }
182
183         /**
184          * Returns the content type of the data.
185          *
186          * @return The content type of the data
187          */
188         public String getContentType() {
189                 return contentType;
190         }
191
192         /**
193          * Sets the content type of the data.
194          *
195          * @param contentType
196          *            The content type of the data
197          */
198         void setContentType(String contentType) {
199                 this.contentType = contentType;
200         }
201
202         /**
203          * Returns the error code. This method should only be called if
204          * {@link #hasFailed()} returns <code>true</code>.
205          *
206          * @return The error code
207          */
208         public int getErrorCode() {
209                 return errorCode;
210         }
211
212         /**
213          * Sets the error code.
214          *
215          * @param errorCode
216          *            The error code
217          */
218         void setErrorCode(int errorCode) {
219                 this.errorCode = errorCode;
220         }
221
222         /**
223          * Returns whether this request has fatally failed, i.e. repitition will not
224          * cause the request to succeed.
225          *
226          * @return <code>true</code> if this request can not be made succeed by
227          *         repeating, <code>false</code> otherwise
228          */
229         public boolean isFatal() {
230                 return fatal;
231         }
232
233         /**
234          * Sets whether this request has fatally failed.
235          *
236          * @param fatal
237          *            <code>true</code> if this request failed fatally,
238          *            <code>false</code> otherwise
239          */
240         void setFatal(boolean fatal) {
241                 this.fatal = fatal;
242         }
243
244         /**
245          * Returns the total number of blocks of this request.
246          *
247          * @return This request’s total number of blocks
248          */
249         public int getTotalBlocks() {
250                 return totalBlocks;
251         }
252
253         /**
254          * Sets the total number of blocks of this request.
255          *
256          * @param totalBlocks
257          *            This request’s total number of blocks
258          */
259         public void setTotalBlocks(int totalBlocks) {
260                 this.totalBlocks = totalBlocks;
261         }
262
263         /**
264          * TODO
265          *
266          * @return the requiredBlocks
267          */
268         public int getRequiredBlocks() {
269                 return requiredBlocks;
270         }
271
272         /**
273          * TODO
274          *
275          * @param requiredBlocks
276          *            the requiredBlocks to set
277          */
278         public void setRequiredBlocks(int requiredBlocks) {
279                 this.requiredBlocks = requiredBlocks;
280         }
281
282         /**
283          * TODO
284          *
285          * @return the succeededBlocks
286          */
287         public int getSucceededBlocks() {
288                 return succeededBlocks;
289         }
290
291         /**
292          * TODO
293          *
294          * @param succeededBlocks
295          *            the succeededBlocks to set
296          */
297         public void setSucceededBlocks(int succeededBlocks) {
298                 this.succeededBlocks = succeededBlocks;
299         }
300
301         /**
302          * TODO
303          *
304          * @return the failedBlocks
305          */
306         public int getFailedBlocks() {
307                 return failedBlocks;
308         }
309
310         /**
311          * TODO
312          *
313          * @param failedBlocks
314          *            the failedBlocks to set
315          */
316         public void setFailedBlocks(int failedBlocks) {
317                 this.failedBlocks = failedBlocks;
318         }
319
320         /**
321          * TODO
322          *
323          * @return the fatallyFailedBlocks
324          */
325         public int getFatallyFailedBlocks() {
326                 return fatallyFailedBlocks;
327         }
328
329         /**
330          * TODO
331          *
332          * @param fatallyFailedBlocks
333          *            the fatallyFailedBlocks to set
334          */
335         public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
336                 this.fatallyFailedBlocks = fatallyFailedBlocks;
337         }
338
339         public boolean isFinalizedTotal() {
340                 return finalizedTotal;
341         }
342
343         void setFinalizedTotal(boolean finalizedTotal) {
344                 this.finalizedTotal = finalizedTotal;
345         }
346
347 }