001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.util.xmlreader;
016:
017: import java.nio.charset.UnsupportedCharsetException;
018: import java.nio.charset.Charset;
019:
020: /**
021: * This class encapsulate Advanced Settings.
022: * The example xml is <pre>
023: ....
024: <advanced-settings>
025: <charset>ISO-8859-1<charset>
026: <byte-buffer-size>61440<byte-buffer-size>
027: <use-direct-byte-buffer>true</use-direct-byte-buffer>
028: <backlog>1024</backlog>
029: <socket-linger>-1</socket-linger>
030: <debug-non-blocking-mode>false</debug-non-blocking-mode>
031: </advanced-settings>
032: ....
033: </pre>
034: * @author Akshathkumar Shetty
035: * @since 1.4.5
036: */
037: public class AdvancedSettings implements java.io.Serializable {
038: private String charset = "ISO-8859-1";
039: private int byteBufferSize = 1024 * 64;
040: private int backlog = 0;
041: private boolean useDirectByteBuffer = true;
042: private int socketLinger = -1;
043: private boolean debugNonBlockingMode;
044: private String clientIdentifierClass = "org.quickserver.net.server.impl.OptimisticClientIdentifier";
045: private String qSObjectPoolMakerClass = null;
046: private int maxThreadsForNioWrite = 10;
047:
048: /**
049: * Sets the Charset to be used for String decoding and encoding.
050: * XML Tag: <charset>ISO-8859-1</charset>
051: * @param charset to be used for String decoding and encoding
052: * @see #getCharset
053: */
054: public void setCharset(String charset) {
055: if (charset == null || charset.trim().length() == 0)
056: return;
057: if (Charset.isSupported(charset) == false) {
058: throw new UnsupportedCharsetException(charset);
059: }
060: this .charset = charset;
061: }
062:
063: /**
064: * Returns Charset to be used for String decoding and encoding..
065: * @see #setCharset
066: */
067: public String getCharset() {
068: return charset;
069: }
070:
071: /**
072: * Sets the ByteBuffer size to be used in ByteBuffer pool.
073: * XML Tag: <byte-buffer-size>65536</byte-buffer-size>
074: * @param byteBufferSize size to be used in ByteBuffer pool.
075: * @see #getByteBufferSize
076: */
077: public void setByteBufferSize(int byteBufferSize) {
078: if (byteBufferSize > 0)
079: this .byteBufferSize = byteBufferSize;
080: }
081:
082: /**
083: * Returns ByteBuffer size to be used in ByteBuffer pool.
084: * @see #setByteBufferSize
085: */
086: public int getByteBufferSize() {
087: return byteBufferSize;
088: }
089:
090: /**
091: * Sets the listen backlog length for the QuickServer to listen on.
092: * If not set or set a value equal or less than 0, then the default
093: * value will be assumed.<br/>
094: * XML Tag: <backlog>0</backlog>
095: * @param backlog The listen backlog length.
096: * @see #getBacklog
097: */
098: public void setBacklog(int backlog) {
099: if (backlog >= 0)
100: this .backlog = backlog;
101: }
102:
103: /**
104: * Returns the listen backlog length for the QuickServer.
105: * @see #setBacklog
106: */
107: public int getBacklog() {
108: return backlog;
109: }
110:
111: /**
112: * Sets the UseDirectByteBuffer flag.
113: * If not set, it will use <code>true</code><br/>
114: * XML Tag: <use-direct-byte-buffer>true</use-direct-byte-buffer>
115: * @param flag UseDirectByteBuffer flag.
116: * @see #getUseDirectByteBuffer
117: */
118: public void setUseDirectByteBuffer(boolean flag) {
119: this .useDirectByteBuffer = flag;
120: }
121:
122: /**
123: * Returns UseDirectByteBuffer flag.
124: * @see #setUseDirectByteBuffer
125: */
126: public boolean getUseDirectByteBuffer() {
127: return useDirectByteBuffer;
128: }
129:
130: /**
131: * Enable SO_LINGER with the specified linger time in seconds. If linger time is less than
132: * <code>0</code> SO_LINGER will be disable.
133: * XML Tag: <socket-linger>-1</socket-linger>
134: * @param socketLinger if the linger value is negative SO_LINGER will be disable.
135: * @see #getSocketLinger
136: */
137: public void setSocketLinger(int socketLinger) {
138: this .socketLinger = socketLinger;
139: }
140:
141: /**
142: * Returns linger time in seconds. If SO_LINGER is disabled time will be negative;
143: * @see #setSocketLinger
144: */
145: public int getSocketLinger() {
146: return socketLinger;
147: }
148:
149: /**
150: * Sets the DebugNonBlockingMode flag.
151: * If not set, it will use <code>false</code><br/>
152: * XML Tag: <debug-non-blocking-mode>false</debug-non-blocking-mode>
153: * @param debugNonBlockingMode DebugNonBlockingMode flag.
154: * @see #getDebugNonBlockingMode
155: */
156: public void setDebugNonBlockingMode(boolean debugNonBlockingMode) {
157: this .debugNonBlockingMode = debugNonBlockingMode;
158: }
159:
160: /**
161: * Returns DebugNonBlockingMode flag.
162: * @see #setDebugNonBlockingMode
163: */
164: public boolean getDebugNonBlockingMode() {
165: return debugNonBlockingMode;
166: }
167:
168: /**
169: * Sets the ClientIdentifier class that implements
170: * {@link org.quickserver.net.server.ClientIdentifier}.
171: * XML Tag: <client-identifier>org.quickserver.net.server.impl.TryClientIdentifier</client-identifier>
172: * @param clientIdentifierClass the fully qualified name of the class that
173: * implements {@link org.quickserver.net.server.ClientIdentifier}.
174: * @see #getClientIdentifier
175: */
176: public void setClientIdentifier(String clientIdentifierClass) {
177: if (clientIdentifierClass == null
178: || clientIdentifierClass.trim().length() == 0)
179: return;
180: this .clientIdentifierClass = clientIdentifierClass;
181: }
182:
183: /**
184: * Returns the ClientIdentifier class that that implements
185: * {@link org.quickserver.net.server.ClientIdentifier}.
186: * @see #setClientIdentifier
187: */
188: public String getClientIdentifier() {
189: return clientIdentifierClass;
190: }
191:
192: /**
193: * Sets the QSObjectPoolMaker class that implements
194: * {@link org.quickserver.util.pool.QSObjectPoolMaker}.
195: * XML Tag: <qsobject-pool-maker>org.quickserver.util.pool.MakeQSObjectPool</qsobject-pool-maker>
196: * @param qSObjectPoolMakerClass the fully qualified name of the class that
197: * implements {@link org.quickserver.util.pool.QSObjectPoolMaker}.
198: * @see #getQSObjectPoolMaker
199: */
200: public void setQSObjectPoolMaker(String qSObjectPoolMakerClass) {
201: this .qSObjectPoolMakerClass = qSObjectPoolMakerClass;
202: }
203:
204: /**
205: * Returns the QSObjectPoolMaker class that implements
206: * {@link org.quickserver.util.pool.QSObjectPoolMaker}.
207: * @see #setQSObjectPoolMaker
208: */
209: public String getQSObjectPoolMaker() {
210: if (qSObjectPoolMakerClass == null)
211: qSObjectPoolMakerClass = "org.quickserver.util.pool.MakeQSObjectPool";
212: return qSObjectPoolMakerClass;
213: }
214:
215: /**
216: * Sets the maximum threads allowed for nio write. If set to 0 or less no limit is
217: * imposed.
218: * XML Tag: <max-threads-for-nio-write>10</max-threads-for-nio-write>
219: * @param maxThreadsForNioWrite maximum threads allowed for nio write
220: * @see #getMaxThreadsForNioWrite
221: * @since 1.4.6
222: */
223: public void setMaxThreadsForNioWrite(int maxThreadsForNioWrite) {
224: this .maxThreadsForNioWrite = maxThreadsForNioWrite;
225: }
226:
227: /**
228: * Returns the maximum threads allowed for nio write.
229: * @see #setMaxThreadsForNioWrite
230: * @since 1.4.6
231: */
232: public int getMaxThreadsForNioWrite() {
233: return maxThreadsForNioWrite;
234: }
235:
236: /**
237: * Returns XML config of this class.
238: */
239: public String toXML(String pad) {
240: if (pad == null)
241: pad = "";
242: StringBuffer sb = new StringBuffer();
243: sb.append(pad + "<advanced-settings>\n");
244: sb.append(pad + "\t<charset>").append(getCharset()).append(
245: "</charset>\n");
246: sb.append(pad + "\t<use-direct-byte-buffer>"
247: + getUseDirectByteBuffer()
248: + "</use-direct-byte-buffer>\n");
249: sb.append(pad + "\t<byte-buffer-size>").append(
250: getByteBufferSize()).append("</byte-buffer-size>\n");
251: sb.append(pad + "\t<backlog>" + getBacklog() + "</backlog>\n");
252: sb.append(pad + "\t<socket-linger>" + getSocketLinger()
253: + "</socket-linger>\n");
254: sb.append(pad + "\t<debug-non-blocking-mode>"
255: + getDebugNonBlockingMode()
256: + "</debug-non-blocking-mode>\n");
257: sb.append(pad + "\t<client-identifier>" + getClientIdentifier()
258: + "</client-identifier>\n");
259: sb.append(pad + "\t<qsobject-pool-maker>"
260: + getQSObjectPoolMaker() + "</qsobject-pool-maker>\n");
261: sb.append(pad + "\t<max-threads-for-nio-write>"
262: + getMaxThreadsForNioWrite()
263: + "</max-threads-for-nio-write>\n");
264: sb.append(pad + "</advanced-settings>\n");
265: return sb.toString();
266: }
267:
268: }
|