Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x

This commit is contained in:
Greg Wilkins 2016-06-15 10:41:10 +10:00
commit 4ba0fa9544
5 changed files with 37 additions and 105 deletions

View File

@ -265,31 +265,6 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
{ {
handle(); handle();
} }
// TODO Revert once #624 debugged
private static ThreadLocal<Throwable> __dispatchedFrom=new ThreadLocal<>();
public static Throwable getDispatchedFrom() { return __dispatchedFrom.get(); }
public Runnable getRunnable()
{
Throwable _dispatched = new Throwable();
return new Runnable()
{
@Override
public void run()
{
try
{
__dispatchedFrom.set(_dispatched);
handle();
}
finally
{
__dispatchedFrom.set(null);
}
}
};
}
AtomicReference<Action> caller = new AtomicReference<>(); AtomicReference<Action> caller = new AtomicReference<>();

View File

@ -615,7 +615,7 @@ public class HttpChannelState
cancelTimeout(event); cancelTimeout(event);
if (handle) if (handle)
runInContext(event,_channel.getRunnable()); runInContext(event,_channel);
} }
public void errorComplete() public void errorComplete()
@ -887,7 +887,7 @@ public class HttpChannelState
protected void scheduleDispatch() protected void scheduleDispatch()
{ {
_channel.execute(_channel.getRunnable()); _channel.execute(_channel);
} }
protected void scheduleTimeout(AsyncContextEvent event) protected void scheduleTimeout(AsyncContextEvent event)

View File

@ -122,7 +122,7 @@ public class HttpInput extends ServletInputStream implements Runnable
{ {
HttpChannel channel = _channelState.getHttpChannel(); HttpChannel channel = _channelState.getHttpChannel();
Executor executor = channel.getConnector().getServer().getThreadPool(); Executor executor = channel.getConnector().getServer().getThreadPool();
executor.execute(channel.getRunnable()); executor.execute(channel);
} }

View File

@ -860,7 +860,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{ {
_writeListener = writeListener; _writeListener = writeListener;
if (_channel.getState().onWritePossible()) if (_channel.getState().onWritePossible())
_channel.execute(_channel.getRunnable()); _channel.execute(_channel);
} }
else else
throw new IllegalStateException(); throw new IllegalStateException();
@ -1005,7 +1005,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
if (!_state.compareAndSet(OutputState.UNREADY, OutputState.READY)) if (!_state.compareAndSet(OutputState.UNREADY, OutputState.READY))
continue; continue;
if (_channel.getState().onWritePossible()) if (_channel.getState().onWritePossible())
_channel.execute(_channel.getRunnable()); _channel.execute(_channel);
break; break;
case CLOSED: case CLOSED:
@ -1023,7 +1023,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{ {
_onError=e==null?new IOException():e; _onError=e==null?new IOException():e;
if (_channel.getState().onWritePossible()) if (_channel.getState().onWritePossible())
_channel.execute(_channel.getRunnable()); _channel.execute(_channel);
} }
} }

View File

