From 17b4e836ca0fe816f9c28f96368c4f4900031928 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 24 Mar 2009 23:15:32 +0100 Subject: [PATCH] Add base request wrapper. --- src/net/pterodactylus/fcp/highlevel/Request.java | 348 +++++++++++++++++++++++ 1 file changed, 348 insertions(+) create mode 100644 src/net/pterodactylus/fcp/highlevel/Request.java diff --git a/src/net/pterodactylus/fcp/highlevel/Request.java b/src/net/pterodactylus/fcp/highlevel/Request.java new file mode 100644 index 0000000..dd6820f --- /dev/null +++ b/src/net/pterodactylus/fcp/highlevel/Request.java @@ -0,0 +1,348 @@ +/* + * jFCPlib - Request.java - + * Copyright © 2009 David Roden + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.pterodactylus.fcp.highlevel; + +import net.pterodactylus.fcp.PersistentGet; +import net.pterodactylus.fcp.PersistentPut; + +/** + * Wrapper class around request responses from the node, such as + * {@link PersistentGet} or {@link PersistentPut}. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + */ +public class Request { + + /** The identifier of the request. */ + private final String identifier; + + /** The client token of the request. */ + private final String clientToken; + + /** Whether the request is on the global queue. */ + private final boolean global; + + /** Whether the get request is complete. */ + private boolean complete; + + /** Whether the get request has failed. */ + private boolean failed; + + /** The data length. */ + private long length; + + /** The mime type. */ + private String contentType; + + /** The error code in case of failure. */ + private int errorCode; + + /** Whether the failure is fatal. */ + private boolean fatal; + + /** The total number of blocks. */ + private int totalBlocks; + + /** The required number of blocks. */ + private int requiredBlocks; + + /** The successfully processed number of blocks. */ + private int succeededBlocks; + + /** The number of failed blocks. */ + private int failedBlocks; + + /** The number of fatally failed blocks. */ + private int fatallyFailedBlocks; + + /** Whether the total number of blocks is finalized. */ + private boolean finalizedTotal; + + /** + * Creates a new request with the given identifier and client token. + * + * @param identifier + * The identifier of the request + * @param clientToken + * The client token of the request + * @param global + * true if the request is on the global queue, + * false otherwise + */ + protected Request(String identifier, String clientToken, boolean global) { + this.identifier = identifier; + this.clientToken = clientToken; + this.global = global; + } + + /** + * Returns the identifier of the request. + * + * @return The request’s identifier + */ + public String getIdentifier() { + return identifier; + } + + /** + * Returns the client token of the request. + * + * @return The request’s client token + */ + public String getClientToken() { + return clientToken; + } + + /** + * Returns whether this request is on the global queue. + * + * @return true if the request is on the global queue, + * false otherwise + */ + public boolean isGlobal() { + return global; + } + + /** + * Returns whether this request is complete. + * + * @return true if this request is complete, false otherwise + */ + public boolean isComplete() { + return complete; + } + + /** + * Sets whether this request is complete. + * + * @param complete + * true if this request is complete, false otherwise + */ + void setComplete(boolean complete) { + this.complete = complete; + } + + /** + * Returns whether this request has failed. This method should only be + * called if {@link #isComplete()} returns true. + * + * @return true if this request failed, false + * otherwise + */ + public boolean hasFailed() { + return failed; + } + + /** + * Sets whether this request has failed. + * + * @param failed + * true if this request failed, false + * otherwise + */ + void setFailed(boolean failed) { + this.failed = failed; + } + + /** + * Returns the length of the data. + * + * @return The length of the data + */ + public long getLength() { + return length; + } + + /** + * Sets the length of the data. + * + * @param length + * The length of the data + */ + void setLength(long length) { + this.length = length; + } + + /** + * Returns the content type of the data. + * + * @return The content type of the data + */ + public String getContentType() { + return contentType; + } + + /** + * Sets the content type of the data. + * + * @param contentType + * The content type of the data + */ + void setContentType(String contentType) { + this.contentType = contentType; + } + + /** + * Returns the error code. This method should only be called if + * {@link #hasFailed()} returns true. + * + * @return The error code + */ + public int getErrorCode() { + return errorCode; + } + + /** + * Sets the error code. + * + * @param errorCode + * The error code + */ + void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + /** + * Returns whether this request has fatally failed, i.e. repitition will not + * cause the request to succeed. + * + * @return true if this request can not be made succeed by + * repeating, false otherwise + */ + public boolean isFatal() { + return fatal; + } + + /** + * Sets whether this request has fatally failed. + * + * @param fatal + * true if this request failed fatally, + * false otherwise + * + */ + void setFatal(boolean fatal) { + this.fatal = fatal; + } + + /** + * Returns the total number of blocks of this request. + * + * @return This request’s total number of blocks + */ + public int getTotalBlocks() { + return totalBlocks; + } + + /** + * Sets the total number of blocks of this request. + * + * @param totalBlocks + * This request’s total number of blocks + */ + public void setTotalBlocks(int totalBlocks) { + this.totalBlocks = totalBlocks; + } + + /** + * TODO + * + * @return the requiredBlocks + */ + public int getRequiredBlocks() { + return requiredBlocks; + } + + /** + * TODO + * + * @param requiredBlocks + * the requiredBlocks to set + */ + public void setRequiredBlocks(int requiredBlocks) { + this.requiredBlocks = requiredBlocks; + } + + /** + * TODO + * + * @return the succeededBlocks + */ + public int getSucceededBlocks() { + return succeededBlocks; + } + + /** + * TODO + * + * @param succeededBlocks + * the succeededBlocks to set + */ + public void setSucceededBlocks(int succeededBlocks) { + this.succeededBlocks = succeededBlocks; + } + + /** + * TODO + * + * @return the failedBlocks + */ + public int getFailedBlocks() { + return failedBlocks; + } + + /** + * TODO + * + * @param failedBlocks + * the failedBlocks to set + */ + public void setFailedBlocks(int failedBlocks) { + this.failedBlocks = failedBlocks; + } + + /** + * TODO + * + * @return the fatallyFailedBlocks + */ + public int getFatallyFailedBlocks() { + return fatallyFailedBlocks; + } + + /** + * TODO + * + * @param fatallyFailedBlocks + * the fatallyFailedBlocks to set + */ + public void setFatallyFailedBlocks(int fatallyFailedBlocks) { + this.fatallyFailedBlocks = fatallyFailedBlocks; + } + + public boolean isFinalizedTotal() { + return finalizedTotal; + } + + void setFinalizedTotal(boolean finalizedTotal) { + this.finalizedTotal = finalizedTotal; + } + +} -- 2.7.4