add identifier to all requests
[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 abstract 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          * Returns the number of total blocks.
60          * 
61          * @return The number of total blocks
62          */
63         public int getTotalBlocks() {
64                 return totalBlocks;
65         }
66
67         /**
68          * Sets the number of total blocks.
69          * 
70          * @param totalBlocks
71          *            The number of total blocks
72          */
73         void setTotalBlocks(int totalBlocks) {
74                 this.totalBlocks = totalBlocks;
75         }
76
77         /**
78          * Returns the number of required blocks. For downloads, this number is
79          * smaller than {@link #getTotalBlocks()}.
80          * 
81          * @return The number of required blocks
82          */
83         public int getRequiredBlocks() {
84                 return requiredBlocks;
85         }
86
87         /**
88          * Sets the number of required blocks.
89          * 
90          * @param requiredBlocks
91          *            The number of required blocks
92          */
93         void setRequiredBlocks(int requiredBlocks) {
94                 this.requiredBlocks = requiredBlocks;
95         }
96
97         /**
98          * Returns the number of successfully transferred blocks.
99          * 
100          * @return The number of successfully transferred blocks
101          */
102         public int getSuccessfulBlocks() {
103                 return successfulBlocks;
104         }
105
106         /**
107          * Sets the number of successfully transferred blocks.
108          * 
109          * @param successfulBlocks
110          *            The number of successfully transferred blocks
111          */
112         void setSuccessfulBlocks(int successfulBlocks) {
113                 this.successfulBlocks = successfulBlocks;
114         }
115
116         /**
117          * Returns the number of failed blocks. Blocks that have failed can be
118          * retried.
119          * 
120          * @return The number of failed blocks
121          */
122         public int getFailedBlocks() {
123                 return failedBlocks;
124         }
125
126         /**
127          * Sets the number of failed blocks.
128          * 
129          * @param failedBlocks
130          *            The number of failed blocks
131          */
132         void setFailedBlocks(int failedBlocks) {
133                 this.failedBlocks = failedBlocks;
134         }
135
136         /**
137          * Returns the number of fatally failed blocks. Fatally failed blocks will
138          * never complete, even with endless retries.
139          * 
140          * @return The number of fatally failed blocks
141          */
142         public int getFatallyFailedBlocks() {
143                 return fatallyFailedBlocks;
144         }
145
146         /**
147          * Sets the number of fatally failed blocks.
148          * 
149          * @param fatallyFailedBlocks
150          *            The number fatally failed blocks
151          */
152         void setFatallyFailedBlocks(int fatallyFailedBlocks) {
153                 this.fatallyFailedBlocks = fatallyFailedBlocks;
154         }
155
156         /**
157          * Returns whether the result of {@link #getTotalBlocks()} is final, i.e. it
158          * won’t change anymore.
159          * 
160          * @return <code>true</code> if the result of {@link #getTotalBlocks()} is
161          *         final, <code>false</code> otherwise
162          */
163         public boolean isTotalFinalized() {
164                 return totalFinalized;
165         }
166
167         /**
168          * Sets whether the result of {@link #getTotalBlocks()} is final, i.e. it
169          * won’t change anymore.
170          * 
171          * @param totalFinalized
172          *            <code>true</code> if the result of {@link #getTotalBlocks()}
173          *            is final, <code>false</code> otherwise
174          */
175         void setTotalFinalized(boolean totalFinalized) {
176                 this.totalFinalized = totalFinalized;
177         }
178
179 }