X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FHighLevelProgress.java;h=32f08841536c29b8ca4534bd3fb18996a0bd4841;hb=c6d398abde5664ea2c8c01532e53d634a67bcc09;hp=ec648f8e1f3e8ff635bf3749f5be4b6450760c42;hpb=16353715c279d8b535b7aabb287764e591788c92;p=jFCPlib.git diff --git a/src/net/pterodactylus/fcp/highlevel/HighLevelProgress.java b/src/net/pterodactylus/fcp/highlevel/HighLevelProgress.java index ec648f8..32f0884 100644 --- a/src/net/pterodactylus/fcp/highlevel/HighLevelProgress.java +++ b/src/net/pterodactylus/fcp/highlevel/HighLevelProgress.java @@ -21,11 +21,35 @@ package net.pterodactylus.fcp.highlevel; /** * Result for operations that send progress messages until they have completed. + * The fields of the progress message has to be checked in given order because + * if you receive this progress asynchronously via a + * {@link HighLevelProgressListener} the progress will not have any state, you + * will simply get the latest results, with other fields unset. First you should + * check whether {@link #isFinished()} returns true. If it does, + * the request is finished and {@link #isFailed()} will tell you whether the + * request has failed or succeeded. Other fields are not set. If the request is + * not yet finished, {@link #isFetchable()} will tell you whether the request + * has progressed to a state that allows other clients to fetch the inserted + * data. This is of course only valid for Put and PutDir requests. Alternatively + * {@link #getURI()} can return a non-null value which signals + * that the request generated a URI. If none of those methods return + * true, you can use the block count methods to get detailed + * progress statistics. When progress you received is a {@link DownloadResult} + * you do not need to check * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ -public abstract class HighLevelProgress extends HighLevelResult { +public class HighLevelProgress extends HighLevelResult { + + /** Whether the request is finished. */ + private boolean finished; + + /** Whether a Put request should be fetchable now. */ + private boolean fetchable; + + /** The generated URI, in case of a Put request. */ + private String uri; /** The number of total blocks. */ private int totalBlocks; @@ -56,6 +80,129 @@ public abstract class HighLevelProgress extends HighLevelResult { } /** + * Creates a new high-level progress for a request that is finished. + * + * @param identifier + * The identifier of the request + * @param successful + * true if the request finished successfully, + * false otherwise + */ + public HighLevelProgress(String identifier, boolean successful) { + this(identifier); + finished = true; + setFailed(!successful); + } + + /** + * Creates a new high-level progress for a Put or PutDir request that + * generated a URI. + * + * @param identifier + * The identifier of the request + * @param uri + * The URI of the request + */ + public HighLevelProgress(String identifier, String uri) { + this(identifier); + this.uri = uri; + } + + /** + * Creates a new high-level progress with the given values. + * + * @param identifier + * The identifier of the request + * @param totalBlocks + * The total number of blocks + * @param requiredBlocks + * The number of required blocks + * @param successfulBlocks + * The number of successful blocks + * @param failedBlocks + * The number of failed blocks + * @param fatallyFailedBlocks + * The number of fatally failed blocks + * @param totalFinalized + * true if the total number of blocks is + * finalized, false otherwise + */ + public HighLevelProgress(String identifier, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean totalFinalized) { + this(identifier); + this.totalBlocks = totalBlocks; + this.requiredBlocks = requiredBlocks; + this.successfulBlocks = successfulBlocks; + this.failedBlocks = failedBlocks; + this.fatallyFailedBlocks = fatallyFailedBlocks; + this.totalFinalized = totalFinalized; + } + + /** + * Returns whether this progress means that a request has finished. Use + * {@link #isFailed()} to check if the request failed. + * + * @see #isFailed() + * @return true if the request has finished + */ + public boolean isFinished() { + return finished; + } + + /** + * Sets whether the request described by this progress has finished. + * + * @param finished + * true if the request has finished, + * false otherwise + */ + void setFinished(boolean finished) { + this.finished = finished; + } + + /** + * Returns whether the request should be fetchable now, in case it was a Put + * request. + * + * @return true if the request should be fetchable now, + * false otherwise + */ + public boolean isFetchable() { + return fetchable; + } + + /** + * Sets whether the request should be fetchable now, in case it was a Put + * request. + * + * @param fetchable + * true if the request should be fetchable now, + * false otherwise + */ + void setFetchable(boolean fetchable) { + this.fetchable = fetchable; + } + + /** + * Returns the URI that was generated by the request. Of course only Put and + * PutDir requests will generated URIs. + * + * @return The generated URI + */ + public String getURI() { + return uri; + } + + /** + * Sets the URI generated by the request. + * + * @param uri + * The generated URI + */ + void setURI(String uri) { + this.uri = uri; + } + + /** * Returns the number of total blocks. * * @return The number of total blocks