2 * jSite2 - Request.java -
3 * Copyright © 2008 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.jsite.core;
22 import net.pterodactylus.util.beans.AbstractBean;
25 * A request is an ongoing download or upload reported by the freenet node.
27 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29 public class Request extends AbstractBean {
32 * The type of a request.
34 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
38 /** Type of request is unknown. */
41 /** The request is a Get request. */
44 /** The request is a Put request. */
47 /** The request is a PutDir request. */
52 /** Name of the “type” property. */
53 public static final String PROPERTY_TYPE = "type";
55 /** Name of the “client token” property. */
56 public static final String PROPERTY_CLIENT_TOKEN = "clientToken";
58 /** Name of the “finished” property. */
59 public static final String PROPERTY_FINISHED = "finished";
61 /** Name of the “successful” property. */
62 public static final String PROPERTY_SUCCESSFUL = "successful";
64 /** Name of the “fetchable” property. */
65 public static final String PROPERTY_FETCHABLE = "fetchable";
67 /** Name of the “URI” property. */
68 public static final String PROPERTY_URI = "uri";
70 /** Name of the “total blocks” property. */
71 public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
73 /** Name of the “required blocks” property. */
74 public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
76 /** Name of the “successful blocks” property. */
77 public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
79 /** Name of the “failed blocks” property. */
80 public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
82 /** Name of the “fatally failed blocks” property. */
83 public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
85 /** Name of the “total finalized” property. */
86 public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
88 /** The node the request belongs to. */
89 private final Node node;
91 /** The identifier of the request. */
92 private final String identifier;
94 /** The type of the request. */
97 /** The client token of the request. */
98 private String clientToken;
100 /** Whether the request is finished. */
101 private boolean finished;
103 /** Whether the request was finished successfully. */
104 private boolean successful;
106 /** Whether the data is already fetchable (in case of put requests). */
107 private boolean fetchable;
109 /** The generated URI. */
112 /** The total number of blocks. */
113 private int totalBlocks;
115 /** The required number of blocks. */
116 private int requiredBlocks;
118 /** The number of successful blocks. */
119 private int successfulBlocks;
121 /** The number of failedBlocks. */
122 private int failedBlocks;
124 /** The number of fatally failed blocks. */
125 private int fatallyFailedBlocks;
127 /** Whether the total number has been finalized. */
128 private boolean totalFinalized;
131 * Creates a new request with the given identifier.
134 * The node the request belongs to
136 * The identifier of the request
138 Request(Node node, String identifier) {
140 this.identifier = identifier;
148 * Returns the node the request belongs to.
150 * @return The node the request belongs to
152 public Node getNode() {
157 * Returns the identifier of the request. It is unique per node.
159 * @return The identifier of the request
161 public String getIdentifier() {
166 * Returns the type of the request.
168 * @return The type of the request
171 public Type getType() {
176 * Sets the type of the request.
179 * The type of the request
181 void setType(Type type) {
182 Type oldType = this.type;
184 fireIfPropertyChanged(PROPERTY_TYPE, oldType, type);
188 * Returns the client token of the request.
190 * @return The client token of the request
192 public String getClientToken() {
197 * Sets the client token of the request.
200 * The client token of the request
202 void setClientToken(String clientToken) {
203 String oldClientToken = this.clientToken;
204 this.clientToken = clientToken;
205 fireIfPropertyChanged(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
209 * Returns whether the request has finished.
211 * @see #isSuccessful()
212 * @return <code>true</code> if the request is finished,
213 * <code>false</code> otherwise
215 public boolean isFinished() {
220 * Sets whether the request has finished.
223 * <code>true</code> if the request has finished,
224 * <code>false</code> otherwise
226 void setFinished(boolean finished) {
227 boolean oldFinished = this.finished;
228 this.finished = finished;
229 firePropertyChange(PROPERTY_FINISHED, oldFinished, finished);
233 * Returns whether the request finished successfully. This value will only
234 * have meaning if {@link #isFinished()} returns <code>true</code>.
236 * @return <code>true</code> if the request finished successfully,
237 * <code>false</code> otherwise
239 public boolean isSuccessful() {
244 * Sets whether this request finished successfully.
247 * <code>true</code> if the request finished successfully,
248 * <code>false</code> otherwise
250 void setSuccessful(boolean successful) {
251 boolean oldSuccessful = this.successful;
252 this.successful = successful;
253 firePropertyChange(PROPERTY_SUCCESSFUL, oldSuccessful, successful);
257 * Returns whether the data inserted by this {@link Type#put} or
258 * {@link Type#putDir} request is already fetchable by other clients.
260 * @return <code>true</code> if the data is already fetchable,
261 * <code>false</code> otherwise
263 public boolean isFetchable() {
268 * Sets whether the data inserted by this {@link Type#put} or
269 * {@link Type#putDir} request is already fetchable by other clients.
272 * <code>true</code> if the data is already fetchable,
273 * <code>false</code> otherwise
275 void setFetchable(boolean fetchable) {
276 boolean oldFetchable = this.fetchable;
277 this.fetchable = fetchable;
278 firePropertyChange(PROPERTY_FETCHABLE, oldFetchable, fetchable);
282 * Returns the URI generated by this request.
284 * @return The generated URI
286 public String getURI() {
291 * Sets the URI generated by this request.
296 void setURI(String uri) {
301 * Returns the total number of blocks of a request. Until
302 * {@link #isTotalFinalized()} returns <code>true</code> this value may
305 * @return The total number of blocks of a request
307 public int getTotalBlocks() {
312 * Sets the total number of blocks of a request.
315 * The total number of blocks
317 void setTotalBlocks(int totalBlocks) {
318 int oldTotalBlocks = this.totalBlocks;
319 this.totalBlocks = totalBlocks;
320 fireIfPropertyChanged(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
324 * @return the requiredBlocks
326 public int getRequiredBlocks() {
327 return requiredBlocks;
331 * @param requiredBlocks
332 * the requiredBlocks to set
334 void setRequiredBlocks(int requiredBlocks) {
335 int oldRequiredBlocks = this.requiredBlocks;
336 this.requiredBlocks = requiredBlocks;
337 fireIfPropertyChanged(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
341 * @return the successfulBlocks
343 public int getSuccessfulBlocks() {
344 return successfulBlocks;
348 * @param successfulBlocks
349 * the successfulBlocks to set
351 void setSuccessfulBlocks(int successfulBlocks) {
352 int oldSuccessfulBlocks = this.successfulBlocks;
353 this.successfulBlocks = successfulBlocks;
354 fireIfPropertyChanged(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
358 * @return the failedBlocks
360 public int getFailedBlocks() {
365 * @param failedBlocks
366 * the failedBlocks to set
368 void setFailedBlocks(int failedBlocks) {
369 int oldFailedBlocks = this.failedBlocks;
370 this.failedBlocks = failedBlocks;
371 fireIfPropertyChanged(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
375 * @return the fatallyFailedBlocks
377 public int getFatallyFailedBlocks() {
378 return fatallyFailedBlocks;
382 * @param fatallyFailedBlocks
383 * the fatallyFailedBlocks to set
385 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
386 int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
387 this.fatallyFailedBlocks = fatallyFailedBlocks;
388 fireIfPropertyChanged(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
392 * @return the totalFinalized
394 public boolean isTotalFinalized() {
395 return totalFinalized;
399 * @param totalFinalized
400 * the totalFinalized to set
402 void setTotalFinalized(boolean totalFinalized) {
403 boolean oldTotalFinalized = this.totalFinalized;
404 this.totalFinalized = totalFinalized;
405 fireIfPropertyChanged(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);