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 “URI” property. */
70 public static final String PROPERTY_URI = "uri";
72 /** Name of the “total blocks” property. */
73 public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
75 /** Name of the “required blocks” property. */
76 public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
78 /** Name of the “successful blocks” property. */
79 public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
81 /** Name of the “failed blocks” property. */
82 public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
84 /** Name of the “fatally failed blocks” property. */
85 public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
87 /** Name of the “total finalized” property. */
88 public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
90 /** The node the request belongs to. */
91 private final Node node;
93 /** The identifier of the request. */
94 private final String identifier;
96 /** The type of the request. */
99 /** The client token of the request. */
100 private String clientToken;
102 /** Whether the request is finished. */
103 private boolean finished;
105 /** Whether the request was finished successfully. */
106 private boolean successful;
108 /** Whether the data is already fetchable (in case of put requests). */
109 private boolean fetchable;
111 /** The generated URI. */
114 /** The total number of blocks. */
115 private int totalBlocks;
117 /** The required number of blocks. */
118 private int requiredBlocks;
120 /** The number of successful blocks. */
121 private int successfulBlocks;
123 /** The number of failedBlocks. */
124 private int failedBlocks;
126 /** The number of fatally failed blocks. */
127 private int fatallyFailedBlocks;
129 /** Whether the total number has been finalized. */
130 private boolean totalFinalized;
133 * Creates a new request with the given identifier.
136 * The node the request belongs to
138 * The identifier of the request
140 Request(Node node, String identifier) {
142 this.identifier = identifier;
150 * Returns the node the request belongs to.
152 * @return The node the request belongs to
154 public Node getNode() {
159 * Returns the identifier of the request. It is unique per node.
161 * @return The identifier of the request
163 public String getIdentifier() {
168 * Returns the type of the request.
170 * @return The type of the request
173 public Type getType() {
178 * Sets the type of the request.
181 * The type of the request
183 void setType(Type type) {
184 Type oldType = this.type;
186 fireIfPropertyChanged(PROPERTY_TYPE, oldType, type);
190 * Returns the client token of the request.
192 * @return The client token of the request
194 public String getClientToken() {
199 * Sets the client token of the request.
202 * The client token of the request
204 void setClientToken(String clientToken) {
205 String oldClientToken = this.clientToken;
206 this.clientToken = clientToken;
207 fireIfPropertyChanged(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
211 * Returns whether the request has finished.
213 * @see #isSuccessful()
214 * @return <code>true</code> if the request is finished,
215 * <code>false</code> otherwise
217 public boolean isFinished() {
222 * Sets whether the request has finished.
225 * <code>true</code> if the request has finished,
226 * <code>false</code> otherwise
228 void setFinished(boolean finished) {
229 boolean oldFinished = this.finished;
230 this.finished = finished;
231 firePropertyChange(PROPERTY_FINISHED, oldFinished, finished);
235 * Returns whether the request finished successfully. This value will only
236 * have meaning if {@link #isFinished()} returns <code>true</code>.
238 * @return <code>true</code> if the request finished successfully,
239 * <code>false</code> otherwise
241 public boolean isSuccessful() {
246 * Sets whether this request finished successfully.
249 * <code>true</code> if the request finished successfully,
250 * <code>false</code> otherwise
252 void setSuccessful(boolean successful) {
253 boolean oldSuccessful = this.successful;
254 this.successful = successful;
255 firePropertyChange(PROPERTY_SUCCESSFUL, oldSuccessful, successful);
259 * Returns whether the data inserted by this {@link Type#put} or
260 * {@link Type#putDir} request is already fetchable by other clients.
262 * @return <code>true</code> if the data is already fetchable,
263 * <code>false</code> otherwise
265 public boolean isFetchable() {
270 * Sets whether the data inserted by this {@link Type#put} or
271 * {@link Type#putDir} request is already fetchable by other clients.
274 * <code>true</code> if the data is already fetchable,
275 * <code>false</code> otherwise
277 void setFetchable(boolean fetchable) {
278 boolean oldFetchable = this.fetchable;
279 this.fetchable = fetchable;
280 firePropertyChange(PROPERTY_FETCHABLE, oldFetchable, fetchable);
284 * Returns the URI generated by this request.
286 * @return The generated URI
288 public String getURI() {
293 * Sets the URI generated by this request.
298 void setURI(String uri) {
303 * Returns the total number of blocks of a request. Until
304 * {@link #isTotalFinalized()} returns <code>true</code> this value may
307 * @return The total number of blocks of a request
309 public int getTotalBlocks() {
314 * Sets the total number of blocks of a request.
317 * The total number of blocks
319 void setTotalBlocks(int totalBlocks) {
320 int oldTotalBlocks = this.totalBlocks;
321 this.totalBlocks = totalBlocks;
322 fireIfPropertyChanged(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
326 * @return the requiredBlocks
328 public int getRequiredBlocks() {
329 return requiredBlocks;
333 * @param requiredBlocks
334 * the requiredBlocks to set
336 void setRequiredBlocks(int requiredBlocks) {
337 int oldRequiredBlocks = this.requiredBlocks;
338 this.requiredBlocks = requiredBlocks;
339 fireIfPropertyChanged(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
343 * @return the successfulBlocks
345 public int getSuccessfulBlocks() {
346 return successfulBlocks;
350 * @param successfulBlocks
351 * the successfulBlocks to set
353 void setSuccessfulBlocks(int successfulBlocks) {
354 int oldSuccessfulBlocks = this.successfulBlocks;
355 this.successfulBlocks = successfulBlocks;
356 fireIfPropertyChanged(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
360 * @return the failedBlocks
362 public int getFailedBlocks() {
367 * @param failedBlocks
368 * the failedBlocks to set
370 void setFailedBlocks(int failedBlocks) {
371 int oldFailedBlocks = this.failedBlocks;
372 this.failedBlocks = failedBlocks;
373 fireIfPropertyChanged(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
377 * @return the fatallyFailedBlocks
379 public int getFatallyFailedBlocks() {
380 return fatallyFailedBlocks;
384 * @param fatallyFailedBlocks
385 * the fatallyFailedBlocks to set
387 void setFatallyFailedBlocks(int fatallyFailedBlocks) {
388 int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
389 this.fatallyFailedBlocks = fatallyFailedBlocks;
390 fireIfPropertyChanged(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
394 * @return the totalFinalized
396 public boolean isTotalFinalized() {
397 return totalFinalized;
401 * @param totalFinalized
402 * the totalFinalized to set
404 void setTotalFinalized(boolean totalFinalized) {
405 boolean oldTotalFinalized = this.totalFinalized;
406 this.totalFinalized = totalFinalized;
407 fireIfPropertyChanged(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);