FileDocCategorySizeDatePackage
BaseEndpoint.javaAPI DocApache Tomcat 6.0.149561Fri Jul 20 04:20:34 BST 2007org.apache.tomcat.util.net

BaseEndpoint

public abstract class BaseEndpoint extends Object
APR tailored thread pool, providing the following services:
  • Socket acceptor thread
  • Socket poller thread
  • Sendfile thread
  • Worker threads pool
When switching to Java 5, there's an opportunity to use the virtual machine's thread pool.
author
Mladen Turk
author
Remy Maucherat

Fields Summary
protected static org.apache.juli.logging.Log
log
protected static org.apache.tomcat.util.res.StringManager
sm
public static final String
CIPHER_SUITE_KEY
The Request attribute key for the cipher suite.
public static final String
KEY_SIZE_KEY
The Request attribute key for the key size.
public static final String
CERTIFICATE_KEY
The Request attribute key for the client certificate chain.
public static final String
SESSION_ID_KEY
The Request attribute key for the session id. This one is a Tomcat extension to the Servlet spec.
protected volatile boolean
running
Running state of the endpoint.
protected volatile boolean
paused
Will be set to true whenever the endpoint is paused.
protected boolean
initialized
Track the initialization state of the endpoint.
protected int
curThreadsBusy
Current worker threads busy count.
protected int
curThreads
Current worker threads count.
protected int
sequence
Sequence number used to generate thread names.
protected Executor
executor
External Executor based thread pool.
protected int
maxThreads
Maximum amount of worker threads.
protected int
threadPriority
Priority of the acceptor and poller threads.
protected int
port
Server socket port.
protected InetAddress
address
Address for the server socket.
protected int
backlog
Allows the server developer to specify the backlog that should be used for server sockets. By default, this value is 100.
protected boolean
tcpNoDelay
Socket TCP no delay.
protected int
soLinger
Socket linger.
protected int
soTimeout
Socket timeout.
protected boolean
daemon
The 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
name
Name of the thread pool, which will be used for naming child threads.
Constructors Summary
Methods Summary
public abstract voiddestroy()
Deallocate APR memory pools, and close server socket.

public java.net.InetAddressgetAddress()

 return address; 
public intgetBacklog()

 return backlog; 
public intgetCurrentThreadCount()
Return the amount of threads that are managed by the pool.

return
the amount of threads that are managed by the pool

        return curThreads;
    
public intgetCurrentThreadsBusy()
Return the amount of threads currently busy.

return
the amount of threads currently busy

        return curThreadsBusy;
    
public booleangetDaemon()

 return daemon; 
public java.util.concurrent.ExecutorgetExecutor()

 return executor; 
public intgetMaxSpareThreads()
Dummy maxSpareThreads property.

 return 0; 
public intgetMaxThreads()

 return maxThreads; 
public intgetMinSpareThreads()
Dummy minSpareThreads property.

 return 0; 
public java.lang.StringgetName()

 return name; 
public intgetPort()

 return port; 
protected intgetSequence()
Get a sequence number used for thread naming.

        return sequence++;
    
public intgetSoLinger()

        return soLinger; 
public intgetSoTimeout()

        return soTimeout; 
public booleangetTcpNoDelay()

        return tcpNoDelay; 
public intgetThreadPriority()

 return threadPriority; 
public abstract voidinit()
Initialize the endpoint.

public booleanisPaused()
Return the state of the endpoint.

return
true if the endpoint is paused, false otherwise

        return paused;
    
public booleanisRunning()
Return the state of the endpoint.

return
true if the endpoint is running, false otherwise

        return running;
    
public voidpause()
Pause the endpoint, which will make it stop accepting new sockets.

        if (running && !paused) {
            paused = true;
            unlockAccept();
        }
    
public voidresume()
Resume the endpoint, which will make it start accepting new sockets again.

        if (running) {
            paused = false;
        }
    
public voidsetAddress(java.net.InetAddress address)

 this.address = address; 
public voidsetBacklog(int backlog)

         if (backlog > 0) this.backlog = backlog; 
public voidsetDaemon(boolean b)

         daemon = b; 
public voidsetExecutor(java.util.concurrent.Executor executor)

         this.executor = executor; 
public voidsetMaxThreads(int maxThreads)

         this.maxThreads = maxThreads; 
public voidsetName(java.lang.String name)

         this.name = name; 
public voidsetPort(int port)

 this.port=port; 
public voidsetSoLinger(int soLinger)

 this.soLinger = soLinger; 
public voidsetSoTimeout(int soTimeout)

 this.soTimeout = soTimeout; 
public voidsetTcpNoDelay(boolean tcpNoDelay)

 this.tcpNoDelay = tcpNoDelay; 
public voidsetThreadPriority(int threadPriority)

         this.threadPriority = threadPriority; 
public abstract voidstart()
Start the APR endpoint, creating acceptor, poller and sendfile threads.

public abstract voidstop()
Stop the endpoint. This will cause all processing threads to stop.

protected voidunlockAccept()
Unlock the server socket accept using a bugus connection.

        java.net.Socket s = null;
        try {
            // Need to create a connection to unlock the accept();
            if (address == null) {
                s = new java.net.Socket("127.0.0.1", port);
            } else {
                s = new java.net.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
                }
            }
        }