FileDocCategorySizeDatePackage
GrizzlyHttpProtocol.javaAPI DocGlassfish v2 API32138Mon Jul 09 13:46:46 BST 2007com.sun.enterprise.web.connector.grizzly

GrizzlyHttpProtocol

public class GrizzlyHttpProtocol extends org.apache.coyote.http11.Http11Protocol
Abstract the protocol implementation, including threading, etc. Processor is single threaded and specific to stream-based protocols. This is an adaptation of org.apache.coyote.http11.Http11Processor except here NIO is used.
author
Jean-Francois Arcand

Fields Summary
private int
socketBuffer
private SelectorThread
selectorThread
The SelectorThread used by this object.
private Management
jmxManagement
The JMX management class.
private String
compression
Compression value.
private String
noCompressionUserAgents
private String
restrictedUserAgents
private String
compressableMimeTypes
private int
compressionMinSize
private String
proxiedProtocols
List of proxied protocol supported by the listener.
private static final ConcurrentLinkedQueue
supportedHandlers
The default proxied protocol.
private static final ConcurrentHashMap
supportedProtocols
The default proxied protocol.
private static final String
TLS
private static final String
HTTP
Constructors Summary
public GrizzlyHttpProtocol(boolean secure, boolean blocking, String selectorThreadImpl)

    
    
        supportedProtocols.put(
                HTTP,com.sun.enterprise.web.portunif.
                HttpProtocolFinder.class.getName());
        supportedProtocols.put(
                TLS,com.sun.enterprise.web.portunif.
                TlsProtocolFinder.class.getName());
        supportedProtocols.put(
                "ws/tcp","com.sun.xml.ws.transport.tcp.grizzly.WSTCPProtocolFinder");      
        supportedHandlers.add(com.sun.enterprise.web.portunif.
                HttpProtocolHandler.class.getName());
        supportedHandlers.add("com.sun.xml.ws.transport.tcp.grizzly.WSTCPProtocolHandler");        
    
        super(secure,blocking,selectorThreadImpl);     
    
Methods Summary
private voidaddProtocol(java.lang.String protocol, com.sun.enterprise.web.portunif.PortUnificationPipeline pipeline, java.lang.ClassLoader classLoader)

        String className = supportedProtocols.get(protocol);
        if (className == null) {
            SelectorThread.logger().log(Level.WARNING, 
                       "Invalid proxied protocol value: " + protocol);            
            return;
        }
        
        ProtocolFinder finder = 
                (ProtocolFinder)loadInstance(className,classLoader);
        if (finder != null){
            pipeline.addProtocolFinder(finder);
        }          
    
private voidcheckSocketFactory()
Sanity check and socketFactory setup. IMHO it is better to stop the show on a broken connector, then leave Tomcat running and broken.

exception
TomcatException Unable to resolve classes

        if ( !blocking && !secure) return;
        
        SecureSelector secureSel = (SecureSelector)selectorThread;
        if (secure) {
            // The SSL setup code has been moved into
            // SSLImplementation since SocketFactory doesn't
            // provide a wide enough interface
            sslImplementation =
                SSLImplementation.getInstance(sslImplementationName);
            
            socketFactory = sslImplementation.getServerSocketFactory();
            
            secureSel.setSSLImplementation(sslImplementation);
            secureSel.setEnabledCipherSuites(toStringArray(getCiphers()));
            secureSel.setEnabledProtocols(toStringArray(getProtocols()));
            String clientAuthStr = (String) getAttribute("clientauth");
            if (clientAuthStr != null){
                secureSel.setNeedClientAuth(
                        Boolean.valueOf(clientAuthStr).booleanValue());
            }            
        } else if (socketFactoryName != null) {
            socketFactory = string2SocketFactory(socketFactoryName);
        }
        
        if(socketFactory==null)
            socketFactory=ServerSocketFactory.getDefault();

        secureSel.setServerSocketFactory(socketFactory);
    
