98c36ce1be20bf677f45f74fd6c37a73f44b1ee1
[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          */
241         void setFatal(boolean fatal) {
242                 this.fatal = fatal;
243         }
244
245         /**
246          * Returns the total number of blocks of this request.
247          *
248          * @return This request’s total number of blocks
249          */
250         public int getTotalBlocks() {
251                 return totalBlocks;
252         }
253
254         /**
255          * Sets the total number of blocks of this request.
256          *
257          * @param totalBlocks
258          *            This request’s total number of blocks
259          */
260         public void setTotalBlocks(int totalBlocks) {
261                 this.totalBlocks = totalBlocks;
262         }
263
264         /**
265          * TODO
266          *
267          * @return the requiredBlocks
268          */
269         public int getRequiredBlocks() {
270                 return requiredBlocks;
271         }
272
273         /**
274          * TODO
275          *
276          * @param requiredBlocks
277          *            the requiredBlocks to set
278          */
279         public void setRequiredBlocks(int requiredBlocks) {
280                 this.requiredBlocks = requiredBlocks;
281         }
282
283         /**
284          * TODO
285          *
286          * @return the succeededBlocks
287          */
288         public int getSucceededBlocks() {
289                 return succeededBlocks;
290         }
291
292         /**
293          * TODO
294          *
295          * @param succeededBlocks
296          *            the succeededBlocks to set
297          */
298         public void setSucceededBlocks(int succeededBlocks) {
299                 this.succeededBlocks = succeededBlocks;
300         }
301
302         /**
303          * TODO
304          *
305          * @return the failedBlocks
306          */
307         public int getFailedBlocks() {
308                 return failedBlocks;
309         }
310
311         /**
312          * TODO
313          *
314          * @param failedBlocks
315          *            the failedBlocks to set
316          */
317         public void setFailedBlocks(int failedBlocks) {
318                 this.failedBlocks = failedBlocks;
319         }
320
321         /**
322          * TODO
323          *
324          * @return the fatallyFailedBlocks
325          */
326         public int getFatallyFailedBlocks() {
327                 return fatallyFailedBlocks;
328         }
329
330         /**
331          * TODO
332          *
333          * @param fatallyFailedBlocks
334          *            the fatallyFailedBlocks to set
335          */
336         public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
337                 this.fatallyFailedBlocks = fatallyFailedBlocks;
338         }
339
340         public boolean isFinalizedTotal() {
341                 return finalizedTotal;
342         }
343
344         void setFinalizedTotal(boolean finalizedTotal) {
345                 this.finalizedTotal = finalizedTotal;
346         }
347
348 }