Search in sources :

Example 1 with UpdateablePriorityQueue

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;
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) DeadlineAction(org.spf4j.io.tcp.DeadlineAction) IOException(java.io.IOException) UpdateablePriorityQueue(org.spf4j.ds.UpdateablePriorityQueue) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketChannel (java.nio.channels.SocketChannel)1 UpdateablePriorityQueue (org.spf4j.ds.UpdateablePriorityQueue)1 DeadlineAction (org.spf4j.io.tcp.DeadlineAction)1