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();
}
// 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<>();

View File

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

View File

@ -122,7 +122,7 @@ public class HttpInput extends ServletInputStream implements Runnable
{
HttpChannel channel = _channelState.getHttpChannel();
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;
if (_channel.getState().onWritePossible())
_channel.execute(_channel.getRunnable());
_channel.execute(_channel);
}
else
throw new IllegalStateException();
@ -1005,7 +1005,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
if (!_state.compareAndSet(OutputState.UNREADY, OutputState.READY))
continue;
if (_channel.getState().onWritePossible())
_channel.execute(_channel.getRunnable());
_channel.execute(_channel);
break;
case CLOSED:
@ -1023,7 +1023,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
_onError=e==null?new IOException():e;
if (_channel.getState().onWritePossible())
_channel.execute(_channel.getRunnable());
_channel.execute(_channel);
}
}

View File

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