private voidconfigureProxiedProtocols()
Configure the domain.xml proxied protocols.

        PortUnificationPipeline pipeline = (PortUnificationPipeline)
            selectorThread.getProcessorPipeline();
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        StringTokenizer st = new StringTokenizer(proxiedProtocols,",");
          
        String className;
        ProtocolFinder finder;
        // By default, we must add an https finder if secure.
        if (secure){
            addProtocol(TLS,pipeline,classLoader);  
        } 

        String protocol;
        while (st.hasMoreTokens()){
            protocol = st.nextToken().toLowerCase();
            if (protocol.equals(TLS) && secure){
                continue;
            } else if (protocol.equals(HTTP)){
                continue;
            }
            addProtocol(protocol,pipeline,classLoader);
        }
                
        // Always add http finder at the end.
        addProtocol(HTTP,pipeline,classLoader);   

        Iterator<String> iterator = supportedHandlers.iterator();
        while(iterator.hasNext()){
            ProtocolHandler handler = 
                    (ProtocolHandler)loadInstance(iterator.next(),classLoader);
            if (handler != null){
                pipeline.addProtocolHandler(handler);
            }
        }               
    
protected voidcreate()
This method is called by the constructor of the Http11Protocol superclass.

         
        if (blocking){
            selectorThread = new SelectorBlockingThread();   
            ((SelectorBlockingThread)selectorThread).setSecure(secure);
        } else if ( !secure ){
            if (selectorThreadImpl != null){
                try{               
                    Class clazz = Class.forName(selectorThreadImpl);
                    selectorThread = (SelectorThread)clazz.newInstance();
                } catch (Throwable t){
                    selectorThread.logger().log(Level.WARNING,
                      "Unable to load SelectorThread: " + selectorThreadImpl,t);
                }
            } 
            
            if ( selectorThread == null ){
                selectorThread = new SelectorThread(); 
            }            
        } else { 
            selectorThread = new SSLSelectorThread();
        }
        setSoLinger(-1);
        setSoTimeout(Constants.DEFAULT_TIMEOUT * 1000);
        setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
        setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
    
public voiddestroy()

        SelectorThread.logger().log(Level.INFO, 
                   "grizzlyHttpProtocol.stop", 
                                String.valueOf(getPort()));
        
        if ( domain != null ){
           jmxManagement.
                    unregisterComponent(new ObjectName(domain,"type", "Selector"));
        }
        selectorThread.stopEndpoint();
    
public java.net.InetAddressgetAddress()

        return selectorThread.getAddress();
    
public intgetBacklog()

        return selectorThread.getSsBackLog();
    
public java.lang.StringgetCompressableMimeType()

        return compressableMimeTypes;
    
public java.lang.StringgetCompression()

        return compression;
    
public intgetCompressionMinSize()

        return compressionMinSize;
    
public java.lang.StringgetDefaultResponseType()
Return the default response type used

         return  selectorThread.getDefaultResponseType();
    
public booleangetDisableUploadTimeout()

        return disableUploadTimeout;
    
public booleangetDisplayConfiguration()

        return selectorThread.isDisplayConfiguration();
    
public java.lang.StringgetForcedRequestType()
Return the default request type used

        return  selectorThread.getForcedRequestType();
    
public booleangetLargeFileCacheEnabled()
Is the large file cache support enabled.

        return selectorThread.isLargeFileCacheEnabled;
    
public static java.util.logging.LoggergetLogger()
Return the logger used by the Grizzly classes.

        return SelectorThread.getLogger();
    
public intgetMaxCacheEntries()
Return the maximum entries this cache can contains.

        return selectorThread.maxCacheEntries;
    
public longgetMaxEntrySize()
Get the maximum size a FileCacheEntry can have.

        return selectorThread.maxEntrySize;
    
public longgetMaxLargeCacheSize()
Get the maximum cache size

        return selectorThread.maxLargeFileCacheSize;
    
