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.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -432,8 +431,7 @@ public class ConnectHandler extends HandlerWrapper
protected class ConnectManager extends SelectorManager protected class ConnectManager extends SelectorManager
{ {
protected ConnectManager(Executor executor, Scheduler scheduler, int selectors)
private ConnectManager(Executor executor, Scheduler scheduler, int selectors)
{ {
super(executor, scheduler, selectors); super(executor, scheduler, selectors);
} }
@ -455,10 +453,16 @@ public class ConnectHandler extends HandlerWrapper
} }
@Override @Override
protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment) protected void connectionFailed(SocketChannel channel, final Throwable ex, final Object attachment)
{ {
ConnectContext connectContext = (ConnectContext)attachment; getExecutor().execute(new Runnable()
onConnectFailure(connectContext.request, connectContext.response, connectContext.asyncContext, ex); {
public void run()
{
ConnectContext connectContext = (ConnectContext)attachment;
onConnectFailure(connectContext.request, connectContext.response, connectContext.asyncContext, ex);
}
});
} }
} }
@ -518,8 +522,14 @@ public class ConnectHandler extends HandlerWrapper
public void onOpen() public void onOpen()
{ {
super.onOpen(); super.onOpen();
onConnectSuccess(connectContext, this); getExecutor().execute(new Runnable()
fillInterested(); {
public void run()
{
onConnectSuccess(connectContext, UpstreamConnection.this);
fillInterested();
}
});
} }
@Override @Override