add listener for progress events
[jFCPlib.git] / src / net / pterodactylus / fcp / highlevel / HighLevelProgress.java
1 /*
2  * jFCPlib-high-level-client - HighLevelContinuosResult.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.highlevel;
21
22 /**
23  * Result for operations that send progress messages until they have completed.
24  * 
25  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26  * @version $Id$
27  */
28 public class HighLevelProgress extends HighLevelResult {
29
30         /** The number of total blocks. */
31         private int totalBlocks;
32
33         /** The number of required blocks. */
34         private int requiredBlocks;
35
36         /** The number of successfully transferred blocks. */
37         private int successfulBlocks;
38
39         /** The number of failed blocks. */
40         private int failedBlocks;
41
42         /** The number of fatally failed blocks. */
43         private int fatallyFailedBlocks;
44
45         /** Whether the total number is finalized. */
46         private boolean totalFinalized;
47
48         /**
49          * Package-private constructor.
50          * 
51          * @param identifier
52          *            The identifier of the request
53          */
54         public HighLevelProgress(String identifier) {
55                 super(identifier);
56         }
57
58         /**
59          * Creates a new high-level progress with the given values.
60          * 
61          * @param identifier
62          *            The identifier of the request
63          * @param totalBlocks
64          *            The total number of blocks
65          * @param requiredBlocks
66          *            The number of required blocks
67          * @param successfulBlocks
68          *            The number of successful blocks
69          * @param failedBlocks
70          *            The number of failed blocks
71          * @param fatallyFailedBlocks
72          *            The number of fatally failed blocks
73          * @param totalFinalized
74          *            <code>true</code> if the total number of blocks is
75          *            finalized, <code>false</code> otherwise
76          */
77         public HighLevelProgress(String identifier, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean totalFinalized) {
78                 this(identifier);
79                 this.totalBlocks = totalBlocks;
80                 this.requiredBlocks = requiredBlocks;
81                 this.successfulBlocks = successfulBlocks;
82                 this.failedBlocks = failedBlocks;
83                 this.fatallyFailedBlocks = fatallyFailedBlocks;
84                 this.totalFinalized = totalFinalized;
85         }
86
87         /**
88          * Returns the number of total blocks.
89          * 
90          * @return The number of total blocks
91          */
92         public int getTotalBlocks() {
93                 return totalBlocks;
94         }
95
96         /**
97          * Sets the number of total blocks.
98          * 
99          * @param totalBlocks
100          *            The number of total blocks
101          */
102         void setTotalBlocks(int totalBlocks) {
103                 this.totalBlocks = totalBlocks;
104         }
105
106         /**
107          * Returns the number of required blocks. For downloads, this number is
108          * smaller than {@link #getTotalBlocks()}.
109          * 
110          * @return The number of required blocks
111          */
112         public int getRequiredBlocks() {
113                 return requiredBlocks;
114         }
115
116         /**
117          * Sets the number of required blocks.
118          * 
119          * @param requiredBlocks
120          *            The number of required blocks
121          */
122         void setRequiredBlocks(int requiredBlocks) {
123                 this.requiredBlocks = requiredBlocks;
124         }
125
126         /**
127          * Returns the number of successfully transferred blocks.
128          * 
129          * @return The number of successfully transferred blocks
130          */
131         public int getSuccessfulBlocks() {
132                 return successfulBlocks;
133         }
134
135         /**
136          * Sets the number of successfully transferred blocks.
137          * 
138          * @param successfulBlocks
139          *            The number of successfully transferred blocks
140          */
141         void setSuccessfulBlocks(int successfulBlocks) {
142                 this.successfulBlocks = successfulBlocks;
143         }
144
145         /**
146          * Returns the number of failed blocks. Blocks that have failed can be
147          * retried.
148          * 
149          * @return The number of failed blocks
150          */
151         public int getFailedBlocks() {
152                 return failedBlocks;
153         }
154
155         /**
156          * Sets the number of failed blocks.
157          * 
158          * @param failedBlocks
159          *            The number of failed blocks
160          */
161         void setFailedBlocks(int failedBlocks) {
162                 this.failedBlocks = failedBlocks;
163         }
164
165         /**
166          * Returns the number of fatally failed blocks. Fatally failed blocks will
167          * never complete, even with endless retries.
168          * 
169          * @return The number of fatally failed blocks
170          */
171         public int getFatallyFailedBlocks() {
172                 return fatallyFailedBlocks;
173         }
174
175         /**
176          * Sets the number of fatally failed blocks.
177          * 
178          * @param fatallyFailedBlocks
179          *            The number fatally failed blocks
180          */
181         void setFatallyFailedBlocks(int fatallyFailedBlocks) {
182                 this.fatallyFailedBlocks = fatallyFailedBlocks;
183         }
184
185         /**
186          * Returns whether the result of {@link #getTotalBlocks()} is final, i.e. it
187          * won’t change anymore.
188          * 
189          * @return <code>true</code> if the result of {@link #getTotalBlocks()} is
190          *         final, <code>false</code> otherwise
191          */
192         public boolean isTotalFinalized() {
193                 return totalFinalized;
194         }
195
196         /**
197          * Sets whether the result of {@link #getTotalBlocks()} is final, i.e. it
198          * won’t change anymore.
199          * 
200          * @param totalFinalized
201          *            <code>true</code> if the result of {@link #getTotalBlocks()}
202          *            is final, <code>false</code> otherwise
203          */
204         void setTotalFinalized(boolean totalFinalized) {
205                 this.totalFinalized = totalFinalized;
206         }
207
208 }