001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.tomcat.util.net;
018:
019: import java.net.Socket;
020: import java.net.SocketException;
021:
022: /**
023: * Properties that can be set in the <Connector> element
024: * in server.xml. All properties are prefixed with "socket."
025: * and are currently only working for the Nio connector
026: *
027: * @author Filip Hanik
028: */
029: public class SocketProperties {
030: /**
031: * Enable/disable key cache, this bounded cache stores
032: * KeyAttachment objects to reduce GC
033: * Default is 500
034: * -1 is unlimited
035: * 0 is disabled
036: */
037: protected int keyCache = 500;
038:
039: /**
040: * Enable/disable socket processor cache, this bounded cache stores
041: * SocketProcessor objects to reduce GC
042: * Default is 500
043: * -1 is unlimited
044: * 0 is disabled
045: */
046: protected int processorCache = 500;
047:
048: /**
049: * Enable/disable poller event cache, this bounded cache stores
050: * PollerEvent objects to reduce GC for the poller
051: * Default is 500
052: * -1 is unlimited
053: * 0 is disabled
054: * >0 the max number of objects to keep in cache.
055: */
056: protected int eventCache = 500;
057:
058: /**
059: * Enable/disable direct buffers for the network buffers
060: * Default value is enabled
061: */
062: protected boolean directBuffer = false;
063: /**
064: * Socket receive buffer size in bytes (SO_RCVBUF)
065: * Default value is 25188
066: */
067: protected int rxBufSize = 25188;
068: /**
069: * Socket send buffer size in bytes (SO_SNDBUF)
070: * Default value is 43800
071: */
072: protected int txBufSize = 43800;
073:
074: /**
075: * The application read buffer size in bytes.
076: * Default value is rxBufSize
077: */
078: protected int appReadBufSize = 8192;
079:
080: /**
081: * The application write buffer size in bytes
082: * Default value is txBufSize
083: */
084: protected int appWriteBufSize = 8192;
085:
086: /**
087: * NioChannel pool size for the endpoint,
088: * this value is how many channels
089: * -1 means unlimited cached, 0 means no cache
090: * Default value is 500
091: */
092: protected int bufferPool = 500;
093:
094: /**
095: * Buffer pool size in bytes to be cached
096: * -1 means unlimited, 0 means no cache
097: * Default value is 100MB (1024*1024*100 bytes)
098: */
099: protected int bufferPoolSize = 1024 * 1024 * 100;
100:
101: /**
102: * TCP_NO_DELAY option, default is true
103: */
104: protected boolean tcpNoDelay = true;
105: /**
106: * SO_KEEPALIVE option, default is false
107: */
108: protected boolean soKeepAlive = false;
109: /**
110: * OOBINLINE option, default is true
111: */
112: protected boolean ooBInline = true;
113: /**
114: * SO_REUSEADDR option, default is true
115: */
116: protected boolean soReuseAddress = true;
117: /**
118: * SO_LINGER option, default is true, paired with the <code>soLingerTime</code> value
119: */
120: protected boolean soLingerOn = true;
121: /**
122: * SO_LINGER option, default is 25 seconds.
123: */
124: protected int soLingerTime = 25;
125: /**
126: * SO_TIMEOUT option, default is 5000 milliseconds
127: */
128: protected int soTimeout = 5000;
129: /**
130: * Traffic class option, value between 0 and 255
131: * IPTOS_LOWCOST (0x02)
132: * IPTOS_RELIABILITY (0x04)
133: * IPTOS_THROUGHPUT (0x08)
134: * IPTOS_LOWDELAY (0x10)
135: * Default value is 0x04 | 0x08 | 0x010
136: */
137: protected int soTrafficClass = 0x04 | 0x08 | 0x010;
138: /**
139: * Performance preferences according to
140: * http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)
141: * Default value is 1
142: */
143: protected int performanceConnectionTime = 1;
144: /**
145: * Performance preferences according to
146: * http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)
147: * Default value is 0
148: */
149: protected int performanceLatency = 0;
150: /**
151: * Performance preferences according to
152: * http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)
153: * Default value is 1
154: */
155: protected int performanceBandwidth = 1;
156: private Socket properties;
157:
158: public void setProperties(Socket socket) throws SocketException {
159: socket.setReceiveBufferSize(rxBufSize);
160: socket.setSendBufferSize(txBufSize);
161: socket.setOOBInline(ooBInline);
162: socket.setKeepAlive(soKeepAlive);
163: socket.setPerformancePreferences(performanceConnectionTime,
164: performanceLatency, performanceBandwidth);
165: socket.setReuseAddress(soReuseAddress);
166: socket.setSoLinger(soLingerOn, soLingerTime);
167: socket.setSoTimeout(soTimeout);
168: socket.setTcpNoDelay(tcpNoDelay);
169: socket.setTrafficClass(soTrafficClass);
170: }
171:
172: public boolean getDirectBuffer() {
173: return directBuffer;
174: }
175:
176: public boolean getOoBInline() {
177: return ooBInline;
178: }
179:
180: public int getPerformanceBandwidth() {
181: return performanceBandwidth;
182: }
183:
184: public int getPerformanceConnectionTime() {
185: return performanceConnectionTime;
186: }
187:
188: public int getPerformanceLatency() {
189: return performanceLatency;
190: }
191:
192: public int getRxBufSize() {
193: return rxBufSize;
194: }
195:
196: public boolean getSoKeepAlive() {
197: return soKeepAlive;
198: }
199:
200: public boolean getSoLingerOn() {
201: return soLingerOn;
202: }
203:
204: public int getSoLingerTime() {
205: return soLingerTime;
206: }
207:
208: public boolean getSoReuseAddress() {
209: return soReuseAddress;
210: }
211:
212: public int getSoTimeout() {
213: return soTimeout;
214: }
215:
216: public int getSoTrafficClass() {
217: return soTrafficClass;
218: }
219:
220: public boolean getTcpNoDelay() {
221: return tcpNoDelay;
222: }
223:
224: public int getTxBufSize() {
225: return txBufSize;
226: }
227:
228: public int getBufferPool() {
229: return bufferPool;
230: }
231:
232: public int getBufferPoolSize() {
233: return bufferPoolSize;
234: }
235:
236: public int getEventCache() {
237: return eventCache;
238: }
239:
240: public int getKeyCache() {
241: return keyCache;
242: }
243:
244: public Socket getProperties() {
245: return properties;
246: }
247:
248: public int getAppReadBufSize() {
249: return appReadBufSize;
250: }
251:
252: public int getAppWriteBufSize() {
253: return appWriteBufSize;
254: }
255:
256: public int getProcessorCache() {
257: return processorCache;
258: }
259:
260: public int getDirectBufferPool() {
261: return bufferPool;
262: }
263:
264: public void setPerformanceConnectionTime(
265: int performanceConnectionTime) {
266: this .performanceConnectionTime = performanceConnectionTime;
267: }
268:
269: public void setTxBufSize(int txBufSize) {
270: this .txBufSize = txBufSize;
271: }
272:
273: public void setTcpNoDelay(boolean tcpNoDelay) {
274: this .tcpNoDelay = tcpNoDelay;
275: }
276:
277: public void setSoTrafficClass(int soTrafficClass) {
278: this .soTrafficClass = soTrafficClass;
279: }
280:
281: public void setSoTimeout(int soTimeout) {
282: this .soTimeout = soTimeout;
283: }
284:
285: public void setSoReuseAddress(boolean soReuseAddress) {
286: this .soReuseAddress = soReuseAddress;
287: }
288:
289: public void setSoLingerTime(int soLingerTime) {
290: this .soLingerTime = soLingerTime;
291: }
292:
293: public void setSoKeepAlive(boolean soKeepAlive) {
294: this .soKeepAlive = soKeepAlive;
295: }
296:
297: public void setRxBufSize(int rxBufSize) {
298: this .rxBufSize = rxBufSize;
299: }
300:
301: public void setPerformanceLatency(int performanceLatency) {
302: this .performanceLatency = performanceLatency;
303: }
304:
305: public void setPerformanceBandwidth(int performanceBandwidth) {
306: this .performanceBandwidth = performanceBandwidth;
307: }
308:
309: public void setOoBInline(boolean ooBInline) {
310: this .ooBInline = ooBInline;
311: }
312:
313: public void setDirectBuffer(boolean directBuffer) {
314: this .directBuffer = directBuffer;
315: }
316:
317: public void setSoLingerOn(boolean soLingerOn) {
318: this .soLingerOn = soLingerOn;
319: }
320:
321: public void setBufferPool(int bufferPool) {
322: this .bufferPool = bufferPool;
323: }
324:
325: public void setBufferPoolSize(int bufferPoolSize) {
326: this .bufferPoolSize = bufferPoolSize;
327: }
328:
329: public void setEventCache(int eventCache) {
330: this .eventCache = eventCache;
331: }
332:
333: public void setKeyCache(int keyCache) {
334: this .keyCache = keyCache;
335: }
336:
337: public void setAppReadBufSize(int appReadBufSize) {
338: this .appReadBufSize = appReadBufSize;
339: }
340:
341: public void setAppWriteBufSize(int appWriteBufSize) {
342: this .appWriteBufSize = appWriteBufSize;
343: }
344:
345: public void setProcessorCache(int processorCache) {
346: this .processorCache = processorCache;
347: }
348:
349: public void setDirectBufferPool(int directBufferPool) {
350: this.bufferPool = directBufferPool;
351: }
352:
353: }
|