FileDocCategorySizeDatePackage
AjpProtocol.javaAPI DocApache Tomcat 6.0.1417093Fri Jul 20 04:20:32 BST 2007org.apache.coyote.ajp

AjpProtocol

public class AjpProtocol extends Object implements org.apache.coyote.ProtocolHandler, MBeanRegistration
Abstract the protocol implementation, including threading, etc. Processor is single threaded and specific to stream-based protocols, will not fit Jk protocols like JNI.
author
Remy Maucherat
author
Costin Manolache

Fields Summary
protected static org.apache.juli.logging.Log
log
protected static org.apache.tomcat.util.res.StringManager
sm
The string manager for this package.
protected ObjectName
tpOname
protected ObjectName
rgOname
protected org.apache.tomcat.util.net.JIoEndpoint
endpoint
Associated java.io endpoint.
protected Hashtable
attributes
Configuration attributes.
private org.apache.coyote.Adapter
adapter
Adapter which will process the requests recieved by this endpoint.
private AjpConnectionHandler
cHandler
Connection handler for AJP.
protected int
processorCache
Processor cache.
protected boolean
tomcatAuthentication
Should authentication be done in the native webserver layer, or in the Servlet container ?
protected String
requiredSecret
Required secret.
protected int
packetSize
AJP packet size.
protected int
keepAliveTimeout
The number of seconds Tomcat will wait for a subsequent request before closing the connection.
protected String
domain
protected ObjectName
oname
protected MBeanServer
mserver
Constructors Summary
public AjpProtocol()



    // ------------------------------------------------------------ Constructor


      
        cHandler = new AjpConnectionHandler(this);
        setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
        setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
        //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
        setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
    
Methods Summary
public voiddestroy()

        if (log.isInfoEnabled())
            log.info(sm.getString("ajpprotocol.stop", getName()));
        endpoint.destroy();
        if (tpOname!=null)
            Registry.getRegistry(null, null).unregisterComponent(tpOname);
        if (rgOname != null)
            Registry.getRegistry(null, null).unregisterComponent(rgOname);
    
public org.apache.coyote.AdaptergetAdapter()

        return adapter;
    
public java.net.InetAddressgetAddress()

 return endpoint.getAddress(); 
public java.lang.ObjectgetAttribute(java.lang.String key)

        if (log.isTraceEnabled()) {
            log.trace(sm.getString("ajpprotocol.getattribute", key));
        }
        return attributes.get(key);
    
public java.util.IteratorgetAttributeNames()

        return attributes.keySet().iterator();
    
public intgetBacklog()

 return endpoint.getBacklog(); 
public java.lang.StringgetDomain()

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

 return endpoint.getExecutor(); 
public intgetKeepAliveTimeout()

        return keepAliveTimeout; 
public intgetMaxThreads()

 return endpoint.getMaxThreads(); 
public java.lang.StringgetName()

        String encodedAddr = "";
        if (getAddress() != null) {
            encodedAddr = "" + getAddress();
            if (encodedAddr.startsWith("/"))
                encodedAddr = encodedAddr.substring(1);
            encodedAddr = URLEncoder.encode(encodedAddr) + "-";
        }
        return ("ajp-" + encodedAddr + endpoint.getPort());
    
public javax.management.ObjectNamegetObjectName()

        return oname;
    
public intgetPacketSize()

        return packetSize; 
public intgetPort()

 return endpoint.getPort(); 
public intgetProcessorCache()

        return this.processorCache; 
public java.lang.StringgetProperty(java.lang.String name)
Get a property

        return (String) getAttribute(name);
    
public intgetSoLinger()

 return endpoint.getSoLinger(); 
public intgetSoTimeout()

 return endpoint.getSoTimeout(); 
public booleangetTcpNoDelay()

 return endpoint.getTcpNoDelay(); 
public intgetThreadPriority()

 return endpoint.getThreadPriority(); 
public booleangetTomcatAuthentication()

        return tomcatAuthentication; 
