422723 - Dispatch failed callbacks to avoid blocking selector

This commit is contained in:
Greg Wilkins 2013-11-28 10:04:08 +11:00
parent b6c0fe2cd6
commit 1b30b0f9a8
2 changed files with 53 additions and 10 deletions

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.IteratingNestedCallback; import org.eclipse.jetty.util.IteratingNestedCallback;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -466,19 +467,20 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
} }
} }
private class CommitCallback extends IteratingNestedCallback private class CommitCallback extends IteratingCallback
{ {
final ByteBuffer _content; final ByteBuffer _content;
final boolean _lastContent; final boolean _lastContent;
final ResponseInfo _info; final ResponseInfo _info;
final Callback _callback;
ByteBuffer _header; ByteBuffer _header;
CommitCallback(ResponseInfo info, ByteBuffer content, boolean last, Callback callback) CommitCallback(ResponseInfo info, ByteBuffer content, boolean last, Callback callback)
{ {
super(callback);
_info=info; _info=info;
_content=content; _content=content;
_lastContent=last; _lastContent=last;
_callback=callback;
} }
@Override @Override
@ -586,18 +588,39 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
} }
} }
} }
@Override
protected void completed()
{
_callback.succeeded();
} }
private class ContentCallback extends IteratingNestedCallback @Override
public void failed(final Throwable x)
{
super.failed(x);
getExecutor().execute(new Runnable()
{
@Override
public void run()
{
_callback.failed(x);
}
});
}
}
private class ContentCallback extends IteratingCallback
{ {
final ByteBuffer _content; final ByteBuffer _content;
final boolean _lastContent; final boolean _lastContent;
final Callback _callback;
ContentCallback(ByteBuffer content, boolean last, Callback callback) ContentCallback(ByteBuffer content, boolean last, Callback callback)
{ {
super(callback);
_content=content; _content=content;
_lastContent=last; _lastContent=last;
_callback=callback;
} }
@Override @Override
@ -668,6 +691,26 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
} }
} }
} }
@Override
protected void completed()
{
_callback.succeeded();
}
@Override
public void failed(final Throwable x)
{
super.failed(x);
getExecutor().execute(new Runnable()
{
@Override
public void run()
{
_callback.failed(x);
}
});
}
} }
} }