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

ReadBlockingTask

public class ReadBlockingTask extends com.sun.enterprise.web.connector.grizzly.DefaultReadTask
Process a blocking socket. By default, SSL is using blocking mode.
author
Jean-Francois Arcand

Fields Summary
protected com.sun.enterprise.web.connector.grizzly.PipelineStatistic
pipelineStat
The PipelineStatistic objects used when gathering statistics.
protected boolean
isSecure
If the Task handling an SSL based request.
private com.sun.enterprise.web.connector.grizzly.handlers.NoParsingHandler
handler
The Handler used to pre-process the request.
Constructors Summary
public ReadBlockingTask()

    
            
     
        type = READ_TASK;
        taskContext = new TaskContext();
        taskEvent = new TaskEvent(taskContext);
        taskEvent.setStatus(TaskEvent.START);
    
Methods Summary
public voidattachProcessor(com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask processorTask)
Force this task to always use the same ProcessorTask instance.

        handler = new NoParsingHandler();
        
        this.processorTask = processorTask;      
        processorTask.setHandler(handler);  
    
public voiddoTask()
Dispatch an Http request to a ProcessorTask

        Socket socket = processorTask.getSocket();
        SelectorBlockingThread blockingSelector = 
                (SelectorBlockingThread)selectorThread;
        blockingSelector.setSocketOptions(socket);

        if (isSecure) {
            try {
                blockingSelector.getServerSocketFactory().handshake(socket);
            } catch (Throwable ex) {
                selectorThread.getLogger().log(Level.FINE,
                           "selectorThread.sslHandshakeException", ex);
                try {
                    socket.close();
                } catch (IOException ioe){
                    // Do nothing
                }
                taskEvent.setStatus(TaskEvent.COMPLETED);
                taskEvent(taskEvent);
                return;
            }
        }
        processorTask.addTaskListener(this);
        addTaskListener((ProcessorBlockingTask)processorTask);       
        handler.attachChannel(socket.getChannel());

        // Notify the ProcessorTask that we are ready to process the request.
        fireTaskEvent(taskEvent);
    
protected voidfinishConnection()
Gracefully close the blocking socket.

        Socket socket = processorTask.getSocket();

        if ( !isSecure ) {
            try{
                if (!socket.isInputShutdown()){
                    socket.shutdownInput();
                }
            } catch (IOException ioe){
                ;
            }
            try{
                if (!socket.isOutputShutdown()){
                    socket.shutdownOutput();
                }
            } catch (IOException ex){
                ;
            }
        }

        try{
            socket.close();   
        } catch (IOException ex){
            ;
        } finally {
            if (isMonitoringEnabled()) {
                getRequestGroupInfo().decreaseCountOpenConnections();
            }
        }
    
public com.sun.enterprise.web.connector.grizzly.PipelineStatisticgetPipelineStatistic()
Return the PipelineStatistic object used to gather statistic;

        return pipelineStat;
    
public booleangetSecure()
Return the isSecure.

        return isSecure;
    
public java.net.SocketgetSocket()
Return the current Socket used by this instance

return
socket the current Socket used by this instance

        return processorTask.getSocket();
    
public voidrecycle()
Clear the current state and make this object ready for another request.

        clearTaskListeners();
        taskEvent.setStatus(TaskEvent.START);                    
    
public voidsetPipelineStatistic(com.sun.enterprise.web.connector.grizzly.PipelineStatistic pipelineStatistic)
Set the PipelineStatistic object used to gather statistic;

        this.pipelineStat = pipelineStatistic;
    
public voidsetSecure(boolean isSecure)
Set the isSecure attribute.

        this.isSecure = isSecure;
    
public voidtaskEvent(com.sun.enterprise.web.connector.grizzly.TaskEvent event)
Receive notification from other Task and recycle this task.

        if ( event.getStatus() == TaskEvent.COMPLETED){
            finishConnection();

            // We must recycle only if we are sure ProcessorTask has completed its
            // processing. If not, 
            if (recycle) {
                processorTask.recycle();
                recycle();
                selectorThread.returnTask(this);
            }
        }