rename fcplib to jFCPlib
[jFCPlib.git] / src / net / pterodactylus / fcp / SimpleProgress.java
1 /*
2  * jSite2 - SimpleProgress.java -
3  * Copyright © 2008 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package net.pterodactylus.fcp;
21
22 /**
23  * A “SimpleProgress” message tells the client about the progress of a
24  * {@link ClientGet} or {@link ClientPut} operation.
25  * 
26  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
27  * @version $Id$
28  */
29 public class SimpleProgress extends BaseMessage {
30
31         /**
32          * Creates a new “SimpleProgress” message that wraps the received message.
33          * 
34          * @param receivedMessage
35          *            The received message
36          */
37         SimpleProgress(FcpMessage receivedMessage) {
38                 super(receivedMessage);
39         }
40
41         /**
42          * Returns the total number of blocks. This number may increase as long as
43          * {@link #isFinalizedTotal()} returns <code>false</code>.
44          * 
45          * @return The total number of blocks
46          */
47         public int getTotal() {
48                 return FcpUtils.safeParseInt(getField("Total"));
49         }
50
51         /**
52          * Returns the number of blocks that are required to completet the request.
53          * This number might actually be lower than {@link #getTotal} because of
54          * redundancy information. This number may also increase as long as
55          * {@link #isFinalizedTotal()} returns <code>false</code>.
56          * 
57          * @return The number of required blocks
58          */
59         public int getRequired() {
60                 return FcpUtils.safeParseInt(getField("Required"));
61         }
62
63         /**
64          * Returns the number of blocks that have failed and run out of retries.
65          * 
66          * @return The number of failed blocks
67          */
68         public int getFailed() {
69                 return FcpUtils.safeParseInt(getField("Failed"));
70         }
71
72         /**
73          * Returns the number of fatally failed blocks. A block that failed fatally
74          * can never be completed, even with infinite retries.
75          * 
76          * @return The number of fatally failed blocks
77          */
78         public int getFatallyFailed() {
79                 return FcpUtils.safeParseInt(getField("FatallyFailed"));
80         }
81
82         /**
83          * Returns the number of blocks that have been successfully processed.
84          * 
85          * @return The number of succeeded blocks
86          */
87         public int getSucceeded() {
88                 return FcpUtils.safeParseInt(getField("Succeeded"));
89         }
90
91         /**
92          * Returns whether the total number of blocks (see {@link #getTotal()} has
93          * been finalized. Once the total number of blocks has been finalized for a
94          * request it will not change any more, and this method of every further
95          * SimpleProgress message will always return <code>true</code>.
96          * 
97          * @return <code>true</code> if the number of total blocks has been
98          *         finalized, <code>false</code> otherwise
99          */
100         public boolean isFinalizedTotal() {
101                 return Boolean.valueOf(getField("FinalizedTotal"));
102         }
103
104         /**
105          * Returns the identifier of the request.
106          * 
107          * @return The identifier of the request
108          */
109         public String getIdentifier() {
110                 return getField("Identifier");
111         }
112
113 }