public intgetMaxProcessorWorkerThreads()
Return the processor-thread used by this Selector

        return selectorThread.getMaxProcessorWorkerThreads();
    
public intgetMaxReadWorkerThreads()
Return the read-thread used by this Selector

        return selectorThread.getMaxReadWorkerThreads();
    
public longgetMaxSmallCacheSize()
Get the maximum cache size

        return selectorThread.maxSmallFileCacheSize;
    
public intgetMaxThreads()

        return selectorThread.getMaxThreads();
    
public longgetMinEntrySize()
Get the maximum size a FileCacheEntry can have.

        return selectorThread.minEntrySize;
    
public intgetMinProcessorQueueLength()
Return the processor-queue-length value on this Selector

        return selectorThread.getMinProcessorQueueLength();
    
public intgetMinReadQueueLength()
Return the reader-queue-length value on this Selector

        return selectorThread.getMinReadQueueLength();
    
public java.lang.StringgetName()

        String encodedAddr = "";
        if (getAddress() != null) {
            encodedAddr = "" + getAddress();
            if (encodedAddr.startsWith("/"))
                encodedAddr = encodedAddr.substring(1);
            encodedAddr = URLEncoder.encode(encodedAddr) + "-";
        }
        return ("http-" + encodedAddr + selectorThread.getPort());
    
public java.lang.StringgetNoCompressionUserAgents()

        return noCompressionUserAgents;
    
public intgetPort()

        return selectorThread.getPort();
    
public intgetProcessorThreadsIncrement()

        return selectorThread.getThreadsIncrement();
    
public intgetProcessorWorkerThreadsTimeout()

        return selectorThread.getThreadsTimeout();
    
public java.lang.StringgetProxiedProtocols()

        return proxiedProtocols;
    
public booleangetRecycleTasks()
Return the recycle-tasks used by this Selector

        return selectorThread.isRecycleTasks();
    
public java.lang.StringgetRestrictedUserAgents()

        return restrictedUserAgents;
    
public booleangetReuseAddress()

        return selectorThread.getReuseAddress();
    
public intgetSelectorTimeout()
Return the Selector times out value.

        return selectorThread.getSelectorTimeout();
    
public intgetServerSoTimeout()

        return selectorThread.getServerSoTimeout();
    
public intgetSoLinger()

        return selectorThread.getSoLinger();
    
public intgetSoTimeout()

        return selectorThread.getSoTimeout();
    
public intgetSocketBuffer()

        return socketBuffer;
    
public booleangetTcpNoDelay()

        return selectorThread.getTcpNoDelay();
    
public intgetTimeout()
Get the upload timeout.

        return selectorThread.getTimeout();
    
public booleangetUseByteBufferView()

        return selectorThread.isUseByteBufferView() ;
    
public booleangetUseDirectByteBuffer()
Return the use-nio-non-blocking used by this Selector

        return selectorThread.isUseDirectByteBuffer();
    
public java.lang.StringgetWebAppRootPath()
Return the folder's root where application are deployed.

        return selectorThread.getRootFolder();
    
public voidinit()
Start the protocol

        try {
            checkSocketFactory();
        } catch( Exception ex ) {
            SelectorThread.logger().log(Level.SEVERE,
                       "grizzlyHttpProtocol.socketfactory.initerror",ex);
            throw ex;
        }

        if( socketFactory!=null ) {
            Enumeration attE=attributes.keys();
            while( attE.hasMoreElements() ) {
                String key=(String)attE.nextElement();
                Object v=attributes.get( key );
                socketFactory.setAttribute( key, v );
            }
        }

        if ( secure && !blocking){
            socketFactory.init();
            ((SSLSelectorThread)selectorThread)
                    .setSSLContext(socketFactory.getSSLContext());
        }
        
        try {
             selectorThread.setAdapter(adapter);
             if (proxiedProtocols != null|| 
                  System.getProperty(
                     PortUnificationPipeline.PROTOCOL_HANDLERS) != null){
                 
                 selectorThread.pipelineClassName = com.sun.enterprise.web.
                         portunif.PortUnificationPipeline.class.getName();
             }
             selectorThread.initEndpoint();
             if (proxiedProtocols != null && !blocking){
                configureProxiedProtocols();
             }
        } catch (Exception ex) {
            SelectorThread.logger().log(Level.SEVERE, 
                       "grizzlyHttpProtocol.endpoint.initerror", ex);
            throw ex;
        }
    
