Code cleanups.
This commit is contained in:
parent
046cbe4bc6
commit
8b76358208
|
@ -18,10 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static javax.servlet.RequestDispatcher.ERROR_EXCEPTION;
|
||||
import static javax.servlet.RequestDispatcher.ERROR_MESSAGE;
|
||||
import static javax.servlet.RequestDispatcher.ERROR_STATUS_CODE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -42,6 +38,10 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
import org.eclipse.jetty.util.thread.Locker;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
|
||||
import static javax.servlet.RequestDispatcher.ERROR_EXCEPTION;
|
||||
import static javax.servlet.RequestDispatcher.ERROR_MESSAGE;
|
||||
import static javax.servlet.RequestDispatcher.ERROR_STATUS_CODE;
|
||||
|
||||
/**
|
||||
* Implementation of AsyncContext interface that holds the state of request-response cycle.
|
||||
*/
|
||||
|
@ -87,7 +87,7 @@ public class HttpChannelState
|
|||
/**
|
||||
* The state of the servlet async API.
|
||||
*/
|
||||
public enum Async
|
||||
private enum Async
|
||||
{
|
||||
NOT_ASYNC,
|
||||
STARTED, // AsyncContext.startAsync() has been called
|
||||
|
@ -99,25 +99,24 @@ public class HttpChannelState
|
|||
ERRORED // The error has been processed
|
||||
}
|
||||
|
||||
public enum Interest
|
||||
private enum Interest
|
||||
{
|
||||
NONE(false),
|
||||
NEEDED(true),
|
||||
REGISTERED(true);
|
||||
|
||||
final boolean _interested;
|
||||
boolean isInterested() { return _interested;}
|
||||
|
||||
private final boolean _interested;
|
||||
|
||||
Interest(boolean interest)
|
||||
{
|
||||
_interested = interest;
|
||||
}
|
||||
|
||||
private boolean isInterested() { return _interested;}
|
||||
}
|
||||
|
||||
private final boolean DEBUG=LOG.isDebugEnabled();
|
||||
|
||||
private final Locker _locker=new Locker();
|
||||
private final HttpChannel _channel;
|
||||
|
||||
private List<AsyncListener> _asyncListeners;
|
||||
private State _state;
|
||||
private Async _async;
|
||||
|
@ -221,7 +220,7 @@ public class HttpChannelState
|
|||
{
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("handling {}",toStringLocked());
|
||||
|
||||
switch(_state)
|
||||
|
@ -296,7 +295,7 @@ public class HttpChannelState
|
|||
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("startAsync {}",toStringLocked());
|
||||
if (_state!=State.DISPATCHED || _async!=Async.NOT_ASYNC)
|
||||
throw new IllegalStateException(this.getStatusStringLocked());
|
||||
|
@ -338,7 +337,6 @@ public class HttpChannelState
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void asyncError(Throwable failure)
|
||||
{
|
||||
AsyncContextEvent event = null;
|
||||
|
@ -392,7 +390,7 @@ public class HttpChannelState
|
|||
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("unhandle {}",toStringLocked());
|
||||
|
||||
switch(_state)
|
||||
|
@ -432,7 +430,7 @@ public class HttpChannelState
|
|||
case STARTED:
|
||||
// If a read is possible and either we are interested in reads or we have
|
||||
// to call onAllDataRead, then we need a READ_CALLBACK
|
||||
if (_asyncReadPossible && ( _asyncRead.isInterested() || _channel.getRequest().getHttpInput().isAsyncEOF()))
|
||||
if (_asyncReadPossible && (_asyncRead.isInterested() || _channel.getRequest().getHttpInput().isAsyncEOF()))
|
||||
{
|
||||
_state=State.ASYNC_IO;
|
||||
_asyncRead=Interest.NONE;
|
||||
|
@ -503,7 +501,7 @@ public class HttpChannelState
|
|||
AsyncContextEvent event;
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("dispatch {} -> {}",toStringLocked(),path);
|
||||
|
||||
boolean started=false;
|
||||
|
@ -557,7 +555,7 @@ public class HttpChannelState
|
|||
AsyncContextEvent event;
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onTimeout {}",toStringLocked());
|
||||
|
||||
if (_async!=Async.STARTED)
|
||||
|
@ -656,7 +654,7 @@ public class HttpChannelState
|
|||
AsyncContextEvent event;
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("complete {}",toStringLocked());
|
||||
|
||||
boolean started=false;
|
||||
|
@ -694,7 +692,7 @@ public class HttpChannelState
|
|||
{
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("error complete {}",toStringLocked());
|
||||
|
||||
_async=Async.COMPLETE;
|
||||
|
@ -729,7 +727,7 @@ public class HttpChannelState
|
|||
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onError {} {}",toStringLocked(),failure);
|
||||
|
||||
// Set error on request.
|
||||
|
@ -739,8 +737,7 @@ public class HttpChannelState
|
|||
_event.getSuppliedRequest().setAttribute(ERROR_STATUS_CODE,code);
|
||||
_event.getSuppliedRequest().setAttribute(ERROR_EXCEPTION,failure);
|
||||
_event.getSuppliedRequest().setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,failure==null?null:failure.getClass());
|
||||
|
||||
_event.getSuppliedRequest().setAttribute(ERROR_MESSAGE,reason!=null?reason:null);
|
||||
_event.getSuppliedRequest().setAttribute(ERROR_MESSAGE,reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -750,7 +747,7 @@ public class HttpChannelState
|
|||
baseRequest.setAttribute(ERROR_STATUS_CODE,code);
|
||||
baseRequest.setAttribute(ERROR_EXCEPTION,failure);
|
||||
baseRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,failure==null?null:failure.getClass());
|
||||
baseRequest.setAttribute(ERROR_MESSAGE,reason!=null?reason:null);
|
||||
baseRequest.setAttribute(ERROR_MESSAGE,reason);
|
||||
}
|
||||
|
||||
// Are we blocking?
|
||||
|
@ -847,7 +844,7 @@ public class HttpChannelState
|
|||
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onComplete {}",toStringLocked());
|
||||
|
||||
switch(_state)
|
||||
|
@ -904,7 +901,7 @@ public class HttpChannelState
|
|||
cancelTimeout();
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("recycle {}",toStringLocked());
|
||||
|
||||
switch(_state)
|
||||
|
@ -934,7 +931,7 @@ public class HttpChannelState
|
|||
cancelTimeout();
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("upgrade {}",toStringLocked());
|
||||
|
||||
switch(_state)
|
||||
|
@ -1124,9 +1121,8 @@ public class HttpChannelState
|
|||
_channel.getRequest().setAttribute(name,attribute);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Called to signal async read isReady() has returned false.
|
||||
/**
|
||||
* Called to signal async read isReady() has returned false.
|
||||
* This indicates that there is no content available to be consumed
|
||||
* and that once the channel enteres the ASYNC_WAIT state it will
|
||||
* register for read interest by calling {@link HttpChannel#asyncReadFillInterested()}
|
||||
|
@ -1137,7 +1133,7 @@ public class HttpChannelState
|
|||
boolean interested=false;
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onReadUnready {}",toStringLocked());
|
||||
|
||||
// We were already unready, this is not a state change, so do nothing
|
||||
|
@ -1158,8 +1154,8 @@ public class HttpChannelState
|
|||
_channel.asyncReadFillInterested();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Called to signal that content is now available to read.
|
||||
/**
|
||||
* Called to signal that content is now available to read.
|
||||
* If the channel is in ASYNC_WAIT state and unready (ie isReady() has
|
||||
* returned false), then the state is changed to ASYNC_WOKEN and true
|
||||
* is returned.
|
||||
|
@ -1170,7 +1166,7 @@ public class HttpChannelState
|
|||
boolean woken=false;
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onReadPossible {}",toStringLocked());
|
||||
|
||||
_asyncReadPossible=true;
|
||||
|
@ -1183,8 +1179,8 @@ public class HttpChannelState
|
|||
return woken;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Called to signal that the channel is ready for a callback.
|
||||
/**
|
||||
* Called to signal that the channel is ready for a callback.
|
||||
* This is similar to calling {@link #onReadUnready()} followed by
|
||||
* {@link #onReadPossible()}, except that as content is already
|
||||
* available, read interest is never set.
|
||||
|
@ -1195,7 +1191,7 @@ public class HttpChannelState
|
|||
boolean woken=false;
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onReadReady {}",toStringLocked());
|
||||
|
||||
_asyncRead=Interest.REGISTERED;
|
||||
|
@ -1209,8 +1205,8 @@ public class HttpChannelState
|
|||
return woken;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Called to signal that a read has read -1.
|
||||
/**
|
||||
* Called to signal that a read has read -1.
|
||||
* Will wake if the read was called while in ASYNC_WAIT state
|
||||
* @return true if woken
|
||||
*/
|
||||
|
@ -1219,7 +1215,7 @@ public class HttpChannelState
|
|||
boolean woken=false;
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onReadEof {}",toStringLocked());
|
||||
|
||||
if (_state==State.ASYNC_WAIT)
|
||||
|
@ -1237,7 +1233,6 @@ public class HttpChannelState
|
|||
return woken;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isReadPossible()
|
||||
{
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
|
@ -1246,14 +1241,13 @@ public class HttpChannelState
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean onWritePossible()
|
||||
{
|
||||
boolean handle=false;
|
||||
|
||||
try(Locker.Lock lock= _locker.lock())
|
||||
{
|
||||
if(DEBUG)
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("onWritePossible {}",toStringLocked());
|
||||
|
||||
_asyncWritePossible=true;
|
||||
|
@ -1266,5 +1260,4 @@ public class HttpChannelState
|
|||
|
||||
return handle;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue