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