FileDocCategorySizeDatePackage
ProcessorBlockingTask.javaAPI DocGlassfish v2 API10141Fri May 04 22:37:08 BST 2007com.sun.enterprise.web.connector.grizzly.blocking

ProcessorBlockingTask

public class ProcessorBlockingTask extends com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask
Process HTTP request. This class is based on org.apache.coyote.http11.Http11Processor. This class must be used when NIO Blocking is enabled.
author
Jean-Francois Arcand

Fields Summary
protected int
maxKeepAliveRequests
Max keep-alive request before timing out.
protected org.apache.tomcat.util.net.SSLImplementation
sslImplementation
The wrapper used to support SSL.
Constructors Summary
public ProcessorBlockingTask()

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

     
        this(true);
    
public ProcessorBlockingTask(boolean init)

    
        
        type = PROCESSOR_TASK;
        if (init) {
            initialize();
        }
    
Methods Summary
public intcountBlockingKeepAlive()
Return the number of blocking keep-alive connection

        if (maxKeepAliveRequests == -1) return -1;
                
        return maxKeepAliveRequests - keepAliveLeft; 
    
protected booleandoProcess(java.io.InputStream input, java.io.OutputStream output)
Process an HTTP request using a blocking socket

param
input the InputStream to read bytes
param
output the OutputStream to write bytes

        boolean keptAlive = false;    
        while (started && !error && keepAlive) {                
            boolean exitWhile = parseRequest(input,output,keptAlive);
            if (exitWhile) break;                     
            invokeAdapter();            
            postResponse();
        }      
        return true;
    
public voiddoTask()
Execute the HTTP request by parsing the header/body, and then by delegating the process to the Catalina container.

        try {
            process(socket.getInputStream(),socket.getOutputStream());
        } catch(Throwable ex){
            ex.printStackTrace();
            SelectorThread.logger().log(Level.FINE,
                    "processorTask.errorProcessingRequest", ex);
        } finally {
            terminateProcess();        
        }
    
public intgetMaxKeepAliveRequests()
Return the number of Keep-Alive requests that we will honor.

        return maxKeepAliveRequests;
    
public org.apache.tomcat.util.net.SSLImplementationgetSSLImplementation()
Return the current SSLImplementation this Thread

        return sslImplementation;
    
public voidinitialize()
Initialize the stream and the buffer used to parse the request.

        started = true;   
        request = new Request();

        response = new Response();
        response.setHook(this);
        
        inputBuffer = new InternalInputBuffer(request,requestBufferSize);
        outputBuffer = new InternalOutputBuffer(response,
                                                maxHttpHeaderSize);
        
        request.setInputBuffer(inputBuffer);
       
        response.setOutputBuffer(outputBuffer);
        request.setResponse(response);

        initializeFilters();

    
public booleanparseRequest(java.io.InputStream input, java.io.OutputStream output, boolean keptAlive)
Parse the request line and the http header.

        boolean exitWhile = super.parseRequest(input,output,keptAlive);  
        
        if (maxKeepAliveRequests > 0 && --keepAliveLeft == 0)
            keepAlive = false;
        return exitWhile;
    
public voidpreProcess(java.io.InputStream input, java.io.OutputStream output)
Pre process the request by decoding the request line and the header.

param
input the InputStream to read bytes
param
output the OutputStream to write bytes

        
        // Make sure this object has been initialized.
        if ( !started ){
            initialize();
        }               
        // Setting up the I/O
        inputBuffer.setInputStream(input);
        outputBuffer.setOutputStream(output);  
        configPreProcess();
    
public booleanprocess(java.io.InputStream input, java.io.OutputStream output)
Process pipelined HTTP requests using the specified input and output streams.

param
input stream from which the HTTP requests will be read
param
output stream which will be used to output the HTTP responses
return
true is an error occured.
throws
Exception error during an I/O operation

        preProcess(input,output);            
        if (sslImplementation != null) {
            sslSupport = sslImplementation.getSSLSupport(socket);
        }        
        doProcess(input,output);
        postProcess(input,output);
        return keepAlive;
    
public voidrecycle()
Recyle this object.

        socket = null;
        dropConnection = false;
    
public voidsetMaxKeepAliveRequests(int maxKeepAliveRequests)
Set the maximum number of Keep-Alive requests to honor. This is to safeguard from DoS attacks. Setting to a negative value disables the check.

        this.maxKeepAliveRequests = maxKeepAliveRequests;
    
public voidsetSSLImplementation(org.apache.tomcat.util.net.SSLImplementation sslImplementation)
Set the SSLImplementation used by this thread.It usually means HTTPS will be used.

        this.sslImplementation = sslImplementation;
    
public voidtaskEvent(com.sun.enterprise.web.connector.grizzly.TaskEvent event)

        if ( event.getStatus() == TaskEvent.START) {
            taskContext = (TaskContext)event.attachement();
            if (  taskEvent == null ) {
                taskEvent = new TaskEvent<TaskContext>();
            }
            
            taskEvent.attach(taskContext);
            execute();
        }
    
public voidterminateProcess()
Notify the TaskListener that the request has been fully processed.

        taskEvent.setStatus(TaskEvent.COMPLETED);
        fireTaskEvent(taskEvent);