jSite: First commit : verion 4.0 (written by Bombe)
[jSite.git] / src / de / todesbaum / util / freenet / fcp2 / ClientPut.java
1 /*
2  * todesbaum-lib - 
3  * Copyright (C) 2006 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 de.todesbaum.util.freenet.fcp2;
21
22 import java.io.IOException;
23 import java.io.Writer;
24
25 /**
26  * Abstract base class for all put requests. It contains all parameters that put
27  * requests have in common.
28  * 
29  * @author David Roden <droden@gmail.com>
30  * @version $Id: ClientPut.java 356 2006-03-24 15:13:38Z bombe $
31  */
32 public abstract class ClientPut extends Command {
33
34         /** The URI of this request. */
35         protected final String uri;
36         
37         /** The client token of this request. */
38         protected String clientToken = null;
39
40         /** Whether this request should only create a CHK. */
41         protected boolean getCHKOnly = false;
42
43         /** Whether this request is a global request. */
44         protected boolean global = false;
45
46         /** Whether the node should not try to compress the file. */
47         protected boolean dontCompress = false;
48
49         /** The maximum number of retries of this command. */
50         protected int maxRetries = 0;
51
52         /** The persistence of this request. */
53         protected Persistence persistence = Persistence.CONNECTION;
54
55         /** The priority class of this request. */
56         protected PriorityClass priorityClass = PriorityClass.INTERACTIVE;
57
58         /** The verbosiry of this request. */
59         protected Verbosity verbosity = Verbosity.NONE;
60
61         /**
62          * Creates a new put request with the specified name, identifier and URI.
63          * 
64          * @param name
65          *            The name of this request
66          * @param identifier
67          *            The identifier of this request
68          * @param uri
69          *            The URI of this request
70          */
71         protected ClientPut(String name, String identifier, String uri) {
72                 super(name, identifier);
73                 this.uri = uri;
74         }
75
76         /**
77          * Returns whether the node should not try to compress the data.
78          * 
79          * @return <code>true</code> if the node should <strong>not</strong> try
80          *         to compress the data
81          */
82         public boolean isDontCompress() {
83                 return dontCompress;
84         }
85
86         /**
87          * Sets whether the node should not try to compress the data. A client might
88          * set this hint on data that is clearly not compressible, like MPEG audio
89          * files, JPEG or PNG images, highly compressed movies, or compressed
90          * archives like ZIP files. Otherwise the node will try to compress the file
91          * which -- depending on the size of the data -- might take a lot of time
92          * and memory.
93          * 
94          * @param dontCompress
95          *            <code>true</code> if the node should <strong>not</strong>
96          *            try to compress the data
97          */
98         public void setDontCompress(boolean dontCompress) {
99                 this.dontCompress = dontCompress;
100         }
101
102         /**
103          * Returns whether this request should only return the CHK of the data.
104          * @return Whether this request should only return the CHK of the data
105          */
106         public boolean isGetCHKOnly() {
107                 return getCHKOnly;
108         }
109
110         /**
111          * Sets whether this request should only return the CHK of the data.
112          * @param getCHKOnly
113          *            <code>true</code> if this request should only return the CHK of the data
114          */
115         public void setGetCHKOnly(boolean getCHKOnly) {
116                 this.getCHKOnly = getCHKOnly;
117         }
118
119         /**
120          * Returns whether this request is a global request.
121          * @return <code>true</code> if this request is a global request, <code>false</code> otherwise
122          */
123         public boolean isGlobal() {
124                 return global;
125         }
126
127         /**
128          * Sets whether this request is a global request.
129          * @param global
130          *            <code>true</code> if this request is a global request, <code>false</code> otherwise
131          */
132         public void setGlobal(boolean global) {
133                 this.global = global;
134         }
135
136         /**
137          * Returns the maximum number of retries of this request.
138          * @return The maximum number of retries of this request
139          */
140         public int getMaxRetries() {
141                 return maxRetries;
142         }
143
144         /**
145          * Sets the maximum number of retries of this request
146          * @param maxRetries
147          *            The maximum number of retries of this request
148          */
149         public void setMaxRetries(int maxRetries) {
150                 this.maxRetries = maxRetries;
151         }
152
153         /**
154          * Returns the priority class of this request.
155          * @return The priority class of this request
156          */
157         public PriorityClass getPriorityClass() {
158                 return priorityClass;
159         }
160
161         /**
162          * Sets the priority class of this request.
163          * @param priorityClass
164          *            The priority class of this request
165          */
166         public void setPriorityClass(PriorityClass priorityClass) {
167                 this.priorityClass = priorityClass;
168         }
169
170         /**
171          * Returns the verbosity of this request.
172          * @return The verbosity of this request
173          */
174         public Verbosity getVerbosity() {
175                 return verbosity;
176         }
177
178         /**
179          * Sets the verbosity of this request.
180          * @param verbosity
181          *            The verbosity of this request
182          */
183         public void setVerbosity(Verbosity verbosity) {
184                 this.verbosity = verbosity;
185         }
186
187         /**
188          * Returns the URI of this request
189          * @return The URI of this request.
190          */
191         public String getUri() {
192                 return uri;
193         }
194
195         /**
196          * {@inheritDoc}
197          */
198         @Override
199         protected void write(Writer writer) throws IOException {
200                 super.write(writer);
201                 writer.write("URI=" + uri + LINEFEED);
202                 if (verbosity != null)
203                         writer.write("Verbosity=" + verbosity.getValue() + LINEFEED);
204                 if (maxRetries != 0)
205                         writer.write("MaxRetries=" + maxRetries + LINEFEED);
206                 if (priorityClass != null)
207                         writer.write("PriorityClass=" + priorityClass.getValue() + LINEFEED);
208                 writer.write("GetCHKOnly=" + getCHKOnly + LINEFEED);
209                 writer.write("Global=" + global + LINEFEED);
210                 writer.write("DontCompress=" + dontCompress + LINEFEED);
211                 if (clientToken != null)
212                         writer.write("ClientToken=" + clientToken + LINEFEED);
213                 if (persistence != null)
214                         writer.write("Persistence=" + persistence.getName() + LINEFEED);
215         }
216
217 }