use of org.spf4j.ds.UpdateablePriorityQueue in project spf4j by zolyfarkas.
the class ProxyClientHandler method handle.
@Override
public void handle(final Selector serverSelector, final SocketChannel clientChannel, final ExecutorService exec, final BlockingQueue<Runnable> tasksToRunBySelector, final UpdateablePriorityQueue<DeadlineAction> deadlineActions) throws IOException {
final InetSocketAddress socketAddress = new InetSocketAddress(fwdDestination.getHost(), fwdDestination.getPort());
final SocketChannel proxyChannel = SocketChannel.open();
try {
proxyChannel.configureBlocking(false);
proxyChannel.connect(socketAddress);
TransferBuffer c2s = new TransferBuffer(proxyBufferSize);
if (c2sSnifferFact != null) {
c2s.setIncomingSniffer(c2sSnifferFact.get(clientChannel));
}
TransferBuffer s2c = new TransferBuffer(proxyBufferSize);
final long connectDeadline = TimeSource.nanoTime() + TimeUnit.MILLISECONDS.toNanos(connectTimeoutMillis);
UpdateablePriorityQueue.ElementRef daction = deadlineActions.add(new DeadlineAction(connectDeadline, new CloseChannelsOnTimeout(proxyChannel, clientChannel)));
new ProxyBufferTransferHandler(c2s, s2c, null, clientChannel, serverSelector, exec, tasksToRunBySelector, daction).initialInterestRegistration();
new ProxyBufferTransferHandler(s2c, c2s, s2cSnifferFact, proxyChannel, serverSelector, exec, tasksToRunBySelector, daction).initialInterestRegistration();
} catch (IOException ex) {
Exception exs = Closeables.closeAll(proxyChannel, clientChannel);
if (exs != null) {
ex.addSuppressed(exs);
}
throw ex;
}
}
Aggregations