changeset 939:8db5996c8c89

remove AsyncContinuation
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 10 Oct 2016 00:50:06 -0600
parents a088981f9cd4
children b77d631b9e28
files src/org/eclipse/jetty/server/AbstractHttpConnection.java src/org/eclipse/jetty/server/AsyncContinuation.java src/org/eclipse/jetty/server/Request.java
diffstat 3 files changed, 85 insertions(+), 251 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java	Sun Oct 09 23:48:32 2016 -0600
+++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java	Mon Oct 10 00:50:06 2016 -0600
@@ -390,22 +390,12 @@
 		_earlyEOF = false;
 	}
 
-	/* ------------------------------------------------------------ */
 	protected void handleRequest() throws IOException
 	{
 		boolean error = false;
 
-		String threadName=null;
-		Throwable async_exception=null;
 		try
 		{
-			if (LOG.isDebugEnabled())
-			{
-				threadName=Thread.currentThread().getName();
-				Thread.currentThread().setName(threadName+" - "+_uri);
-			}
-
-
 			// Loop here to handle async request redispatches.
 			// The loop is controlled by the call to async.unhandle in the
 			// finally block below.  If call is from a non-blocking connector,
@@ -414,134 +404,113 @@
 			// the wait for the asynchronous dispatch or timeout actually happens
 			// within the call to unhandle().
 
-			final Server server=_server;
-			_request._async.handling();
-			if(server!=null && server.isRunning())
+			_request.setHandled(false);
+
+			String info=null;
+			try
 			{
-				_request.setHandled(false);
+				_uri.getPort();
+				String path = null;
 
-				String info=null;
 				try
 				{
-					_uri.getPort();
-					String path = null;
+					path = _uri.getDecodedPath();
+				}
+				catch (Exception e)
+				{
+					LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
+					LOG.trace("",e);
+					path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
+				}
 
-					try
-					{
-						path = _uri.getDecodedPath();
-					}
-					catch (Exception e)
-					{
-						LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
-						LOG.trace("",e);
-						path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
-					}
-
-					info=URIUtil.canonicalPath(path);
-					if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT))
+				info = URIUtil.canonicalPath(path);
+				if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT))
+				{
+					if (path==null && _uri.getScheme()!=null && _uri.getHost()!=null)
 					{
-						if (path==null && _uri.getScheme()!=null && _uri.getHost()!=null)
-						{
-							info="/";
-							_request.setRequestURI("");
-						}
-						else
-							throw new HttpException(400);
+						info="/";
+						_request.setRequestURI("");
 					}
-					_request.setPathInfo(info);
-
-					if (_out!=null)
-						_out.reopen();
-
-					_request.setDispatcherType(DispatcherType.REQUEST);
-					_connector.customize(_endp, _request);
-					server.handle(this);
+					else
+						throw new HttpException(400);
 				}
-				catch (EofException e)
-				{
-					async_exception=e;
-					LOG.debug("",e);
-					error=true;
-					_request.setHandled(true);
-					if (!_response.isCommitted())
-						_generator.sendError(500, null, null, true);
-				}
-				catch (RuntimeIOException e)
-				{
-					async_exception=e;
-					LOG.debug("",e);
-					error=true;
-					_request.setHandled(true);
-				}
-				catch (HttpException e)
-				{
-					LOG.debug("",e);
-					error=true;
-					_request.setHandled(true);
-					_response.sendError(e.getStatus(), e.getReason());
-				}
-				catch (Throwable e)
-				{
-					async_exception=e;
-					LOG.warn(String.valueOf(_uri),e);
-					error=true;
-					_request.setHandled(true);
-					_generator.sendError(info==null?400:500, null, null, true);
-					
-				}
-				finally
-				{
-					_request._async.unhandle();
-				}
+				_request.setPathInfo(info);
+
+				if (_out!=null)
+					_out.reopen();
+
+				_request.setDispatcherType(DispatcherType.REQUEST);
+				_connector.customize(_endp, _request);
+				_server.handle(this);
+			}
+			catch (EofException e)
+			{
+				LOG.debug("",e);
+				error=true;
+				_request.setHandled(true);
+				if (!_response.isCommitted())
+					_generator.sendError(500, null, null, true);
+			}
+			catch (RuntimeIOException e)
+			{
+				LOG.debug("",e);
+				error=true;
+				_request.setHandled(true);
+			}
+			catch (HttpException e)
+			{
+				LOG.debug("",e);
+				error=true;
+				_request.setHandled(true);
+				_response.sendError(e.getStatus(), e.getReason());
+			}
+			catch (Throwable e)
+			{
+				LOG.warn(String.valueOf(_uri),e);
+				error=true;
+				_request.setHandled(true);
+				_generator.sendError(info==null?400:500, null, null, true);
+				
 			}
 		}
 		finally
 		{
-			if (threadName!=null)
-				Thread.currentThread().setName(threadName);
-
-			if (_request._async.isUncompleted())
+			if (_expect100Continue)
 			{
-				
-				_request._async.doComplete(async_exception);
+				LOG.debug("100 continues not sent");
+				// We didn't send 100 continues, but the latest interpretation
+				// of the spec (see httpbis) is that the client will either
+				// send the body anyway, or close.  So we no longer need to
+				// do anything special here other than make the connection not persistent
+				_expect100Continue = false;
+				if (!_response.isCommitted())
+					_generator.setPersistent(false);
+			}
 
-				if (_expect100Continue)
+			if(_endp.isOpen())
+			{
+				if (error)
 				{
-					LOG.debug("100 continues not sent");
-					// We didn't send 100 continues, but the latest interpretation
-					// of the spec (see httpbis) is that the client will either
-					// send the body anyway, or close.  So we no longer need to
-					// do anything special here other than make the connection not persistent
-					_expect100Continue = false;
-					if (!_response.isCommitted())
-						_generator.setPersistent(false);
-				}
-
-				if(_endp.isOpen())
-				{
-					if (error)
-					{
-						_endp.shutdownOutput();
-						_generator.setPersistent(false);
-						if (!_generator.isComplete())
-							_response.complete();
-					}
-					else
-					{
-						if (!_response.isCommitted() && !_request.isHandled())
-							_response.sendError(HttpServletResponse.SC_NOT_FOUND);
+					_endp.shutdownOutput();
+					_generator.setPersistent(false);
+					if (!_generator.isComplete())
 						_response.complete();
-						if (_generator.isPersistent())
-							_connector.persist(_endp);
-					}
 				}
 				else
 				{
+					if (!_response.isCommitted() && !_request.isHandled())
+						_response.sendError(HttpServletResponse.SC_NOT_FOUND);
 					_response.complete();
+					if (_generator.isPersistent())
+						_connector.persist(_endp);
 				}
+			}
+			else
+			{
+				_response.complete();
+			}
 
-				_request.setHandled(true);
-			}
+			_request.setHandled(true);
 		}
 	}
 
