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;
23 import net.pterodactylus.util.beans.AbstractBean;
26 * A request is an ongoing download or upload reported by the freenet node.
28 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
31 public class Request extends
35 * The type of a request.
37 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
42 /** Type of request is unknown. */
45 /** The request is a Get request. */
48 /** The request is a Put request. */
51 /** The request is a PutDir request. */
56 /** Name of the “type” property. */
57 public static final String PROPERTY_TYPE = "type";
59 /** Name of the “client token” property. */
60 public static final String PROPERTY_CLIENT_TOKEN = "clientToken";
62 /** Name of the “total blocks” property. */
63 public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
65 /** Name of the “required blocks” property. */
66 public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
68 /** Name of the “successful blocks” property. */
69 public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
71 /** Name of the “failed blocks” property. */
72 public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
74 /** Name of the “fatally failed blocks” property. */
75 public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
77 /** Name of the “total finalized” property. */
78 public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
80 /** The node the request belongs to. */
81 private final Node node;
83 /** The identifier of the request. */
84 private final String identifier;
86 /** The type of the request. */
89 /** The client token of the request. */
90 private String clientToken;
92 /** The total number of blocks. */
93 private int totalBlocks;
95 /** The required number of blocks. */
96 private int requiredBlocks;
98 /** The number of successful blocks. */
99 private int successfulBlocks;
101 /** The number of failedBlocks. */
102 private int failedBlocks;
104 /** The number of fatally failed blocks. */
105 private int fatallyFailedBlocks;
107 /** Whether the total number has been finalized. */
108 private boolean totalFinalized;
111 * Creates a new request with the given identifier.
114 * The node the request belongs to
116 * The identifier of the request
118 Request(Node node, String identifier) {
120 this.identifier = identifier;
128 * Returns the node the request belongs to.
130 * @return The node the request belongs to
132 public Node getNode() {
137 * Returns the identifier of the request. It is unique per node.
139 * @return The identifier of the request
141 public String getIdentifier() {
146 * Returns the type of the request.
148 * @return The type of the request
151 public Type getType() {
156 * Sets the type of the request.
159 * The type of the request
162 public void setType(Type type) {
163 Type oldType = this.type;
165 if (!equal(oldType, type)) {
166 firePropertyChange(PROPERTY_TYPE, oldType, type);
171 * Returns the client token of the request.
173 * @return The client token of the request
175 public String getClientToken() {
180 * Sets the client token of the request.
183 * The client token of the request
185 public void setClientToken(String clientToken) {
186 String oldClientToken = this.clientToken;
187 this.clientToken = clientToken;
188 if (!equal(oldClientToken, clientToken)) {
189 firePropertyChange(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
194 * Returns the total number of blocks of a request. Until
195 * {@link #isTotalFinalized()} returns <code>true</code> this value may
198 * @return The total number of blocks of a request
200 public int getTotalBlocks() {
205 * Sets the total number of blocks of a request.
208 * The total number of blocks
210 public void setTotalBlocks(int totalBlocks) {
211 int oldTotalBlocks = this.totalBlocks;
212 this.totalBlocks = totalBlocks;
213 if (oldTotalBlocks != totalBlocks) {
214 firePropertyChange(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
219 * @return the requiredBlocks
221 public int getRequiredBlocks() {
222 return requiredBlocks;
226 * @param requiredBlocks
227 * the requiredBlocks to set
229 public void setRequiredBlocks(int requiredBlocks) {
230 int oldRequiredBlocks = this.requiredBlocks;
231 this.requiredBlocks = requiredBlocks;
232 if (oldRequiredBlocks != requiredBlocks) {
233 firePropertyChange(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
238 * @return the successfulBlocks
240 public int getSuccessfulBlocks() {
241 return successfulBlocks;
245 * @param successfulBlocks
246 * the successfulBlocks to set
248 public void setSuccessfulBlocks(int successfulBlocks) {
249 int oldSuccessfulBlocks = this.successfulBlocks;
250 this.successfulBlocks = successfulBlocks;
251 if (oldSuccessfulBlocks != successfulBlocks) {
252 firePropertyChange(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
257 * @return the failedBlocks
259 public int getFailedBlocks() {
264 * @param failedBlocks
265 * the failedBlocks to set
267 public void setFailedBlocks(int failedBlocks) {
268 int oldFailedBlocks = this.failedBlocks;
269 this.failedBlocks = failedBlocks;
270 if (oldFailedBlocks != failedBlocks) {
271 firePropertyChange(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
276 * @return the fatallyFailedBlocks
278 public int getFatallyFailedBlocks() {
279 return fatallyFailedBlocks;
283 * @param fatallyFailedBlocks
284 * the fatallyFailedBlocks to set
286 public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
287 int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
288 this.fatallyFailedBlocks = fatallyFailedBlocks;
289 if (oldFatallyFailedBlocks != fatallyFailedBlocks) {
290 firePropertyChange(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
295 * @return the totalFinalized
297 public boolean isTotalFinalized() {
298 return totalFinalized;
302 * @param totalFinalized
303 * the totalFinalized to set
305 public void setTotalFinalized(boolean totalFinalized) {
306 boolean oldTotalFinalized = this.totalFinalized;
307 this.totalFinalized = totalFinalized;
308 if (oldTotalFinalized != totalFinalized) {
309 firePropertyChange(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);