Fields Summary |
---|
protected static org.apache.juli.logging.Log | log |
protected org.apache.tomcat.util.res.StringManager | sm |
public static final String | CIPHER_SUITE_KEYThe Request attribute key for the cipher suite. |
public static final String | KEY_SIZE_KEYThe Request attribute key for the key size. |
public static final String | CERTIFICATE_KEYThe Request attribute key for the client certificate chain. |
public static final String | SESSION_ID_KEYThe Request attribute key for the session id.
This one is a Tomcat extension to the Servlet spec. |
protected WorkerStack | workersAvailable workers. |
protected volatile boolean | runningRunning state of the endpoint. |
protected volatile boolean | pausedWill be set to true whenever the endpoint is paused. |
protected boolean | initializedTrack the initialization state of the endpoint. |
protected int | curThreadsBusyCurrent worker threads busy count. |
protected int | curThreadsCurrent worker threads count. |
protected int | sequenceSequence number used to generate thread names. |
protected ServerSocket | serverSocketAssociated server socket. |
protected int | acceptorThreadCountAcceptor thread count. |
protected Executor | executorExternal Executor based thread pool. |
protected int | maxThreadsMaximum amount of worker threads. |
protected int | threadPriorityPriority of the acceptor and poller threads. |
protected int | portServer socket port. |
protected InetAddress | addressAddress for the server socket. |
protected Handler | handlerHandling of accepted sockets. |
protected int | backlogAllows the server developer to specify the backlog that
should be used for server sockets. By default, this value
is 100. |
protected boolean | tcpNoDelaySocket TCP no delay. |
protected int | soLingerSocket linger. |
protected int | soTimeoutSocket timeout. |
protected boolean | daemonThe default is true - the created threads will be
in daemon mode. If set to false, the control thread
will not be daemon - and will keep the process alive. |
protected String | nameName of the thread pool, which will be used for naming child threads. |
protected ServerSocketFactory | serverSocketFactoryServer socket factory. |
Methods Summary |
---|
protected org.apache.tomcat.util.net.JIoEndpoint$Worker | createWorkerThread()Create (or allocate) and return an available processor for use in
processing a specific HTTP request, if possible. If the maximum
allowed processors have already been created and are in use, return
null instead.
synchronized (workers) {
if (workers.size() > 0) {
curThreadsBusy++;
return workers.pop();
}
if ((maxThreads > 0) && (curThreads < maxThreads)) {
curThreadsBusy++;
return (newWorkerThread());
} else {
if (maxThreads < 0) {
curThreadsBusy++;
return (newWorkerThread());
} else {
return (null);
}
}
}
|
public void | destroy()Deallocate APR memory pools, and close server socket.
if (running) {
stop();
}
if (serverSocket != null) {
try {
if (serverSocket != null)
serverSocket.close();
} catch (Exception e) {
log.error(sm.getString("endpoint.err.close"), e);
}
serverSocket = null;
}
initialized = false ;
|
public int | getAcceptorThreadCount() return acceptorThreadCount;
|
public java.net.InetAddress | getAddress() return address;
|
public int | getBacklog() return backlog;
|
public int | getCurrentThreadCount()
return curThreads;
|
public int | getCurrentThreadsBusy()
return workers!=null?curThreads - workers.size():0;
|
public boolean | getDaemon() return daemon;
|
public java.util.concurrent.Executor | getExecutor() return executor;
|
public org.apache.tomcat.util.net.JIoEndpoint$Handler | getHandler() return handler;
|
public int | getMaxThreads() return maxThreads;
|
public java.lang.String | getName() return name;
|
public int | getPort() return port;
|
public ServerSocketFactory | getServerSocketFactory() return serverSocketFactory;
|
public int | getSoLinger()
return soLinger;
|
public int | getSoTimeout()
return soTimeout;
|
public boolean | getTcpNoDelay()
return tcpNoDelay;
|
public int | getThreadPriority() return threadPriority;
|
protected org.apache.tomcat.util.net.JIoEndpoint$Worker | getWorkerThread()Return a new worker thread, and block while to worker is available.
// Allocate a new worker thread
Worker workerThread = createWorkerThread();
while (workerThread == null) {
try {
synchronized (workers) {
workers.wait();
}
} catch (InterruptedException e) {
// Ignore
}
workerThread = createWorkerThread();
}
return workerThread;
|
public void | init()
if (initialized)
return;
// Initialize thread count defaults for acceptor
if (acceptorThreadCount == 0) {
acceptorThreadCount = 1;
}
if (serverSocketFactory == null) {
serverSocketFactory = ServerSocketFactory.getDefault();
}
if (serverSocket == null) {
try {
if (address == null) {
serverSocket = serverSocketFactory.createSocket(port, backlog);
} else {
serverSocket = serverSocketFactory.createSocket(port, backlog, address);
}
} catch (BindException be) {
throw new BindException(be.getMessage() + ":" + port);
}
}
//if( serverTimeout >= 0 )
// serverSocket.setSoTimeout( serverTimeout );
initialized = true;
|
public boolean | isPaused()
return paused;
|
public boolean | isRunning()
return running;
|
protected org.apache.tomcat.util.net.JIoEndpoint$Worker | newWorkerThread()Create and return a new processor suitable for processing HTTP
requests and returning the corresponding responses.
Worker workerThread = new Worker();
workerThread.start();
return (workerThread);
|
public void | pause()
if (running && !paused) {
paused = true;
unlockAccept();
}
|
protected boolean | processSocket(java.net.Socket socket)Process given socket.
try {
if (executor == null) {
getWorkerThread().assign(socket);
} else {
executor.execute(new SocketProcessor(socket));
}
} catch (Throwable t) {
// This means we got an OOM or similar creating a thread, or that
// the pool and its queue are full
log.error(sm.getString("endpoint.process.fail"), t);
return false;
}
return true;
|
protected void | recycleWorkerThread(org.apache.tomcat.util.net.JIoEndpoint$Worker workerThread)Recycle the specified Processor so that it can be used again.
synchronized (workers) {
workers.push(workerThread);
curThreadsBusy--;
workers.notify();
}
|
public void | resume()
if (running) {
paused = false;
}
|
public void | setAcceptorThreadCount(int acceptorThreadCount)
this.acceptorThreadCount = acceptorThreadCount;
|
public void | setAddress(java.net.InetAddress address) this.address = address;
|
public void | setBacklog(int backlog)
if (backlog > 0) this.backlog = backlog;
|
public void | setDaemon(boolean b)
daemon = b;
|
public void | setExecutor(java.util.concurrent.Executor executor)
this.executor = executor;
|
public void | setHandler(org.apache.tomcat.util.net.JIoEndpoint$Handler handler)
this.handler = handler;
|
public void | setMaxThreads(int maxThreads)
this.maxThreads = maxThreads;
|
public void | setName(java.lang.String name)
this.name = name;
|
public void | setPort(int port) this.port=port;
|
public void | setServerSocketFactory(ServerSocketFactory factory)
this.serverSocketFactory = factory;
|
public void | setSoLinger(int soLinger) this.soLinger = soLinger;
|
public void | setSoTimeout(int soTimeout) this.soTimeout = soTimeout;
|
protected boolean | setSocketOptions(java.net.Socket socket)Set the options for the current socket.
// Process the connection
int step = 1;
try {
// 1: Set socket options: timeout, linger, etc
if (soLinger >= 0) {
socket.setSoLinger(true, soLinger);
}
if (tcpNoDelay) {
socket.setTcpNoDelay(tcpNoDelay);
}
if (soTimeout > 0) {
socket.setSoTimeout(soTimeout);
}
// 2: SSL handshake
step = 2;
serverSocketFactory.handshake(socket);
} catch (Throwable t) {
if (log.isDebugEnabled()) {
if (step == 2) {
log.debug(sm.getString("endpoint.err.handshake"), t);
} else {
log.debug(sm.getString("endpoint.err.unexpected"), t);
}
}
// Tell to close the socket
return false;
}
return true;
|
public void | setTcpNoDelay(boolean tcpNoDelay) this.tcpNoDelay = tcpNoDelay;
|
public void | setThreadPriority(int threadPriority)
this.threadPriority = threadPriority;
|
public void | start()
// Initialize socket if not done before
if (!initialized) {
init();
}
if (!running) {
running = true;
paused = false;
// Create worker collection
if (executor == null) {
workers = new WorkerStack(maxThreads);
}
// Start acceptor threads
for (int i = 0; i < acceptorThreadCount; i++) {
Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);
acceptorThread.setPriority(threadPriority);
acceptorThread.setDaemon(daemon);
acceptorThread.start();
}
}
|
public void | stop()
if (running) {
running = false;
unlockAccept();
}
|
protected void | unlockAccept()Unlock the accept by using a local connection.
Socket s = null;
try {
// Need to create a connection to unlock the accept();
if (address == null) {
s = new Socket("127.0.0.1", port);
} else {
s = new Socket(address, port);
// setting soLinger to a small value will help shutdown the
// connection quicker
s.setSoLinger(true, 0);
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("endpoint.debug.unlock", "" + port), e);
}
} finally {
if (s != null) {
try {
s.close();
} catch (Exception e) {
// Ignore
}
}
}
|