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>
30 public class Request extends AbstractBean {
33 * The type of a request.
35 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
40 /** Type of request is unknown. */
43 /** The request is a Get request. */
46 /** The request is a Put request. */
49 /** The request is a PutDir request. */
54 /** Name of the “type” property. */
55 public static final String PROPERTY_TYPE = "type";
57 /** Name of the “client token” property. */
58 public static final String PROPERTY_CLIENT_TOKEN = "clientToken";
60 /** Name of the “finished” property. */
61 public static final String PROPERTY_FINISHED = "finished";
63 /** Name of the “successful” property. */
64 public static final String PROPERTY_SUCCESSFUL = "successful";
66 /** Name of the “fetchable” property. */
67 public static final String PROPERTY_FETCHABLE = "fetchable";
69 /** Name of the “total blocks” property. */
70 public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
72 /** Name of the “required blocks” property. */
73 public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
75 /** Name of the “successful blocks” property. */
76 public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
78 /** Name of the “failed blocks” property. */
79 public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
81 /** Name of the “fatally failed blocks” property. */
82 public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
84 /** Name of the “total finalized” property. */
85 public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
87 /** The node the request belongs to. */
88 private final Node node;
90 /** The identifier of the request. */
91 private final String identifier;
93 /** The type of the request. */
96 /** The client token of the request. */
97 private String clientToken;
99 /** Whether the request is finished. */
100 private boolean finished;
102 /** Whether the request was finished successfully. */
103 private boolean successful;
105 /** Whether the data is already fetchable (in case of put requests). */
106 private boolean fetchable;
108 /** The total number of blocks. */
109 private int totalBlocks;
111 /** The required number of blocks. */
112 private int requiredBlocks;
114 /** The number of successful blocks. */
115 private int successfulBlocks;
117 /** The number of failedBlocks. */
118 private int failedBlocks;
120 /** The number of fatally failed blocks. */
121 private int fatallyFailedBlocks;
123 /** Whether the total number has been finalized. */
124 private boolean totalFinalized;
127 * Creates a new request with the given identifier.
130 * The node the request belongs to
132 * The identifier of the request
134 Request(Node node, String identifier) {
136 this.identifier = identifier;
144 * Returns the node the request belongs to.
146 * @return The node the request belongs to
148 public Node getNode() {
153 * Returns the identifier of the request. It is unique per node.
155 * @return The identifier of the request
157 public String getIdentifier() {
162 * Returns the type of the request.
164 * @return The type of the request
167 public Type getType() {
172 * Sets the type of the request.
175 * The type of the request
177 void setType(Type type) {
178 Type oldType = this.type;
180 fireIfPropertyChanged(PROPERTY_TYPE, oldType, type);
184 * Returns the client token of the request.
186 * @return The client token of the request
188 public String getClientToken() {
193 * Sets the client token of the request.
196 * The client token of the request
198 void setClientToken(String clientToken) {
199 String oldClientToken = this.clientToken;
200 this.clientToken = clientToken;
201 fireIfPropertyChanged(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
205 * Returns whether the request has finished.
207 * @see #isSuccessful()
208 * @return <code>true</code> if the request is finished,
209 * <code>false</code> otherwise
211 public boolean isFinished() {
216 * Sets whether the request has finished.
219 * <code>true</code> if the request has finished,
220 * <code>false</code> otherwise
222 void setFinished(boolean finished) {
223 boolean oldFinished = this.finished;
224 this.finished = finished;
225 firePropertyChange(PROPERTY_FINISHED, oldFinished, finished);
229 * Returns whether the request finished successfully. This value will only
230 * have meaning if {@link #isFinished()} returns <code>true</code>.
232 * @return <code>true</code> if the request finished successfully,
233 * <code>false</code> otherwise
235 public boolean isSuccessful() {
240 * Sets whether this request finished successfully.
243 * <code>true</code> if the request finished successfully,
244 * <code>false</code> otherwise
246 void setSuccessful(boolean successful) {
247 boolean oldSuccessful = this.successful;
248 this.successful = successful;
249 firePropertyChange(PROPERTY_SUCCESSFUL, oldSuccessful, successful);
253 * Returns whether the data inserted by this {@link Type#put} or
254 * {@link Type#putDir} request is already fetchable by other clients.
256 * @return <code>true</code> if the data is already fetchable,
257 * <code>false</code> otherwise
259 public boolean isFetchable() {
264 * Sets whether the data inserted by this {@link Type#put} or
265 * {@link Type#putDir} request is already fetchable by other clients.
268 * <code>true</code> if the data is already fetchable,
269 * <code>false</code> otherwise
271 void setFetchable(boolean fetchable) {
272 boolean oldFetchable = this.fetchable;
273 this.fetchable = fetchable;
274 firePropertyChange(PROPERTY_FETCHABLE, oldFetchable, fetchable);
278 * Returns the total number of blocks of a request. Until
279 * {@link #isTotalFinalized()} returns <code>true</code> this value may
282 * @return The total number of blocks of a request
284 public int getTotalBlocks() {
289 * Sets the total number of blocks of a request.
292 * The total number of blocks
294 void setTotalBlocks(int totalBlocks) {
295 int oldTotalBlocks = this.totalBlocks;
296 this.totalBlocks = totalBlocks;
297 fireIfPropertyChanged(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
301 * @return the requiredBlocks
303 public int getRequiredBlocks() {
304 return requiredBlocks;
308 * @param requiredBlocks
309 * the requiredBlocks to set
311 void setRequiredBlocks(int requiredBlocks) {
312 int oldRequiredBlocks = this.requiredBlocks;
313 this.requiredBlocks = requiredBlocks;
314 fireIfPropertyChanged(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
318 * @return the successfulBlocks
320 public int getSuccessfulBlocks() {
321 return successfulBlocks;
325 * @param successfulBlocks
326 * the successfulBlocks to set
328 void setSuccessfulBlocks(int successfulBlocks) {
329 int oldSuccessfulBlocks = this.successfulBlocks;
330 this.successfulBlocks = successfulBlocks;
331 fireIfPropertyChanged(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
335 * @return the failedBlocks
337 public int getFailedBlocks() {
342 * @param failedBlocks
343 * the failedBlocks to set
345 void setFailedBlocks(int failedBlocks) {
346 int oldFailedBlocks = this.failedBlocks;
347 this.failedBlocks = failedBlocks;
348 fireIfPropertyChanged(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
352 * @return the fatallyFailedBlocks
354 public int getFatallyFailedBlocks() {
355 return fatallyFailedBlocks;
359 * @param fatallyFailedBlocks
360 * the fatallyFailedBlocks to set
362 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
363 int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
364 this.fatallyFailedBlocks = fatallyFailedBlocks;
365 fireIfPropertyChanged(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
369 * @return the totalFinalized
371 public boolean isTotalFinalized() {
372 return totalFinalized;
376 * @param totalFinalized
377 * the totalFinalized to set
379 void setTotalFinalized(boolean totalFinalized) {
380 boolean oldTotalFinalized = this.totalFinalized;
381 this.totalFinalized = totalFinalized;
382 fireIfPropertyChanged(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);