X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FRequest.java;h=a61bb94ef0a11f571890dcaac97e67c7e1d31d99;hb=708d0d9f54df2f6c02f31c75555a029ec8702614;hp=47349ca6e0fef62011007f92f7b25984acb82e7b;hpb=7ccb1fcb746198ee1417bb2f92c846132bf6bc96;p=jSite2.git
diff --git a/src/net/pterodactylus/jsite/core/Request.java b/src/net/pterodactylus/jsite/core/Request.java
index 47349ca..a61bb94 100644
--- a/src/net/pterodactylus/jsite/core/Request.java
+++ b/src/net/pterodactylus/jsite/core/Request.java
@@ -19,34 +19,390 @@
package net.pterodactylus.jsite.core;
+import net.pterodactylus.util.beans.AbstractBean;
+
/**
* A request is an ongoing download or upload reported by the freenet node.
- *
+ *
* @author David âBombeâ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
-public class Request {
+public class Request extends AbstractBean {
+
+ /**
+ * The type of a request.
+ *
+ * @author David âBombeâ Roden <bombe@freenetproject.org>
+ */
+ public enum Type {
+
+ /** Type of request is unknown. */
+ unknown,
+
+ /** The request is a Get request. */
+ get,
+
+ /** The request is a Put request. */
+ put,
+
+ /** The request is a PutDir request. */
+ putDir
+
+ }
+
+ /** Name of the âtypeâ property. */
+ public static final String PROPERTY_TYPE = "type";
+
+ /** Name of the âclient tokenâ property. */
+ public static final String PROPERTY_CLIENT_TOKEN = "clientToken";
+
+ /** Name of the âfinishedâ property. */
+ public static final String PROPERTY_FINISHED = "finished";
+
+ /** Name of the âsuccessfulâ property. */
+ public static final String PROPERTY_SUCCESSFUL = "successful";
+
+ /** Name of the âfetchableâ property. */
+ public static final String PROPERTY_FETCHABLE = "fetchable";
+
+ /** Name of the âURIâ property. */
+ public static final String PROPERTY_URI = "uri";
+
+ /** Name of the âtotal blocksâ property. */
+ public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
+
+ /** Name of the ârequired blocksâ property. */
+ public static final String PROPERTY_REQUIRED_BLOCKS = "requiredBlocks";
+
+ /** Name of the âsuccessful blocksâ property. */
+ public static final String PROPERTY_SUCCESSFUL_BLOCKS = "successfulBlocks";
+
+ /** Name of the âfailed blocksâ property. */
+ public static final String PROPERTY_FAILED_BLOCKS = "failedBlocks";
+
+ /** Name of the âfatally failed blocksâ property. */
+ public static final String PROPERTY_FATALLY_FAILED_BLOCKS = "fatallyFailedBlocks";
+
+ /** Name of the âtotal finalizedâ property. */
+ public static final String PROPERTY_TOTAL_FINALIZED = "totalFinalized";
+
+ /** The node the request belongs to. */
+ private final Node node;
/** The identifier of the request. */
private final String identifier;
+ /** The type of the request. */
+ private Type type;
+
+ /** The client token of the request. */
+ private String clientToken;
+
+ /** Whether the request is finished. */
+ private boolean finished;
+
+ /** Whether the request was finished successfully. */
+ private boolean successful;
+
+ /** Whether the data is already fetchable (in case of put requests). */
+ private boolean fetchable;
+
+ /** The generated URI. */
+ private String uri;
+
+ /** The total number of blocks. */
+ private int totalBlocks;
+
+ /** The required number of blocks. */
+ private int requiredBlocks;
+
+ /** The number of successful blocks. */
+ private int successfulBlocks;
+
+ /** The number of failedBlocks. */
+ private int failedBlocks;
+
+ /** The number of fatally failed blocks. */
+ private int fatallyFailedBlocks;
+
+ /** Whether the total number has been finalized. */
+ private boolean totalFinalized;
+
/**
* Creates a new request with the given identifier.
- *
+ *
+ * @param node
+ * The node the request belongs to
* @param identifier
* The identifier of the request
*/
- Request(String identifier) {
+ Request(Node node, String identifier) {
+ this.node = node;
this.identifier = identifier;
}
+ //
+ // EVENT MANAGEMENT
+ //
+
+ /**
+ * Returns the node the request belongs to.
+ *
+ * @return The node the request belongs to
+ */
+ public Node getNode() {
+ return node;
+ }
+
/**
* Returns the identifier of the request. It is unique per node.
- *
+ *
* @return The identifier of the request
*/
public String getIdentifier() {
return identifier;
}
+ /**
+ * Returns the type of the request.
+ *
+ * @return The type of the request
+ */
+
+ public Type getType() {
+ return type;
+ }
+
+ /**
+ * Sets the type of the request.
+ *
+ * @param type
+ * The type of the request
+ */
+ void setType(Type type) {
+ Type oldType = this.type;
+ this.type = type;
+ fireIfPropertyChanged(PROPERTY_TYPE, oldType, type);
+ }
+
+ /**
+ * Returns the client token of the request.
+ *
+ * @return The client token of the request
+ */
+ public String getClientToken() {
+ return clientToken;
+ }
+
+ /**
+ * Sets the client token of the request.
+ *
+ * @param clientToken
+ * The client token of the request
+ */
+ void setClientToken(String clientToken) {
+ String oldClientToken = this.clientToken;
+ this.clientToken = clientToken;
+ fireIfPropertyChanged(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
+ }
+
+ /**
+ * Returns whether the request has finished.
+ *
+ * @see #isSuccessful()
+ * @return true
if the request is finished,
+ * false
otherwise
+ */
+ public boolean isFinished() {
+ return finished;
+ }
+
+ /**
+ * Sets whether the request has finished.
+ *
+ * @param finished
+ * true
if the request has finished,
+ * false
otherwise
+ */
+ void setFinished(boolean finished) {
+ boolean oldFinished = this.finished;
+ this.finished = finished;
+ firePropertyChange(PROPERTY_FINISHED, oldFinished, finished);
+ }
+
+ /**
+ * Returns whether the request finished successfully. This value will only
+ * have meaning if {@link #isFinished()} returns true
.
+ *
+ * @return true
if the request finished successfully,
+ * false
otherwise
+ */
+ public boolean isSuccessful() {
+ return successful;
+ }
+
+ /**
+ * Sets whether this request finished successfully.
+ *
+ * @param successful
+ * true
if the request finished successfully,
+ * false
otherwise
+ */
+ void setSuccessful(boolean successful) {
+ boolean oldSuccessful = this.successful;
+ this.successful = successful;
+ firePropertyChange(PROPERTY_SUCCESSFUL, oldSuccessful, successful);
+ }
+
+ /**
+ * Returns whether the data inserted by this {@link Type#put} or
+ * {@link Type#putDir} request is already fetchable by other clients.
+ *
+ * @return true
if the data is already fetchable,
+ * false
otherwise
+ */
+ public boolean isFetchable() {
+ return fetchable;
+ }
+
+ /**
+ * Sets whether the data inserted by this {@link Type#put} or
+ * {@link Type#putDir} request is already fetchable by other clients.
+ *
+ * @param fetchable
+ * true
if the data is already fetchable,
+ * false
otherwise
+ */
+ void setFetchable(boolean fetchable) {
+ boolean oldFetchable = this.fetchable;
+ this.fetchable = fetchable;
+ firePropertyChange(PROPERTY_FETCHABLE, oldFetchable, fetchable);
+ }
+
+ /**
+ * Returns the URI generated by this request.
+ *
+ * @return The generated URI
+ */
+ public String getURI() {
+ return uri;
+ }
+
+ /**
+ * Sets the URI generated by this request.
+ *
+ * @param uri
+ * The generated URI
+ */
+ void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns the total number of blocks of a request. Until
+ * {@link #isTotalFinalized()} returns true
this value may
+ * change!
+ *
+ * @return The total number of blocks of a request
+ */
+ public int getTotalBlocks() {
+ return totalBlocks;
+ }
+
+ /**
+ * Sets the total number of blocks of a request.
+ *
+ * @param totalBlocks
+ * The total number of blocks
+ */
+ void setTotalBlocks(int totalBlocks) {
+ int oldTotalBlocks = this.totalBlocks;
+ this.totalBlocks = totalBlocks;
+ fireIfPropertyChanged(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
+ }
+
+ /**
+ * @return the requiredBlocks
+ */
+ public int getRequiredBlocks() {
+ return requiredBlocks;
+ }
+
+ /**
+ * @param requiredBlocks
+ * the requiredBlocks to set
+ */
+ void setRequiredBlocks(int requiredBlocks) {
+ int oldRequiredBlocks = this.requiredBlocks;
+ this.requiredBlocks = requiredBlocks;
+ fireIfPropertyChanged(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
+ }
+
+ /**
+ * @return the successfulBlocks
+ */
+ public int getSuccessfulBlocks() {
+ return successfulBlocks;
+ }
+
+ /**
+ * @param successfulBlocks
+ * the successfulBlocks to set
+ */
+ void setSuccessfulBlocks(int successfulBlocks) {
+ int oldSuccessfulBlocks = this.successfulBlocks;
+ this.successfulBlocks = successfulBlocks;
+ fireIfPropertyChanged(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
+ }
+
+ /**
+ * @return the failedBlocks
+ */
+ public int getFailedBlocks() {
+ return failedBlocks;
+ }
+
+ /**
+ * @param failedBlocks
+ * the failedBlocks to set
+ */
+ void setFailedBlocks(int failedBlocks) {
+ int oldFailedBlocks = this.failedBlocks;
+ this.failedBlocks = failedBlocks;
+ fireIfPropertyChanged(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
+ }
+
+ /**
+ * @return the fatallyFailedBlocks
+ */
+ public int getFatallyFailedBlocks() {
+ return fatallyFailedBlocks;
+ }
+
+ /**
+ * @param fatallyFailedBlocks
+ * the fatallyFailedBlocks to set
+ */
+ void setFatallyFailedBlocks(int fatallyFailedBlocks) {
+ int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
+ this.fatallyFailedBlocks = fatallyFailedBlocks;
+ fireIfPropertyChanged(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
+ }
+
+ /**
+ * @return the totalFinalized
+ */
+ public boolean isTotalFinalized() {
+ return totalFinalized;
+ }
+
+ /**
+ * @param totalFinalized
+ * the totalFinalized to set
+ */
+ void setTotalFinalized(boolean totalFinalized) {
+ boolean oldTotalFinalized = this.totalFinalized;
+ this.totalFinalized = totalFinalized;
+ fireIfPropertyChanged(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);
+ }
+
}