Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.server;
 
 
 
 
 /* ------------------------------------------------------------ */
Asychronous Server HTTP connection
 
 public class AsyncHttpConnection extends AbstractHttpConnection implements AsyncConnection
 {
     private final static int NO_PROGRESS_INFO = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_INFO",100);
     private final static int NO_PROGRESS_CLOSE = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_CLOSE",200);
 
     private static final Logger LOG = Log.getLogger(AsyncHttpConnection.class);
     private int _total_no_progress;
     private final AsyncEndPoint _asyncEndp;
     private boolean _readInterested = true;
 
     public AsyncHttpConnection(Connector connectorEndPoint endpointServer server)
     {
         super(connector,endpoint,server);
         =(AsyncEndPoint)endpoint;
     }
 
     @Override
     public Connection handle() throws IOException
     {
         Connection connection = this;
         boolean some_progress=false;
         boolean progress=true;
 
         try
         {
             setCurrentConnection(this);
 
             // don't check for idle while dispatched (unless blocking IO is done).
             .setCheckForIdle(false);
 
 
             // While progress and the connection has not changed
             while (progress && connection==this)
             {
                 progress=false;
                 try
                 {
                     // Handle resumed request
                     if (..isAsync())
                     {
                        if (..isDispatchable())
                            handleRequest();
                     }
                     // else Parse more input
                     else if (!.isComplete() && .parseAvailable())
                         progress=true;
 
                     // Generate more output
                     if (.isCommitted() && !.isComplete() && !.isOutputShutdown() && !.getAsyncContinuation().isAsyncStarted())
                         if (.flushBuffer()>0)
                             progress=true;
 
                     // Flush output
                     .flush();
 
                     // Has any IO been done by the endpoint itself since last loop
                     if (.hasProgressed())
                         progress=true;
                 }
                 catch (HttpException e)
                 {
                     if (.isDebugEnabled())
                    {
                        .debug("uri="+);
                        .debug("fields="+);
                        .debug(e);
                    }
                    progress=true;
                    .sendError(e.getStatus(), e.getReason(), nulltrue);
                }
                finally
                {
                    some_progress|=progress;
                    //  Is this request/response round complete and are fully flushed?
                    boolean parserComplete = .isComplete();
                    boolean generatorComplete = .isComplete();
                    boolean complete = parserComplete && generatorComplete;
                    if (parserComplete)
                    {
                        if (generatorComplete)
                        {
                            // Reset the parser/generator
                            progress=true;
                            // look for a switched connection instance?
                            if (.getStatus()==.)
                            {
                                Connection switched=(Connection).getAttribute("org.eclipse.jetty.io.Connection");
                                if (switched!=null)
                                    connection=switched;
                            }
                            reset();
                            // TODO Is this still required?
                            if (!.isPersistent() && !.isOutputShutdown())
                            {
                                .warn("Safety net oshut!!!  IF YOU SEE THIS, PLEASE RAISE BUGZILLA");
                                .shutdownOutput();
                            }
                        }
                        else
                        {
                            // We have finished parsing, but not generating so
                            // we must not be interested in reading until we
                            // have finished generating and we reset the generator
                             = false;
                            .debug("Disabled read interest while writing response {}");
                        }
                    }
                    if (!complete && .getAsyncContinuation().isAsyncStarted())
                    {
                        // The request is suspended, so even though progress has been made,
                        // exit the while loop by setting progress to false
                        .debug("suspended {}",this);
                        progress=false;
                    }
                }
            }
        }
        finally
        {
            setCurrentConnection(null);
            // If we are not suspended
            if (!.getAsyncContinuation().isAsyncStarted())
            {
                // return buffers
                .returnBuffers();
                .returnBuffers();
                // reenable idle checking unless request is suspended
                .setCheckForIdle(true);
            }
            // Safety net to catch spinning
            if (some_progress)
                =0;
            else
            {
                ++;
                if (>0 && %==0 && (<=0 || ))
                    .info("EndPoint making no progress: "++" "++" "+this);
                if (>0 && ==)
                {
                    .warn("Closing EndPoint making no progress: "++" "++" "+this);
                    if ( instanceof SelectChannelEndPoint)
                        ((SelectChannelEndPoint)).getChannel().close();
                }
            }
        }
        return connection;
    }
    public void onInputShutdown() throws IOException
    {
        // If we don't have a committed response and we are not suspended
        {
            // then no more can happen, so close.
            .close();
        }
        // Make idle parser seek EOF
        if (.isIdle())
            .setPersistent(false);
    }
    @Override
    public void reset()
    {
         = true;
        .debug("Enabled read interest {}");
        super.reset();
    }
    @Override
    public boolean isSuspended()
    {
        return ! || super.isSuspended();
    }
New to GrepCode? Check out our FAQ X