add SimpleProgress
[jSite2.git] / src / net / pterodactylus / util / 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.util.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 Roden <droden@gmail.com>
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         public 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                 try {
49                         return Integer.valueOf(getField("Total"));
50                 } catch (NumberFormatException nfe1) {
51                         return -1;
52                 }
53         }
54
55         /**
56          * Returns the number of blocks that are required to completet the request.
57          * This number might actually be lower than {@link #getTotal} because of
58          * redundancy information. This number may also increase as long as
59          * {@link #isFinalizedTotal()} returns <code>false</code>.
60          * 
61          * @return The number of required blocks
62          */
63         public int getRequired() {
64                 try {
65                         return Integer.valueOf(getField("Required"));
66                 } catch (NumberFormatException nfe1) {
67                         return -1;
68                 }
69         }
70
71         /**
72          * Returns the number of blocks that have failed and run out of retries.
73          * 
74          * @return The number of failed blocks
75          */
76         public int getFailed() {
77                 try {
78                         return Integer.valueOf(getField("Failed"));
79                 } catch (NumberFormatException nfe1) {
80                         return -1;
81                 }
82         }
83
84         /**
85          * Returns the number of fatally failed blocks. A block that failed fatally
86          * can never be completed, even with infinite retries.
87          * 
88          * @return The number of fatally failed blocks
89          */
90         public int getFatallyFailed() {
91                 try {
92                         return Integer.valueOf(getField("FatallyFailed"));
93                 } catch (NumberFormatException nfe1) {
94                         return -1;
95                 }
96         }
97
98         /**
99          * Returns the number of blocks that have been successfully processed.
100          * 
101          * @return The number of succeeded blocks
102          */
103         public int getSucceeded() {
104                 try {
105                         return Integer.valueOf(getField("Succeeded"));
106                 } catch (NumberFormatException nfe1) {
107                         return -1;
108                 }
109         }
110
111         /**
112          * Returns whether the total number of blocks (see {@link #getTotal()} has
113          * been finalized. Once the total number of blocks has been finalized for a
114          * request it will not change any more, and this method of every further
115          * SimpleProgress message will always return <code>true</code>.
116          * 
117          * @return <code>true</code> if the number of total blocks has been
118          *         finalized, <code>false</code> otherwise
119          */
120         public boolean isFinalizedTotal() {
121                 return Boolean.valueOf(getField("FinalizedTotal"));
122         }
123
124         /**
125          * Returns the identifier of the request.
126          * 
127          * @return The identifier of the request
128          */
129         public String getIdentifier() {
130                 return getField("Identifier");
131         }
132
133 }