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