public booleanisFileCacheEnabled()
Is the fileCache enabled.

        return selectorThread.isFileCacheEnabled;
    
private java.lang.ObjectloadInstance(java.lang.String name, java.lang.ClassLoader classLoader)
Util to load classes using reflection.

     
        if (name == null) return null;
        Class className = null;                               
        try{                              
            className = Class.forName(name,true,classLoader);
            return className.newInstance();
        } catch (Throwable t) {
            SelectorThread.logger().log(Level.WARNING, 
                       "Error loading proxied protocol " + name, t);            
        }   
        return null;
    
public SelectorThreadselectorThread()
Return the instance of SelectorThread used by this class.

        return selectorThread;
    
public voidsetAddress(java.net.InetAddress ia)

        selectorThread.setAddress( ia );
        setAttribute("address", "" + ia);
    
public voidsetBacklog(int i)

        ;
    
public voidsetBufferSize(int requestBufferSize)
Set the request input buffer size

        super.setBufferSize(requestBufferSize);
        selectorThread.setBufferSize(requestBufferSize);
    
public voidsetCometSupport(boolean cometSupport)

        selectorThread.enableCometSupport(cometSupport);
    
public voidsetCompressableMimeType(java.lang.String valueS)

        compressableMimeTypes = valueS;
        selectorThread.setCompressableMimeTypes(valueS);
    
public voidsetCompression(java.lang.String valueS)

        compression = valueS;
        selectorThread.setCompression(compression);
    
public voidsetCompressionMinSize(int valueI)

        compressionMinSize = valueI;
        selectorThread.setCompressionMinSize(valueI);
    
public voidsetDefaultResponseType(java.lang.String defaultResponseType)
Set the default response type used. Specified as a semi-colon delimited string consisting of content-type, encoding, language, charset

         selectorThread.setDefaultResponseType(defaultResponseType);
    
public voidsetDisableUploadTimeout(boolean isDisabled)

        disableUploadTimeout = isDisabled;
        selectorThread.setDisableUploadTimeout(disableUploadTimeout);
    
public voidsetDisplayConfiguration(boolean displayConfiguration)

        selectorThread.setDisplayConfiguration(displayConfiguration);
    
public voidsetFileCacheEnabled(boolean isFileCacheEnabled)
Is the file caching mechanism enabled.

        selectorThread.isFileCacheEnabled = isFileCacheEnabled;
    
public voidsetForcedRequestType(java.lang.String forcedResponseType)
Sets the forced request type, which is forced onto requests that do not already specify any MIME type.

        selectorThread.setForcedRequestType(forcedResponseType);
    
public voidsetKeepAliveThreadCount(int threadCount)
Sets the number of keep-alive threads.

param
threadCount Number of keep-alive threads

        selectorThread.setKeepAliveThreadCount(threadCount);
    
public voidsetKeepAliveTimeoutInSeconds(int timeout)
Sets the number of seconds before a keep-alive connection that has been idle times out and is closed.

param
timeout Keep-alive timeout in number of seconds

        selectorThread.setKeepAliveTimeoutInSeconds(timeout);
    
public voidsetLargeFileCacheEnabled(boolean isLargeEnabled)
Is the large file cache support enabled.

        selectorThread.isLargeFileCacheEnabled = isLargeEnabled;
    
