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