public voidinit()
Start the protocol

        endpoint.setName(getName());
        endpoint.setHandler(cHandler);

        try {
            endpoint.init();
        } catch (Exception ex) {
            log.error(sm.getString("ajpprotocol.endpoint.initerror"), ex);
            throw ex;
        }
        if (log.isInfoEnabled()) {
            log.info(sm.getString("ajpprotocol.init", getName()));
        }
    
public voidpause()

        try {
            endpoint.pause();
        } catch (Exception ex) {
            log.error(sm.getString("ajpprotocol.endpoint.pauseerror"), ex);
            throw ex;
        }
        if (log.isInfoEnabled())
            log.info(sm.getString("ajpprotocol.pause", getName()));
    
public voidpostDeregister()

    
public voidpostRegister(java.lang.Boolean registrationDone)

    
public voidpreDeregister()

    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)

        oname=name;
        mserver=server;
        domain=name.getDomain();
        return name;
    
public voidresume()

        try {
            endpoint.resume();
        } catch (Exception ex) {
            log.error(sm.getString("ajpprotocol.endpoint.resumeerror"), ex);
            throw ex;
        }
        if (log.isInfoEnabled())
            log.info(sm.getString("ajpprotocol.resume", getName()));
    
public voidsetAdapter(org.apache.coyote.Adapter adapter)
The adapter, used to call the connector

        this.adapter = adapter;
    
public voidsetAddress(java.net.InetAddress ia)

 endpoint.setAddress(ia); 
public voidsetAttribute(java.lang.String name, java.lang.Object value)
Pass config info



    // --------------------------------------------------------- Public Methods


             
          
        if (log.isTraceEnabled()) {
            log.trace(sm.getString("ajpprotocol.setattribute", name, value));
        }
        attributes.put(name, value);
    
public voidsetBacklog(int backlog)

 endpoint.setBacklog(backlog); 
public voidsetExecutor(java.util.concurrent.Executor executor)

 endpoint.setExecutor(executor); 
public voidsetKeepAliveTimeout(int timeout)

 keepAliveTimeout = timeout; 
public voidsetMaxThreads(int maxThreads)

 endpoint.setMaxThreads(maxThreads); 
public voidsetPacketSize(int packetSize)

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

 endpoint.setPort(port); 
public voidsetProcessorCache(int processorCache)

 this.processorCache = processorCache; 
public voidsetProperty(java.lang.String name, java.lang.String value)
Set a property.

        setAttribute(name, value);
    
public voidsetRequiredSecret(java.lang.String requiredSecret)

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

 endpoint.setSoLinger(soLinger); 
public voidsetSoTimeout(int soTimeout)

 endpoint.setSoTimeout(soTimeout); 
public voidsetTcpNoDelay(boolean tcpNoDelay)

 endpoint.setTcpNoDelay(tcpNoDelay); 
public voidsetThreadPriority(int threadPriority)

 endpoint.setThreadPriority(threadPriority); 
public voidsetTomcatAuthentication(boolean tomcatAuthentication)

 this.tomcatAuthentication = tomcatAuthentication; 
public voidstart()

        if (this.domain != null ) {
            try {
                tpOname = new ObjectName
                    (domain + ":" + "type=ThreadPool,name=" + getName());
                Registry.getRegistry(null, null)
                    .registerComponent(endpoint, tpOname, null );
            } catch (Exception e) {
                log.error("Can't register threadpool" );
            }
            rgOname = new ObjectName
                (domain + ":type=GlobalRequestProcessor,name=" + getName());
            Registry.getRegistry(null, null).registerComponent
                (cHandler.global, rgOname, null);
        }

        try {
            endpoint.start();
        } catch (Exception ex) {
            log.error(sm.getString("ajpprotocol.endpoint.starterror"), ex);
            throw ex;
        }
        if (log.isInfoEnabled())
            log.info(sm.getString("ajpprotocol.start", getName()));