public static voidsetLogger(java.util.logging.Logger logger)
Set the logger

        if ( logger != null )
            SelectorThread.setLogger(logger);
    
public voidsetMaxCacheEntries(int mEntries)
Set the maximum entries this cache can contains.

        selectorThread.maxCacheEntries = mEntries;
    
public voidsetMaxEntrySize(long mEntrySize)
Set the maximum size a FileCacheEntry can have.

        selectorThread.maxEntrySize = mEntrySize;
    
public voidsetMaxHttpHeaderSize(int maxHttpHeaderSize)

        super.setMaxHttpHeaderSize(maxHttpHeaderSize);
        selectorThread.setMaxHttpHeaderSize(maxHttpHeaderSize);
    
public voidsetMaxKeepAliveRequests(int mkar)
Set the maximum number of Keep-Alive requests that we will honor.

        selectorThread.setMaxKeepAliveRequests(mkar);
    
public voidsetMaxLargeCacheSize(long mCacheSize)
Set the maximum cache size

        selectorThread.maxLargeFileCacheSize = mCacheSize;
    
public voidsetMaxPostSize(int maxPostSize)

        selectorThread.setMaxPostSize(maxPostSize);
        setAttribute("maxPostSize", maxPostSize);
    
public voidsetMaxProcessorWorkerThreads(int maxProcessorWorkerThreads)
Set the processor-thread from domain.xml

        selectorThread.setMaxProcessorWorkerThreads(maxProcessorWorkerThreads);
    
public voidsetMaxReadWorkerThreads(int maxReadWorkerThreads)
Set the reader-thread from domain.xml.

        selectorThread.setMaxReadWorkerThreads(maxReadWorkerThreads);
    
public voidsetMaxSmallCacheSize(long mCacheSize)
Set the maximum cache size

        selectorThread.maxSmallFileCacheSize = mCacheSize;
    
public voidsetMaxThreads(int maxThreads)

        selectorThread.setMaxThreads(maxThreads);
        setAttribute("maxThreads", "" + maxThreads);
    
public voidsetMinEntrySize(long mSize)
Set the maximum size a FileCacheEntry can have.

        selectorThread.minEntrySize = mSize;
    
public voidsetMinProcessorQueueLength(int minProcessorQueueLength)
Set the processor-queue-length value on this Selector

        selectorThread.setMinProcessorQueueLength(minProcessorQueueLength);
    
public voidsetMinReadQueueLength(int minReadQueueLength)
Set the reader-queue-length value on this Selector

        selectorThread.setMinReadQueueLength(minReadQueueLength);
    
public voidsetMinThreads(int minThreads)
The minimun threads created at startup.

        selectorThread.setMinThreads(minThreads);
    
public voidsetNoCompressionUserAgents(java.lang.String valueS)

        noCompressionUserAgents = valueS;
        selectorThread.setNoCompressionUserAgents(valueS);
    
public voidsetPort(int port)

        selectorThread.setPort(port);
        setAttribute("port", "" + port);
        //this.port=port;
    
public voidsetProcessorThreadsIncrement(int threadsIncrement)

        selectorThread.setThreadsIncrement(threadsIncrement);
        setAttribute("threadsIncrement", "" + threadsIncrement);  
    
public voidsetProcessorWorkerThreadsTimeout(int timeout)

        selectorThread.setThreadsTimeout(timeout);
        setAttribute("threadsTimeout", "" + timeout);     
    
public voidsetProxiedProtocols(java.lang.String proxiedProtocols)

        this.proxiedProtocols = proxiedProtocols;
    
public voidsetQueueSizeInBytes(int maxQueueSizeInBytes)
Set the maximum pending connection this Pipeline can handle.

        selectorThread.setMaxQueueSizeInBytes(maxQueueSizeInBytes);
    
public voidsetRcmSupport(boolean rcmSupport)

        selectorThread.enableRcmSupport(rcmSupport);
    
