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;
24 import net.pterodactylus.util.beans.Comparer;
27 * A request is an ongoing download or upload reported by the freenet node.
29 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
32 public class Request extends
36 * The type of a request.
38 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
43 /** Type of request is unknown. */
46 /** The request is a Get request. */
49 /** The request is a Put request. */
52 /** The request is a PutDir request. */
57 /** Name of the “type” property. */
58 public static final String PROPERTY_TYPE = "type";
60 /** Name of the “client token” property. */
61 public static final String PROPERTY_CLIENT_TOKEN = "clientToken";
63 /** Name of the “total blocks” property. */
64 public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
66 /** Name of the “required blocks” property. */
67 public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
69 /** Name of the “successful blocks” property. */
70 public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
72 /** Name of the “failed blocks” property. */
73 public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
75 /** Name of the “fatally failed blocks” property. */
76 public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
78 /** Name of the “total finalized” property. */
79 public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
81 /** The node the request belongs to. */
82 private final Node node;
84 /** The identifier of the request. */
85 private final String identifier;
87 /** The type of the request. */
90 /** The client token of the request. */
91 private String clientToken;
93 /** The total number of blocks. */
94 private int totalBlocks;
96 /** The required number of blocks. */
97 private int requiredBlocks;
99 /** The number of successful blocks. */
100 private int successfulBlocks;
102 /** The number of failedBlocks. */
103 private int failedBlocks;
105 /** The number of fatally failed blocks. */
106 private int fatallyFailedBlocks;
108 /** Whether the total number has been finalized. */
109 private boolean totalFinalized;
112 * Creates a new request with the given identifier.
115 * The node the request belongs to
117 * The identifier of the request
119 Request(Node node, String identifier) {
121 this.identifier = identifier;
129 * Returns the node the request belongs to.
131 * @return The node the request belongs to
133 public Node getNode() {
138 * Returns the identifier of the request. It is unique per node.
140 * @return The identifier of the request
142 public String getIdentifier() {
147 * Returns the type of the request.
149 * @return The type of the request
152 public Type getType() {
157 * Sets the type of the request.
160 * The type of the request
163 public void setType(Type type) {
164 Type oldType = this.type;
166 if (!Comparer.equal(oldType, type)) {
167 firePropertyChange(PROPERTY_TYPE, oldType, type);
172 * Returns the client token of the request.
174 * @return The client token of the request
176 public String getClientToken() {
181 * Sets the client token of the request.
184 * The client token of the request
186 public void setClientToken(String clientToken) {
187 String oldClientToken = this.clientToken;
188 this.clientToken = clientToken;
189 if (!Comparer.equal(oldClientToken, clientToken)) {
190 firePropertyChange(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
195 * Returns the total number of blocks of a request. Until
196 * {@link #isTotalFinalized()} returns <code>true</code> this value may
199 * @return The total number of blocks of a request
201 public int getTotalBlocks() {
206 * Sets the total number of blocks of a request.
209 * The total number of blocks
211 public void setTotalBlocks(int totalBlocks) {
212 int oldTotalBlocks = this.totalBlocks;
213 this.totalBlocks = totalBlocks;
214 if (oldTotalBlocks != totalBlocks) {
215 firePropertyChange(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
220 * @return the requiredBlocks
222 public int getRequiredBlocks() {
223 return requiredBlocks;
227 * @param requiredBlocks
228 * the requiredBlocks to set
230 public void setRequiredBlocks(int requiredBlocks) {
231 int oldRequiredBlocks = this.requiredBlocks;
232 this.requiredBlocks = requiredBlocks;
233 if (oldRequiredBlocks != requiredBlocks) {
234 firePropertyChange(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
239 * @return the successfulBlocks
241 public int getSuccessfulBlocks() {
242 return successfulBlocks;
246 * @param successfulBlocks
247 * the successfulBlocks to set
249 public void setSuccessfulBlocks(int successfulBlocks) {
250 int oldSuccessfulBlocks = this.successfulBlocks;
251 this.successfulBlocks = successfulBlocks;
252 if (oldSuccessfulBlocks != successfulBlocks) {
253 firePropertyChange(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
258 * @return the failedBlocks
260 public int getFailedBlocks() {
265 * @param failedBlocks
266 * the failedBlocks to set
268 public void setFailedBlocks(int failedBlocks) {
269 int oldFailedBlocks = this.failedBlocks;
270 this.failedBlocks = failedBlocks;
271 if (oldFailedBlocks != failedBlocks) {
272 firePropertyChange(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
277 * @return the fatallyFailedBlocks
279 public int getFatallyFailedBlocks() {
280 return fatallyFailedBlocks;
284 * @param fatallyFailedBlocks
285 * the fatallyFailedBlocks to set
287 public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
288 int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
289 this.fatallyFailedBlocks = fatallyFailedBlocks;
290 if (oldFatallyFailedBlocks != fatallyFailedBlocks) {
291 firePropertyChange(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
296 * @return the totalFinalized
298 public boolean isTotalFinalized() {
299 return totalFinalized;
303 * @param totalFinalized
304 * the totalFinalized to set
306 public void setTotalFinalized(boolean totalFinalized) {
307 boolean oldTotalFinalized = this.totalFinalized;
308 this.totalFinalized = totalFinalized;
309 if (oldTotalFinalized != totalFinalized) {
310 firePropertyChange(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);