/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.tomcat.util.net;
/** * Properties that can be set in the <Connector> element * in server.xml. All properties are prefixed with "socket." * and are currently only working for the Nio connector
*/ publicclass SocketProperties {
/** * Enable/disable socket processor cache, this bounded cache stores * SocketProcessor objects to reduce GC * Default is 0 * -1 is unlimited * 0 is disabled
*/ protectedint processorCache = 0;
/** * Enable/disable poller event cache, this bounded cache stores * PollerEvent objects to reduce GC for the poller * Default is 0 * -1 is unlimited * 0 is disabled * >0 the max number of objects to keep in cache.
*/ protectedint eventCache = 0;
/** * Enable/disable direct buffers for the network buffers * Default value is disabled
*/ protectedboolean directBuffer = false;
/** * Enable/disable direct buffers for the network buffers for SSL * Default value is disabled
*/ protectedboolean directSslBuffer = false;
/** * Socket receive buffer size in bytes (SO_RCVBUF). * JVM default used if not set.
*/ protected Integer rxBufSize = null;
/** * Socket send buffer size in bytes (SO_SNDBUF). * JVM default used if not set.
*/ protected Integer txBufSize = null;
/** * The application read buffer size in bytes. * Default value is 8192
*/ protectedint appReadBufSize = 8192;
/** * The application write buffer size in bytes * Default value is 8192
*/ protectedint appWriteBufSize = 8192;
/** * NioChannel pool size for the endpoint, * this value is how many channels * -1 means unlimited cached, 0 means no cache, * -2 means bufferPoolSize will be used * Default value is -2
*/ protectedint bufferPool = -2;
/** * Buffer pool size in bytes to be cached * -1 means unlimited, 0 means no cache * Default value is based on the max memory reported by the JVM, * if less than 1GB, then 0, else the value divided by 32. This value * will then be used to compute bufferPool if its value is -2
*/ protectedint bufferPoolSize = -2;
/** * TCP_NO_DELAY option. JVM default used if not set.
*/ protectedBoolean tcpNoDelay = Boolean.TRUE;
/** * SO_KEEPALIVE option. JVM default used if not set.
*/ protectedBoolean soKeepAlive = null;
/** * OOBINLINE option. JVM default used if not set.
*/ protectedBoolean ooBInline = null;
/** * SO_REUSEADDR option. JVM default used if not set.
*/ protectedBoolean soReuseAddress = null;
/** * SO_LINGER option, paired with the <code>soLingerTime</code> value. * JVM defaults used unless both attributes are set.
*/ protectedBoolean soLingerOn = null;
/** * SO_LINGER option, paired with the <code>soLingerOn</code> value. * JVM defaults used unless both attributes are set.
*/ protected Integer soLingerTime = null;
/** * The minimum frequency of the timeout interval to avoid excess load from * the poller during high traffic
*/ protectedlong timeoutInterval = 1000;
/** * Timeout in milliseconds for an unlock to take place.
*/ protectedint unlockTimeout = 250;
private ObjectName oname = null;
publicvoid setProperties(Socket socket) throws SocketException{ if (rxBufSize != null) {
socket.setReceiveBufferSize(rxBufSize.intValue());
} if (txBufSize != null) {
socket.setSendBufferSize(txBufSize.intValue());
} if (ooBInline !=null) {
socket.setOOBInline(ooBInline.booleanValue());
} if (soKeepAlive != null) {
socket.setKeepAlive(soKeepAlive.booleanValue());
} if (performanceConnectionTime != null && performanceLatency != null &&
performanceBandwidth != null) {
socket.setPerformancePreferences(
performanceConnectionTime.intValue(),
performanceLatency.intValue(),
performanceBandwidth.intValue());
} if (soReuseAddress != null) {
socket.setReuseAddress(soReuseAddress.booleanValue());
} if (soLingerOn != null && soLingerTime != null) {
socket.setSoLinger(soLingerOn.booleanValue(),
soLingerTime.intValue());
} if (soTimeout != null && soTimeout.intValue() >= 0) {
socket.setSoTimeout(soTimeout.intValue());
} if (tcpNoDelay != null) { try {
socket.setTcpNoDelay(tcpNoDelay.booleanValue());
} catch (SocketException e) { // Some socket types may not support this option which is set by default
}
}
}
/** * Get the actual buffer pool size to use. * @param bufferOverhead When TLS is enabled, additional network buffers * are needed and will be added to the application buffer size * @return the actual buffer pool size that will be used
*/ publicint getActualBufferPool(int bufferOverhead) { if (bufferPool != -2) { return bufferPool;
} else { if (bufferPoolSize == -1) { return -1;
} elseif (bufferPoolSize == 0) { return 0;
} else { long actualBufferPoolSize = bufferPoolSize; long poolSize = 0; if (actualBufferPoolSize == -2) { long maxMemory = Runtime.getRuntime().maxMemory(); if (maxMemory > Integer.MAX_VALUE) {
actualBufferPoolSize = maxMemory / 32;
} else { return 0;
}
} int bufSize = appReadBufSize + appWriteBufSize + bufferOverhead; if (bufSize == 0) { return 0;
}
poolSize = actualBufferPoolSize / (bufSize); if (poolSize > Integer.MAX_VALUE) { return Integer.MAX_VALUE;
} else { return (int) poolSize;
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.