public voidsetRecycleTasks(boolean recycleTasks)
Set the recycle-tasks by this Selector

        selectorThread.setRecycleTasks(recycleTasks);
    
public voidsetRestrictedUserAgents(java.lang.String valueS)

        restrictedUserAgents = valueS;
        selectorThread.setRestrictedUserAgents(valueS);
    
public voidsetReuseAddress(boolean reuseAddress)

        selectorThread.setReuseAddress(reuseAddress);
    
public voidsetSecondsMaxAge(int sMaxAges)
The timeout in seconds before remove a FileCacheEntry from the fileCache

        selectorThread.secondsMaxAge = sMaxAges;
    
public voidsetSecure(boolean b)

        super.setSecure(b);
    
public voidsetSelectorReadThreadsCount(int selectorReadThreadsCount)
Set the number of SelectorThread Grizzly will uses.

        selectorThread.setSelectorReadThreadsCount(selectorReadThreadsCount);
    
public voidsetSelectorTimeout(int selectorTimeout)
Set the Selector times out value.

        selectorThread.setSelectorTimeout(selectorTimeout);
    
public voidsetServerSoTimeout(int i)

        selectorThread.setServerSoTimeout(i);
        setAttribute("serverSoTimeout", "" + i);
    
public voidsetSoLinger(int i)

        selectorThread.setSoLinger( i );
        setAttribute("soLinger", "" + i);
    
public voidsetSoTimeout(int i)

        selectorThread.setSoTimeout(i);
        setAttribute("soTimeout", "" + i);
    
public voidsetSocketBuffer(int valueI)

        socketBuffer = valueI;
    
public voidsetSocketServerBacklog(int ssBackLog)
Set the SocketServer backlog.

        selectorThread.setSsBackLog(ssBackLog);
    
public voidsetTcpNoDelay(boolean b)

        selectorThread.setTcpNoDelay( b );
        setAttribute("tcpNoDelay", "" + b);
    
public voidsetTimeout(int timeout)
Set the upload timeout.

        selectorThread.setUploadTimeout(timeout);
    
public voidsetUseByteBufferView(boolean useByteBufferView)

        selectorThread.setUseByteBufferView(useByteBufferView);
    
public voidsetUseDirectByteBuffer(boolean useDirectByteBuffer)
Set the use-nio-non-blocking by this Selector

        selectorThread.setUseDirectByteBuffer(useDirectByteBuffer);
    
public voidsetWebAppRootPath(java.lang.String rootFolder)
Set the documenr root folder

        selectorThread.setRootFolder(rootFolder);
    
public voidstart()

        try {            
            if ( this.oname != null ) {
                jmxManagement = new ModelerManagement();
                selectorThread.setManagement(jmxManagement);
                
                try {
                    ObjectName sname = new ObjectName(domain
                                   +  ":type=Selector,name=http"
                                   + selectorThread.getPort());                   
                    jmxManagement.registerComponent(selectorThread, sname, null);
                } catch (Exception ex) {
                    SelectorThread.logger().log(Level.SEVERE,
                      "grizzlyHttpProtocol.selectorRegistrationFailed", ex);
                }
            } else {
                SelectorThread.logger().log(Level.INFO,
                           "grizzlyHttpProtocol.selectorRegisterProtocol");
            }

            selectorThread.start();
        } catch (Exception ex) {
            SelectorThread.logger().log(Level.SEVERE, 
                       "grizzlyHttpProtocol.endpoint.starterror", 
                       ex);
            throw ex;
        }
        
        SelectorThread.logger().log(Level.INFO, 
                   "grizzlyHttpProtocol.start", String.valueOf(getPort()));
    
private static final java.lang.String[]toStringArray(java.lang.String list)

        
        if ( list == null ) return null;
        
        StringTokenizer st = new StringTokenizer(list,",");
        String[] array = new String[st.countTokens()];
        int i = 0;
        while(st.hasMoreTokens()){
            array[i++] = st.nextToken();
        }
        return array;