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