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