add EndListPersistentRequests
[jSite2.git] / src / net / pterodactylus / util / fcp / PersistentPut.java
1 /**
2  * © 2008 INA Service GmbH
3  */
4 package net.pterodactylus.util.fcp;
5
6 /**
7  * A “PersistentPut” message notifies a client about a persistent
8  * {@link ClientPut} request.
9  * 
10  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
11  * @version $Id$
12  */
13 public class PersistentPut extends BaseMessage {
14
15         /**
16          * Creates a new “PersistentPut” message that wraps the received message.
17          * 
18          * @param receivedMessage
19          *            The received message
20          */
21         public PersistentPut(FcpMessage receivedMessage) {
22                 super(receivedMessage);
23         }
24
25         /**
26          * Returns the client token of the request.
27          * 
28          * @return The client token of the request
29          */
30         public String getClientToken() {
31                 return getField("ClientToken");
32         }
33
34         /**
35          * Returns the data length of the request.
36          * 
37          * @return The data length of the request, or <code>-1</code> if the
38          *         length could not be parsed
39          */
40         public long getDataLength() {
41                 try {
42                         return Long.valueOf(getField("DataLength"));
43                 } catch (NumberFormatException nfe1) {
44                         return -1;
45                 }
46         }
47
48         /**
49          * Returns whether the request is on the global queue.
50          * 
51          * @return <code>true</code> if the request is on the global queue,
52          *         <code>false</code> otherwise
53          */
54         public boolean isGlobal() {
55                 return Boolean.valueOf(getField("Global"));
56         }
57
58         /**
59          * Returns the identifier of the request.
60          * 
61          * @return The identifier of the request
62          */
63         public String getIdentifier() {
64                 return getField("Identifier");
65         }
66
67         /**
68          * Returns the maximum number of retries for failed blocks. When
69          * <code>-1</code> is returned each block is tried forever.
70          * 
71          * @return The maximum number of retries for failed blocks, or
72          *         <code>-1</code> for unlimited retries, or <code>-2</code> if
73          *         the number of retries could not be parsed
74          */
75         public int getMaxRetries() {
76                 try {
77                         return Integer.valueOf(getField("MaxRetries"));
78                 } catch (NumberFormatException nfe1) {
79                         /* we need to return -2 here as -1 is also a valid value. */
80                         return -2;
81                 }
82         }
83
84         /**
85          * Returns the content type of the data.
86          * 
87          * @return The content type
88          */
89         public String getMetadataContentType() {
90                 return getField("Metadata.ContentType");
91         }
92
93         /**
94          * Returns the persistence of the request.
95          * 
96          * @return The persistence of the request
97          */
98         public Persistence getPersistence() {
99                 return Persistence.valueOf(getField("Persistence"));
100         }
101
102         /**
103          * Returns the priority of the request.
104          * 
105          * @return The priority of the request, or {@link Priority#unknown} if the
106          *         priority could not be parsed
107          */
108         public Priority getPriority() {
109                 try {
110                         return Priority.values()[Integer.valueOf(getField("Priority"))];
111                 } catch (NumberFormatException nfe1) {
112                         return Priority.unknown;
113                 }
114         }
115
116         /**
117          * Returns whether this request has started.
118          * 
119          * @return <code>true</code> if the request has started,
120          *         <code>false</code> otherwise
121          */
122         public boolean isStarted() {
123                 return Boolean.valueOf(getField("Started"));
124         }
125
126         /**
127          * Returns the target filename of the request.
128          * 
129          * @return The target filename of the request
130          */
131         public String getTargetFilename() {
132                 return getField("TargetFilename");
133         }
134
135         /**
136          * Returns the upload source of the request.
137          * 
138          * @return The upload source of the request
139          */
140         public UploadFrom getUploadFrom() {
141                 return UploadFrom.valueOf(getField("UploadFrom"));
142         }
143
144         /**
145          * Returns the target URI of the request.
146          * 
147          * @return The target URI of the request
148          */
149         public String getURI() {
150                 return getField("URI");
151         }
152
153         /**
154          * Returns the verbosity of the request.
155          * 
156          * @return The verbosity of the request
157          */
158         public Verbosity getVerbosity() {
159                 return Verbosity.valueOf(getField("Verbosity"));
160         }
161
162 }