--- a/src/org/eclipse/jetty/server/AsyncContinuation.java	Sun Oct 09 23:48:32 2016 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-//
-//  ========================================================================
-//  Copyright (c) 1995-2014 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;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public final class AsyncContinuation
-{
-	private static final Logger LOG = LoggerFactory.getLogger(AsyncContinuation.class);
-		
-	// STATES:
-	//               handling()    suspend()     unhandle()    resume()       complete()  doComplete()
-	//                             startAsync()                dispatch()   
-	// IDLE          DISPATCHED      
-	// DISPATCHED                  ASYNCSTARTED  UNCOMPLETED
-	// ASYNCSTARTED                              ASYNCWAIT     REDISPATCHING  COMPLETING
-	// REDISPATCHING                             REDISPATCHED  
-	// ASYNCWAIT                                               REDISPATCH     COMPLETING
-	// REDISPATCH    REDISPATCHED
-	// REDISPATCHED                ASYNCSTARTED  UNCOMPLETED
-	// COMPLETING    UNCOMPLETED                 UNCOMPLETED
-	// UNCOMPLETED                                                                        COMPLETED
-	// COMPLETED
-	private static final int __IDLE=0;         // Idle request
-	private static final int __DISPATCHED=1;   // Request dispatched to filter/servlet
-	private static final int __UNCOMPLETED=8;  // Request is completable
-	private static final int __COMPLETED=9;    // Request is complete
-	
-	private int _state;
-	
-	AsyncContinuation()
-	{
-		_state=__IDLE;
-	}
-
-	@Override
-	public synchronized String toString()
-	{
-		return super.toString()+"@"+getStatusString();
-	}
-
-	private synchronized String getStatusString()
-	{
-		return
-		((_state==__IDLE)?"IDLE":
-			(_state==__DISPATCHED)?"DISPATCHED":
-										(_state==__UNCOMPLETED)?"UNCOMPLETED":
-											(_state==__COMPLETED)?"COMPLETE":
-												("UNKNOWN?"+_state));
-	}
-
-	protected synchronized void handling()
-	{
-		switch(_state)
-		{
-			case __IDLE:
-				_state=__DISPATCHED;
-				return;
-				
-			default:
-				throw new IllegalStateException(this.getStatusString());
-		}
-	}
-
-	/* ------------------------------------------------------------ */
-	/**
-	 * Signal that the HttpConnection has finished handling the request.
-	 * For blocking connectors, this call may block if the request has
-	 * been suspended (startAsync called).
-	 * @return true if handling is complete, false if the request should 
-	 * be handled again (eg because of a resume that happened before unhandle was called)
-	 */
-	protected synchronized void unhandle()
-	{
-		switch(_state)
-		{
-			case __DISPATCHED:
-				_state = __UNCOMPLETED;
-				return;
-
-			default:
-				throw new IllegalStateException(this.getStatusString());
-		}
-	}
-
-		
-	protected synchronized void doComplete(Throwable ex)
-	{
-		switch(_state)
-		{
-			case __UNCOMPLETED:
-				_state = __COMPLETED;
-				break;
-				
-			default:
-				throw new IllegalStateException(this.getStatusString());
-		}
-	}
-
-	protected synchronized void recycle()
-	{
-		switch(_state)
-		{
-			case __DISPATCHED:
-				throw new IllegalStateException(getStatusString());
-			default:
-				_state=__IDLE;
-		}
-	}    
-	
-	synchronized boolean isUncompleted()
-	{
-		return _state==__UNCOMPLETED;
-	} 
-}
--- a/src/org/eclipse/jetty/server/Request.java	Sun Oct 09 23:48:32 2016 -0600
+++ b/src/org/eclipse/jetty/server/Request.java	Mon Oct 10 00:50:06 2016 -0600
@@ -141,7 +141,6 @@
 
 		return AbstractHttpConnection.getCurrentConnection().getRequest();
 	}
-	final AsyncContinuation _async = new AsyncContinuation();
 	private volatile Attributes _attributes;
 	private MultiMap<String> _baseParameters;
 	private String _characterEncoding;
@@ -1291,7 +1290,6 @@
 			}
 		}
 
-		_async.recycle();
 		_handled = false;
 		if (_context != null)
 			throw new IllegalStateException("Request in context!");