@ -43,10 +43,8 @@ import org.junit.Test;
public class LocalAsyncContextTest public class LocalAsyncContextTest
{ {
private final Locker _completeLock = new Locker(); private final AtomicReference<Throwable> _completed0 = new AtomicReference<>();
private Throwable __completed; private final AtomicReference<Throwable> _completed1 = new AtomicReference<>();
private Throwable __dispatched;
private final AtomicReference<Throwable> __completed1 = new AtomicReference<>();
protected Server _server; protected Server _server;
protected SuspendHandler _handler; protected SuspendHandler _handler;
protected Connector _connector; protected Connector _connector;
@ -65,11 +63,8 @@ public class LocalAsyncContextTest
_server.setHandler(session); _server.setHandler(session);
_server.start(); _server.start();
try (Locker.Lock lock = _completeLock.lock()) _completed0.set(null);
{ _completed1.set(null);
__completed = null;
}
__completed1.set(null);
} }
protected Connector initConnector() protected Connector initConnector()
@ -95,14 +90,8 @@ public class LocalAsyncContextTest
response = process(null); response = process(null);
check(response, "TIMEOUT"); check(response, "TIMEOUT");
spinAssertEquals(1, () -> spinAssertEquals(1, () -> _completed0.get() == null ? 0 : 1);
{ spinAssertEquals(1, () -> _completed1.get() == null ? 0 : 1);
try (Locker.Lock lock = _completeLock.lock())
{
return __completed == null ? 0 : 1;
}
});
spinAssertEquals(1, () -> __completed1.get() == null ? 0 : 1);
} }
@Test @Test
@ -231,14 +220,8 @@ public class LocalAsyncContextTest
response = process(null); response = process(null);
check(response, "STARTASYNC", "DISPATCHED", "startasync", "STARTASYNC2", "DISPATCHED"); check(response, "STARTASYNC", "DISPATCHED", "startasync", "STARTASYNC2", "DISPATCHED");
spinAssertEquals(1, () -> spinAssertEquals(1, () -> _completed0.get() == null ? 0 : 1);
{ spinAssertEquals(0, () -> _completed1.get() == null ? 0 : 1);
try (Locker.Lock lock = _completeLock.lock())
{
return __completed == null ? 0 : 1;
}
});
spinAssertEquals(0, () -> __completed1.get() == null ? 0 : 1);
} }
protected void check(String response, String... content) protected void check(String response, String... content)
@ -490,56 +473,30 @@ public class LocalAsyncContextTest
public void onComplete(AsyncEvent event) throws IOException public void onComplete(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
Throwable dispatched = HttpChannel.getDispatchedFrom(); if (!_completed0.compareAndSet(null, complete))
try (Locker.Lock lock = _completeLock.lock())
{ {
if (__completed == null) System.err.println("First onCompleted:");
{ _completed0.get().printStackTrace();
__completed = complete; System.err.println("First onCompleted:");
__dispatched = dispatched; complete.printStackTrace();
} _completed0.set(null);
else throw new IllegalStateException();
{
System.err.println("First onCompleted dispatched from:");
if (__dispatched != null)
__dispatched.printStackTrace();
System.err.println("First onCompleted:");
__completed.printStackTrace();
System.err.println("Second onCompleted dispatched from:");
if (dispatched != null)
dispatched.printStackTrace();
complete.printStackTrace();
throw new IllegalStateException();
}
} }
} }
@Override @Override
public void onError(AsyncEvent event) throws IOException public void onError(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
Throwable dispatched = HttpChannel.getDispatchedFrom(); if (!_completed0.compareAndSet(null, complete))
try (Locker.Lock lock = _completeLock.lock()) {
{ System.err.println("First onCompleted:");
if (__completed == null) _completed0.get().printStackTrace();
{ System.err.println("First onCompleted:");
__completed = complete; complete.printStackTrace();
__dispatched = dispatched; _completed0.set(null);
} throw new IllegalStateException();
else }
{
System.err.println("First onCompleted dispatched from:");
if (__dispatched != null)
__dispatched.printStackTrace();
System.err.println("First onCompleted:");
__completed.printStackTrace();
System.err.println("Second onCompleted dispatched from:");
if (dispatched != null)
dispatched.printStackTrace();
complete.printStackTrace();
throw new IllegalStateException();
}
}
} }
@Override @Override
@ -563,11 +520,11 @@ public class LocalAsyncContextTest
public void onComplete(AsyncEvent event) throws IOException public void onComplete(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
if (!__completed1.compareAndSet(null, complete)) if (!_completed1.compareAndSet(null, complete))
{ {
__completed1.get().printStackTrace(); _completed1.get().printStackTrace();
complete.printStackTrace(); complete.printStackTrace();
__completed1.set(null); _completed1.set(null);
throw new IllegalStateException(); throw new IllegalStateException();
} }
} }
@ -576,11 +533,11 @@ public class LocalAsyncContextTest
public void onError(AsyncEvent event) throws IOException public void onError(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
if (!__completed1.compareAndSet(null, complete)) if (!_completed1.compareAndSet(null, complete))
{ {
__completed1.get().printStackTrace(); _completed1.get().printStackTrace();
complete.printStackTrace(); complete.printStackTrace();
__completed1.set(null); _completed1.set(null);
throw new IllegalStateException(); throw new IllegalStateException();
} }
} }