-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(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 <code>true</code> if the request is finished,
- * <code>false</code> otherwise
- */
- public boolean isFinished() {
- return finished;
- }
-
- /**
- * Sets whether the request has finished.
- *
- * @param finished
- * <code>true</code> if the request has finished,
- * <code>false</code> 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 <code>true</code>.
- *
- * @return <code>true</code> if the request finished successfully,
- * <code>false</code> otherwise
- */
- public boolean isSuccessful() {
- return successful;
- }
-
- /**
- * Sets whether this request finished successfully.
- *
- * @param successful
- * <code>true</code> if the request finished successfully,
- * <code>false</code> 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 <code>true</code> if the data is already fetchable,
- * <code>false</code> otherwise
- */
- public boolean isFetchable() {
- return fetchable;
- }