Dispatching execution of blocking code to a different thread to avoid

to block the selector thread.
This commit is contained in:
Simone Bordet 2014-05-05 15:35:11 +02:00
parent dea8d684a6
commit 0e594e55c3
1 changed files with 18 additions and 8 deletions

View File

@ -28,7 +28,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -432,8 +431,7 @@ public class ConnectHandler extends HandlerWrapper
protected class ConnectManager extends SelectorManager
{
private ConnectManager(Executor executor, Scheduler scheduler, int selectors)
protected ConnectManager(Executor executor, Scheduler scheduler, int selectors)
{
super(executor, scheduler, selectors);
}
@ -455,11 +453,17 @@ public class ConnectHandler extends HandlerWrapper
}
@Override
protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment)
protected void connectionFailed(SocketChannel channel, final Throwable ex, final Object attachment)
{
getExecutor().execute(new Runnable()
{
public void run()
{
ConnectContext connectContext = (ConnectContext)attachment;
onConnectFailure(connectContext.request, connectContext.response, connectContext.asyncContext, ex);
}
});
}
}
protected static class ConnectContext
@ -518,9 +522,15 @@ public class ConnectHandler extends HandlerWrapper
public void onOpen()
{
super.onOpen();
onConnectSuccess(connectContext, this);
getExecutor().execute(new Runnable()
{
public void run()
{
onConnectSuccess(connectContext, UpstreamConnection.this);
fillInterested();
}
});
}
@Override
protected int read(EndPoint endPoint, ByteBuffer buffer) throws IOException