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 “total blocks” property. */
61 public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
63 /** Name of the “required blocks” property. */
64 public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
66 /** Name of the “successful blocks” property. */
67 public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
69 /** Name of the “failed blocks” property. */
70 public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
72 /** Name of the “fatally failed blocks” property. */
73 public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
75 /** Name of the “total finalized” property. */
76 public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
78 /** The node the request belongs to. */
79 private final Node node;
81 /** The identifier of the request. */
82 private final String identifier;
84 /** The type of the request. */
87 /** The client token of the request. */
88 private String clientToken;
90 /** The total number of blocks. */
91 private int totalBlocks;
93 /** The required number of blocks. */
94 private int requiredBlocks;
96 /** The number of successful blocks. */
97 private int successfulBlocks;
99 /** The number of failedBlocks. */
100 private int failedBlocks;
102 /** The number of fatally failed blocks. */
103 private int fatallyFailedBlocks;
105 /** Whether the total number has been finalized. */
106 private boolean totalFinalized;
109 * Creates a new request with the given identifier.
112 * The node the request belongs to
114 * The identifier of the request
116 Request(Node node, String identifier) {
118 this.identifier = identifier;
126 * Returns the node the request belongs to.
128 * @return The node the request belongs to
130 public Node getNode() {
135 * Returns the identifier of the request. It is unique per node.
137 * @return The identifier of the request
139 public String getIdentifier() {
144 * Returns the type of the request.
146 * @return The type of the request
149 public Type getType() {
154 * Sets the type of the request.
157 * The type of the request
160 public void setType(Type type) {
161 Type oldType = this.type;
163 fireIfPropertyChanged(PROPERTY_TYPE, oldType, type);
167 * Returns the client token of the request.
169 * @return The client token of the request
171 public String getClientToken() {
176 * Sets the client token of the request.
179 * The client token of the request
181 public void setClientToken(String clientToken) {
182 String oldClientToken = this.clientToken;
183 this.clientToken = clientToken;
184 fireIfPropertyChanged(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
188 * Returns the total number of blocks of a request. Until
189 * {@link #isTotalFinalized()} returns <code>true</code> this value may
192 * @return The total number of blocks of a request
194 public int getTotalBlocks() {
199 * Sets the total number of blocks of a request.
202 * The total number of blocks
204 public void setTotalBlocks(int totalBlocks) {
205 int oldTotalBlocks = this.totalBlocks;
206 this.totalBlocks = totalBlocks;
207 fireIfPropertyChanged(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
211 * @return the requiredBlocks
213 public int getRequiredBlocks() {
214 return requiredBlocks;
218 * @param requiredBlocks
219 * the requiredBlocks to set
221 public void setRequiredBlocks(int requiredBlocks) {
222 int oldRequiredBlocks = this.requiredBlocks;
223 this.requiredBlocks = requiredBlocks;
224 fireIfPropertyChanged(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
228 * @return the successfulBlocks
230 public int getSuccessfulBlocks() {
231 return successfulBlocks;
235 * @param successfulBlocks
236 * the successfulBlocks to set
238 public void setSuccessfulBlocks(int successfulBlocks) {
239 int oldSuccessfulBlocks = this.successfulBlocks;
240 this.successfulBlocks = successfulBlocks;
241 fireIfPropertyChanged(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
245 * @return the failedBlocks
247 public int getFailedBlocks() {
252 * @param failedBlocks
253 * the failedBlocks to set
255 public void setFailedBlocks(int failedBlocks) {
256 int oldFailedBlocks = this.failedBlocks;
257 this.failedBlocks = failedBlocks;
258 fireIfPropertyChanged(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
262 * @return the fatallyFailedBlocks
264 public int getFatallyFailedBlocks() {
265 return fatallyFailedBlocks;
269 * @param fatallyFailedBlocks
270 * the fatallyFailedBlocks to set
272 public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
273 int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
274 this.fatallyFailedBlocks = fatallyFailedBlocks;
275 fireIfPropertyChanged(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
279 * @return the totalFinalized
281 public boolean isTotalFinalized() {
282 return totalFinalized;
286 * @param totalFinalized
287 * the totalFinalized to set
289 public void setTotalFinalized(boolean totalFinalized) {
290 boolean oldTotalFinalized = this.totalFinalized;
291 this.totalFinalized = totalFinalized;
292 fireIfPropertyChanged(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);