KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > util > xmlreader > AdvancedSettings


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.util.xmlreader;
16
17 import java.nio.charset.UnsupportedCharsetException JavaDoc;
18 import java.nio.charset.Charset JavaDoc;
19
20 /**
21  * This class encapsulate Advanced Settings.
22  * The example xml is <pre>
23     ....
24     &lt;advanced-settings&gt;
25         &lt;charset&gt;ISO-8859-1&lt;charset&gt;
26         &lt;byte-buffer-size&gt;61440&lt;byte-buffer-size&gt;
27         &lt;use-direct-byte-buffer&gt;true&lt;/use-direct-byte-buffer&gt;
28         &lt;backlog&gt;1024&lt;/backlog&gt;
29         &lt;socket-linger&gt;-1&lt;/socket-linger&gt;
30         &lt;debug-non-blocking-mode&gt;false&lt;/debug-non-blocking-mode&gt;
31     &lt;/advanced-settings&gt;
32     ....
33  </pre>
34  * @author Akshathkumar Shetty
35  * @since 1.4.5
36  */

37 public class AdvancedSettings implements java.io.Serializable JavaDoc {
38     private String JavaDoc charset = "ISO-8859-1";
39     private int byteBufferSize = 1024*64;
40     private int backlog = 0;
41     private boolean useDirectByteBuffer = true;
42     private int socketLinger = -1;
43     private boolean debugNonBlockingMode;
44     private String JavaDoc clientIdentifierClass =
45         "org.quickserver.net.server.impl.OptimisticClientIdentifier";
46     private String JavaDoc qSObjectPoolMakerClass = null;
47     private int maxThreadsForNioWrite = 10;
48
49     /**
50      * Sets the Charset to be used for String decoding and encoding.
51      * XML Tag: &lt;charset&gt;ISO-8859-1&lt;/charset&gt;
52      * @param charset to be used for String decoding and encoding
53      * @see #getCharset
54      */

55     public void setCharset(String JavaDoc charset) {
56         if(charset==null || charset.trim().length()==0)
57             return;
58         if(Charset.isSupported(charset)==false) {
59             throw new UnsupportedCharsetException JavaDoc(charset);
60         }
61         this.charset = charset;
62     }
63     /**
64      * Returns Charset to be used for String decoding and encoding..
65      * @see #setCharset
66      */

67     public String JavaDoc getCharset() {
68         return charset;
69     }
70
71     /**
72      * Sets the ByteBuffer size to be used in ByteBuffer pool.
73      * XML Tag: &lt;byte-buffer-size&gt;65536&lt;/byte-buffer-size&gt;
74      * @param byteBufferSize size to be used in ByteBuffer pool.
75      * @see #getByteBufferSize
76      */

77     public void setByteBufferSize(int byteBufferSize) {
78         if(byteBufferSize>0)
79             this.byteBufferSize = byteBufferSize;
80     }
81     /**
82      * Returns ByteBuffer size to be used in ByteBuffer pool.
83      * @see #setByteBufferSize
84      */

85     public int getByteBufferSize() {
86         return byteBufferSize;
87     }
88
89     /**
90      * Sets the listen backlog length for the QuickServer to listen on.
91      * If not set or set a value equal or less than 0, then the default
92      * value will be assumed.<br/>
93      * XML Tag: &lt;backlog&gt;0&lt;/backlog&gt;
94      * @param backlog The listen backlog length.
95      * @see #getBacklog
96      */

97     public void setBacklog(int backlog) {
98         if(backlog>=0)
99             this.backlog = backlog;
100     }
101     /**
102      * Returns the listen backlog length for the QuickServer.
103      * @see #setBacklog
104      */

105     public int getBacklog() {
106         return backlog;
107     }
108
109     /**
110      * Sets the UseDirectByteBuffer flag.
111      * If not set, it will use <code>true</code><br/>
112      * XML Tag: &lt;use-direct-byte-buffer&gt;true&lt;/use-direct-byte-buffer&gt;
113      * @param flag UseDirectByteBuffer flag.
114      * @see #getUseDirectByteBuffer
115      */

116     public void setUseDirectByteBuffer(boolean flag) {
117         this.useDirectByteBuffer = flag;
118     }
119     /**
120      * Returns UseDirectByteBuffer flag.
121      * @see #setUseDirectByteBuffer
122      */

123     public boolean getUseDirectByteBuffer() {
124         return useDirectByteBuffer;
125     }
126
127     /**
128      * Enable SO_LINGER with the specified linger time in seconds. If linger time is less than
129      * <code>0</code> SO_LINGER will be disable.
130      * XML Tag: &lt;socket-linger&gt;-1&lt;/socket-linger&gt;
131      * @param socketLinger if the linger value is negative SO_LINGER will be disable.
132      * @see #getSocketLinger
133      */

134     public void setSocketLinger(int socketLinger) {
135         this.socketLinger = socketLinger;
136     }
137     /**
138      * Returns linger time in seconds. If SO_LINGER is disabled time will be negative;
139      * @see #setSocketLinger
140      */

141     public int getSocketLinger() {
142         return socketLinger;
143     }
144     
145     /**
146      * Sets the DebugNonBlockingMode flag.
147      * If not set, it will use <code>false</code><br/>
148      * XML Tag: &lt;debug-non-blocking-mode&gt;false&lt;/debug-non-blocking-mode&gt;
149      * @param debugNonBlockingMode DebugNonBlockingMode flag.
150      * @see #getDebugNonBlockingMode
151      */

152     public void setDebugNonBlockingMode(boolean debugNonBlockingMode) {
153         this.debugNonBlockingMode = debugNonBlockingMode;
154     }
155     /**
156      * Returns DebugNonBlockingMode flag.
157      * @see #setDebugNonBlockingMode
158      */

159     public boolean getDebugNonBlockingMode() {
160         return debugNonBlockingMode;
161     }
162
163     /**
164      * Sets the ClientIdentifier class that implements
165      * {@link org.quickserver.net.server.ClientIdentifier}.
166      * XML Tag: &lt;client-identifier&gt;org.quickserver.net.server.impl.TryClientIdentifier&lt;/client-identifier&gt;
167      * @param clientIdentifierClass the fully qualified name of the class that
168      * implements {@link org.quickserver.net.server.ClientIdentifier}.
169      * @see #getClientIdentifier
170      */

171     public void setClientIdentifier(String JavaDoc clientIdentifierClass) {
172         if(clientIdentifierClass==null || clientIdentifierClass.trim().length()==0)
173             return;
174         this.clientIdentifierClass = clientIdentifierClass;
175     }
176     /**
177      * Returns the ClientIdentifier class that that implements
178      * {@link org.quickserver.net.server.ClientIdentifier}.
179      * @see #setClientIdentifier
180      */

181     public String JavaDoc getClientIdentifier() {
182         return clientIdentifierClass;
183     }
184
185     /**
186      * Sets the QSObjectPoolMaker class that implements
187      * {@link org.quickserver.util.pool.QSObjectPoolMaker}.
188      * XML Tag: &lt;qsobject-pool-maker&gt;org.quickserver.util.pool.MakeQSObjectPool&lt;/qsobject-pool-maker&gt;
189      * @param qSObjectPoolMakerClass the fully qualified name of the class that
190      * implements {@link org.quickserver.util.pool.QSObjectPoolMaker}.
191      * @see #getQSObjectPoolMaker
192      */

193     public void setQSObjectPoolMaker(String JavaDoc qSObjectPoolMakerClass) {
194         this.qSObjectPoolMakerClass = qSObjectPoolMakerClass;
195     }
196     /**
197      * Returns the QSObjectPoolMaker class that implements
198      * {@link org.quickserver.util.pool.QSObjectPoolMaker}.
199      * @see #setQSObjectPoolMaker
200      */

201     public String JavaDoc getQSObjectPoolMaker() {
202         if(qSObjectPoolMakerClass==null)
203             qSObjectPoolMakerClass = "org.quickserver.util.pool.MakeQSObjectPool";
204         return qSObjectPoolMakerClass;
205     }
206
207     /**
208      * Sets the maximum threads allowed for nio write. If set to 0 or less no limit is
209      * imposed.
210      * XML Tag: &lt;max-threads-for-nio-write&gt;10&lt;/max-threads-for-nio-write&gt;
211      * @param maxThreadsForNioWrite maximum threads allowed for nio write
212      * @see #getMaxThreadsForNioWrite
213      * @since 1.4.6
214      */

215     public void setMaxThreadsForNioWrite(int maxThreadsForNioWrite) {
216         this.maxThreadsForNioWrite = maxThreadsForNioWrite;
217     }
218     /**
219      * Returns the maximum threads allowed for nio write.
220      * @see #setMaxThreadsForNioWrite
221      * @since 1.4.6
222      */

223     public int getMaxThreadsForNioWrite() {
224         return maxThreadsForNioWrite;
225     }
226
227     /**
228      * Returns XML config of this class.
229      */

230     public String JavaDoc toXML(String JavaDoc pad) {
231         if(pad==null) pad="";
232         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
233         sb.append(pad+"<advanced-settings>\n");
234         sb.append(pad+"\t<charset>").append(getCharset()).append("</charset>\n");
235         sb.append(pad+"\t<use-direct-byte-buffer>"+getUseDirectByteBuffer()+"</use-direct-byte-buffer>\n");
236         sb.append(pad+"\t<byte-buffer-size>").append(getByteBufferSize()).append("</byte-buffer-size>\n");
237         sb.append(pad+"\t<backlog>"+getBacklog()+"</backlog>\n");
238         sb.append(pad+"\t<socket-linger>"+getSocketLinger()+"</socket-linger>\n");
239         sb.append(pad+"\t<debug-non-blocking-mode>"+getDebugNonBlockingMode()+"</debug-non-blocking-mode>\n");
240         sb.append(pad+"\t<client-identifier>"+getClientIdentifier()+"</client-identifier>\n");
241         sb.append(pad+"\t<qsobject-pool-maker>"+getQSObjectPoolMaker()+"</qsobject-pool-maker>\n");
242         sb.append(pad+"\t<max-threads-for-nio-write>"+getMaxThreadsForNioWrite()+"</max-threads-for-nio-write>\n");
243         sb.append(pad+"</advanced-settings>\n");
244         return sb.toString();
245     }
246
247     
248 }
249
Popular Tags