0522a177b32c3c439b37bb42bc083518c2222295
[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         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                 return FcpUtils.safeParseLong(getField("DataLength"));
42         }
43
44         /**
45          * Returns whether the request is on the global queue.
46          * 
47          * @return <code>true</code> if the request is on the global queue,
48          *         <code>false</code> otherwise
49          */
50         public boolean isGlobal() {
51                 return Boolean.valueOf(getField("Global"));
52         }
53
54         /**
55          * Returns the identifier of the request.
56          * 
57          * @return The identifier of the request
58          */
59         public String getIdentifier() {
60                 return getField("Identifier");
61         }
62
63         /**
64          * Returns the maximum number of retries for failed blocks. When
65          * <code>-1</code> is returned each block is tried forever.
66          * 
67          * @return The maximum number of retries for failed blocks, or
68          *         <code>-1</code> for unlimited retries, or <code>-2</code> if
69          *         the number of retries could not be parsed
70          */
71         public int getMaxRetries() {
72                 return FcpUtils.safeParseInt(getField("MaxRetries"));
73         }
74
75         /**
76          * Returns the content type of the data.
77          * 
78          * @return The content type
79          */
80         public String getMetadataContentType() {
81                 return getField("Metadata.ContentType");
82         }
83
84         /**
85          * Returns the persistence of the request.
86          * 
87          * @return The persistence of the request
88          */
89         public Persistence getPersistence() {
90                 return Persistence.valueOf(getField("Persistence"));
91         }
92
93         /**
94          * Returns the priority of the request.
95          * 
96          * @return The priority of the request, or {@link Priority#unknown} if the
97          *         priority could not be parsed
98          */
99         public Priority getPriority() {
100                 try {
101                         return Priority.values()[Integer.valueOf(getField("PriorityClass"))];
102                 } catch (NumberFormatException nfe1) {
103                         return Priority.unknown;
104                 }
105         }
106
107         /**
108          * Returns whether this request has started.
109          * 
110          * @return <code>true</code> if the request has started,
111          *         <code>false</code> otherwise
112          */
113         public boolean isStarted() {
114                 return Boolean.valueOf(getField("Started"));
115         }
116
117         /**
118          * Returns the target filename of the request.
119          * 
120          * @return The target filename of the request
121          */
122         public String getTargetFilename() {
123                 return getField("TargetFilename");
124         }
125
126         /**
127          * Returns the upload source of the request.
128          * 
129          * @return The upload source of the request
130          */
131         public UploadFrom getUploadFrom() {
132                 return UploadFrom.valueOf(getField("UploadFrom"));
133         }
134
135         /**
136          * Returns the target URI of the request.
137          * 
138          * @return The target URI of the request
139          */
140         public String getURI() {
141                 return getField("URI");
142         }
143
144         /**
145          * Returns the verbosity of the request.
146          * 
147          * @return The verbosity of the request
148          */
149         public Verbosity getVerbosity() {
150                 return Verbosity.valueOf(getField("Verbosity"));
151         }
152
153 }